# 3d Sphere example?

Hey guys, me again. So I got some links to help me learn how to make 3d spheres, but in all of the examples I found there is either a lot of weird things ( I think shaders, here’s an example http://pastebin.com/7kPkXwSV) or is a long script that I quickly get lost trying to decipher. (Here’s an example https://gist.github.com/dermotbalson/26518774e821ff7023bb) I’ve spent hours studying and I still have no idea where to start. Does anyone know where I can find an example that just make a sphere (nothing else) and isn’t confusing
Thanks

I would google for opengl and sphere, because there must be lots of pages out there that explain how to draw a sphere with mesh triangles.

Because there is a lot of geometry, I was happy just to take someone else’s code and not worry about understanding it.

Thanks @ignatz, I’ll try that. However I brought codea to learn to code. I personally feel just copying some else’s work without me at least understanding it would kinda defeat the purpose for me and just cheapen all my effort to learn.

I agree, but I don’t think it means you need to understand all the mathematics, which is mainly what is involved in a sphere.

True, I guess I also like a challenge, beside I want to become a electrical engineer. I’m going to need to work with a lot of math anyway.

Then I can’t wait to see how you’ll go with quaternions…they totally defeated me @-)

It does look intimidating, but that shouldn’t deter me. After all the only guaranteed way to fail is to not try right?

Hi @Progrmr235,

Look in the Wiki (see link to right) a number of us looked into spheres some time ago. I put a routine in the ‘Contributed code’. Showed the algorithm for point generation, didn’t use meshes or rendered triangles but there are other examples in different threads.

Hope tha helps.

Bri_G Untested

``````local sphere = mesh()
local verts = {}
local r = 3
for i=1,10 do
for j=1,10 do
for k,v in ipairs({
{i,j},{i+1,j},{i+1,j-1},{i,j},{i+1,j-1},{i,j-1}
}) do
table.insert(verts, r*vec3(
math.cos(v*2*math.pi/10)*math.sin(v*math.pi/10),
math.sin(v*2*math.pi/10)*math.sin(v*math.pi/10),
math.cos(v*math.pi/10)
))
end
end
end
sphere.vertices = verts
``````

Thanks @LoopSpace, I liked the code, but it’s not quite what I was looking for.

And @Bri_G I have looked at the tutorials on the codea wiki. I’ve been trying to get on to @Jmv38’s page but I can’t because it keeps saying that “the sever stopped responding” . I would really appreciate if someone could give a link to that page that will work.

@Progrmr235 - I copied Jmv38’s code to this link

https://gist.github.com/dermotbalson/26518774e821ff7023bb

Uh, I thought there were some other code examples on there.

Ok then, my bad. Sorry to be a bother.

Try a different browser, perhaps

I tried several browser, even went on my laptop (which is made by Microsoft)

I got nothin. I don’t think it’s the browser

I adapted the sphere code for my own projects, try using the Sphere function from here

https://gist.github.com/dermotbalson/7799661

Yeah, I’ve looked at that before, I tried to figure it out. But I don’t understand what (input) represents in the code

Look at the top of my code where I call the sphere and pass it a table

`````` planet1 = Sphere({
nx = 40, ny = 20 , -- mesh definition
meshOptimize = true, -- optimize mesh for sphere
c1 = color1 , c2 = color1 , -- mesh colors
cx=0, cy=0, cz=0 , -- sphere center
r = 500 , -- radius of the sphere
rotTime1 = 20 , -- rotation time in s
hflip = true, -- to flip image horozontally
})
``````