This code creates a flat circle. I need to change it into a sphere. I have tried, but I sort of get a mess. How do I add the Z to it?
set display mode 1024,768,32
set text opaque
color backdrop 0
hide mouse
sync on
sync rate 0
position camera 0,0,-50
point camera 0,0,0
global w as integer
global h as integer
w = screen width()
h = screen height()
a = 500
dim x#(a)
dim y#(a)
dim z#(a)
dim s#(a)
dim xv#(a,a)
dim yv#(a,a)
dim c#(a)
dim r#(a)
dim r(a)
dim g(a)
dim b(a)
for i = 1 to a
x#(i) = rnd(w)
y#(i) = rnd(h)
c#(i) = 255
next i
grav# = -2.3
rep# = 1510.0
for i = 1 to a
r(i) = 10
g(i) = 10
b(i) = 50
r#(i) = 0.5
make object sphere i,r#(i),6,6
color object i,rgb(r(i),g(i),b(i))
hide object i
next i
rendmax = 1
rend=1
syncrate = 10
texth = 16
do
oldmc = newmc
newmc = mouseclick()
inc renmode, (newmc > oldmc)
oldfps = fps
fps = screen fps()
if rendset = 0
if abs(fps-syncrate)<3 then rendset=1
if fps > syncrate and abs(oldfps-fps)<5 then inc rendmax
if fps=oldfps and fps<syncrate then dec rendmax
if rendmax < 1 then rendmax = 1
rend = rendmax * .1
endif
`}
tx# = mousex()
ty# = mousey()
inc rep#, (upkey()-downkey())*100
dec grav#, (rightkey()-leftkey())*0.1
for i = 1 to rend
`ink 257*c#(i),0
`x = x#(i)
`y = y#(i)
inc t
if t = 1
if r(i) > 10
dec r(i)
endif
if g(i) > 10
dec g(i)
endif
if b(i) > 50
dec b(i)
endif
t = 0
endif
if r#(i) < 0.5 then r#(i) = r#(i)+0.0001
Makesphere(i,x#(i),y#(i),r#(i))
z# = atanfull(x#(i)-tx#,y#(i)-ty#)
x#(i) = newxvalue(x#(i),z#,grav#)
y#(i) = newzvalue(y#(i),z#,grav#)
next i
for i = 0 to rend
gosub _room
gosub _closeones
next i
ink -2,0
circle tx#,ty#,10
y=0
text 0,y, "Sync Rate: " + str$(syncrate) + ", " + "FPS: " + str$(fps) + " [Render Fixed = " + str$(rendset) + "]" : inc y,texth
text 0,y, "Particles rendered: " + str$(rendmax/10.0) : inc y,texth
inc y,texth
text 0,y, "Press up/down to inc/dec repulsive force. -- force =" +str$(rep) : inc y,texth
text 0,y, "Press left/right to inc/dec mouse gravity. -- gravity = "+str$(0-grav#) : inc y,texth
text 0,y, "Click the mouse to change render mode." : inc y,texth
sync
loop
rem +++ subroutines +++
_closeones:
for cl = 0 to rend
v = 0
xv# = 0
yv# = 0
if cl <> i
arg# = ( x#(i) - x#(cl) )^2 + ( y#(i) - y#(cl) )^2
dist# = (arg#>100.0)*arg# + (arg#<100.0)*100.0
if dist# < rep#
inc v
if cl > 0
if r(cl) < 255
change = rnd(9)+1
if change = 1
inc r(cl)
endif
endif
if g(cl) < 255
change = rnd(6)+1
if change = 1
inc g(cl)
endif
endif
if b(cl) < 255
change = rnd(3)+1
if change = 1
inc b(cl)
endif
endif
if r#(i) >= 0.4 then r#(i) = r#(i)-0.00001
if r#(i) <= 0.4 then r(cl) = 255 : g(cl) = 70 : b(cl)=10
color object cl,rgb(r(cl),g(cl),b(cl))
endif
tz# = atanfull(x#(i)-x#(cl),y#(i)-y#(cl))
xv#(i,v) = newxvalue(x#(i),tz#,rep#/dist#)
yv#(i,v) = newzvalue(y#(i),tz#,rep#/dist#)
endif
for cl2 = 1 to v
inc xv#,xv#(i,cl2)
inc yv#,yv#(i,cl2)
next cl2
if v > 0
x#(i) = xv#/v
y#(i) = yv#/v
` c#(i) = arg#
` c#(i) = 255
endif
endif
next cl
return
`//
_room:
if x#(i) < r#(i) then x#(i) = r#(i)
if x#(i) > w-r#(i) then x#(i) = w-r#(i)
if y#(i) < r#(i) then y#(i) = r#(i)
if y#(i) > h-r#(i) then y#(i) = h-r#(i)
return
function Makesphere(i,x#,y#,r#)
y# = y#-(y#*2)
u = (w/2)/100
v = (h/2)/100
show object i
scale object i,r#*100.0,r#*100.0,r#*100.0
position object i,(x#/100.0)-u,(y#/100.0)+v,5
endfunction