Sunday, December 19, 2010

3D plotter


fastgraphics
clg : font "arial",15,100
graphsize 600,600
zoom=5 : max=5 : point=0
for z = -max to max step .1
for y = -max to max step .1
for x = -max to max step .1
Rem change this bit
if (x^2+y^2<1+z^2)then

if abs(x)>(max-.1) or abs(y)>(max-.1) or abs(z)>(max-.1) then rc=0
color rgb( 100+x*(100/max)+rand*rc,100+y*(100/max)+rand*rc,100+z*(100/max)+rand*rc)
point=point+1
gosub graph
else
if (abs(z)<0.01 and abs(y)<0.01) or (abs(x)<0.01 and abs(y)<0.01) or (abs(x)<0.01 and abs(z)<0.01) then
color black
if z>max-.1 then text sx+5,sy-10,"z="+max
if x>max-.1 then text sx+5,sy-10,"x="+max
if y>max-.1 then text sx+5,sy-10,"y="+max
refresh
gosub graph
end if
end if
next x
next y
refresh
next z
print "Aproximate volume ="+point/1000
graph:
prespective=1+(-3*max+x+y+z)/50
sx = 300+ (x*7-y*7)*zoom*prespective
sy = 300+ (-z*7+y*3+x*3)*zoom*prespective
circle sx,sy,2
rc=50
return

1 comment:

  1. Thank you for sharing, it's really helped me...
    Very nice article...

    ReplyDelete