I’m making a code to show how the volume of a sphere is found but, I want to make an equation that gives the area of the exact area of the object even when it’s at level 3 or 4
function setup()
view = 2
parameter.integer("level",3,65,12,setup1)
AngleX = 90
AngleY = 140
AngleZ = 90
end
function setup1()
r =10
tab={}
M,N=level,level
for n=0,N do
tab[n]={}
for m=0,M do
x= r * math.sin(math.pi * m/M) * math.cos(2*math.pi * n/N)
y= r * math.sin(math.pi * m/M) * math.sin(2*math.pi * n/N)
z= r * math.cos(math.pi * m/M)
tab[n][m]=vec3(x,y,z)
end
end
sph={}
for n=0,N-1 do
for m=0,M-1 do
table.insert(sph,tab[n][m])
table.insert(sph,tab[n][m+1])
table.insert(sph,tab[n+1][m+1])
table.insert(sph,tab[n][m])
table.insert(sph,tab[n+1][m])
table.insert(sph,tab[n+1][m+1])
end
end
cols={}
for z=1,#sph,6 do
col=vec4(math.random(),math.random(),math.random(),1)
for q=1,6 do
table.insert(cols,col)
end
end
sphere=mesh()
sphere.vertices=sph
sphere.colors=cols
approx = (4/3)*(math.pi)*(r^3)
fontSize(25)
end
function dpoint(x,y,z)
strokeWidth(15)
pointd = mesh()
pointd.vertices = {x,y,z}
end
function draw()
background(40, 40, 50)
fill(255)
text(approx,WIDTH/2+200,700)
perspective(view,WIDTH/HEIGHT)
camera(2000,0,0,0,0,0,0,1,0)
dpoint(1,1,1)
pointd:draw()
rotate(AngleX,1,0,0)
rotate(AngleY,0,1,0)
rotate(AngleZ,0,0,1)
sphere:draw()
text(r,100,100)
end