It looks like you're new here. If you want to get involved, click one of these buttons!

Recently started looking at 3d, this is my attempt at a cylinder based on antiprism construction

```
-- cylinder
-- creates a cylinder based on an antiprismatic construction
-- variables to be reset are
-- size: the radius of the cylinder
-- poly: the number of side lengths a single lamina circle is split into
-- dz: half the height of the cylinder
-- (called dz as this code is to be further used to create a sphere)
-- p: will pinch the top if less than 1 and flare it out if greater than 1...
-- ...experiment with p values between 0 and 2 to begin with
-- NOTE place your own texture at line 70
function setup()
print("Make sure to read first piece of code regarding variables")
parameter.number("height",-300,300,0)
parameter.number("angleX",-360,360,0)
parameter.number("angleY",-360,360,0)
parameter.number("angleZ",-360,360,0)
-- cylinder variables
size=40
poly=10
dz=25
z=0 -- just leave this alone...it's basically the z plane level
r=1
p=0.25
-- radian calculations to be used in initial loop
posA=(2*math.pi)/poly
posB=(2*math.pi)/(2*poly)
-- 2 tables for the lower ring of vertices and the upper ring of vertices to placed into
Va={}
Vb={}
-- initial loop, creates 2 rings (a lower and upper) of vertex points
for i=1,poly do
fac=(1-(z^2))^0.5
table.insert(Va,i,vec3(size*math.cos(posA*i)/fac,
size*math.sin(posA*i)/fac,
z-dz ))
table.insert(Vb,i,vec3(p*size*math.cos(((2*i)-1)*posB)/fac,
p*size*math.sin(((2*i)-1)*posB)/fac,
z+dz ))
end
Va[poly+1]=Va[1] -- places an additional repeated vertex for following loop
Vb[poly+1]=Vb[1] -- places an additional repeated vertex for following loop
-- 'zips' the two rings together into a single table cyl which can be used
-- to assign vertices to the cylindrical mesh
cyl={}
for i=1,poly do
table.insert(cyl,Va[i])
table.insert(cyl,Vb[i])
table.insert(cyl,Va[i+1])
table.insert(cyl,Vb[i])
table.insert(cyl,Va[i+1])
table.insert(cyl,Vb[i+1])
end
-- assigns texture co-ordinates to table cyltex so as to apply texture to mesh
cyltex={}
for i=1,2*poly do
table.insert(cyltex,vec2(0,0))
table.insert(cyltex,vec2(1,1))
table.insert(cyltex,vec2(0,1))
end
-- creates mesh
cy=mesh()
cy.vertices=cyl
cy:setColors(255,255,255,255)
cy.texCoords =cyltex
cy.texture="Documents:shader"
end
function draw()
background(0)
perspective(45, WIDTH/HEIGHT)
camera(0,height,200, 0,0,0, 0,1,0)
-- pushMatrix()
rotate(angleX,1,0,0)
rotate(angleY,0,1,0)
rotate(angleZ,0,0,1)
cy:draw()
-- ortho()
-- viewMatrix(matrix())
-- popMatrix()
end
```

Next step spheres...

Above is inspired by an attempt to access a link kindly sent to me by @Ignatz...

http://jmv38.comze.com/CODEAbis/download.php?ﬁle=3D-tutorial-v0.txt

...which I couldn't access/find (perhaps corrupted?), regarding sphere construction...so I thought I'd give it a go myself...next step is to use repeated laminae to create the sphere...

In the meantime... @Jmv38 is it still available somewhere? Would love to look at other's methods.

## Comments

Try this link, it contains all his projects

http://jmv38.comze.com/CODEAbis/server.php

You will certainly also enjoy this

http://twolivesleft.com/Codea/Talk/discussion/comment/26216

Thanks @Ignatz. More study...

If you want some inspiration

https://gist.github.com/tnlogy/5146337

it links to a blog about it also.

Thanks for that @tnlogy. Lovely example of icosahedron approaching sphericity... Have you seen this before

Dymaxion map unfolding - YouTube

www.youtube.com/watch?v=vfOcYUWfVqE

Buckminster Fuller rocks!...or maybe more credit should go to the programmer!

Also @tnlogy... Do I need to sign in to find the blog link?

The link was hidden in the code

http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html

Thanks again @tnlogy that's great. I was wondering about splitting faces only yesterday. Much appreciated.

Here's the same code converted for a sphere...has a nice geometry to it....I've used a grey granite like texture and looks pretty good...