Welcome to DrChip
Posted: Thu Jan 01, 2015 9:04 pm
Code: Select all
option base 1 ! option angle degrees
graphics ! graphics clear ! refresh off ! draw color 0,0,0
cx=screen_width()/2 ! cy=screen_height()/2
np=14 ! nz=10 ! nl=20 ! scale=100
dim point(np,3),pt(np,3),pix(np,2),line(nl,2),centre(3)
for i=1 to np ! for j=1 to 3
read point(i,j) ! if i<=nz then centre(j)+=point(i,j)
next j ! next i
for j=1 to 3 ! centre(j)/=nz ! next j
for i=1 to nl ! for j=1 to 2 ! read line(i,j) ! next j ! next i
for i=1 to np ! for j=1 to 3
point(i,j)=scale*(point(i,j)-centre(j))
next j ! next i
data 3,2,1, 6,2,1, 6,0,1, 3,0,1, 3,2,6
data 6,2,6, 6,0,6, 3,0,6, 4.5,3,1, 4.5,3,6
data 6,0,2, 6,0,3, 6,1.5,2, 6,1.5,3
data 1,2, 2,3, 3,4, 4,1, 5,6, 6,7, 7,8
data 8,5, 1,5, 2,6, 3,7, 4,8, 1,9, 2,9, 5,10, 6,10, 9,10
data 11,13, 13,14, 14,12
loop: a+=3
graphics clear
rotate(point,pt,10*cos(5*a),a,10*sin(3*a))
trans(pt,pt,0,0,400*(1+sin(4*a)))
project(pt,pix)
disp(pix,line)
goto loop
end
def rotate(pin(,),pout(,),ax,ay,az)
sax=sin(ax) ! cax=cos(ax)
say=sin(ay) ! cay=cos(ay)
saz=sin(az) ! caz=cos(az)
for i=1 to .np ! for j=1 to 3 ! pout(i,j)=pin(i,j) ! next j ! next i
if ax then
for i=1 to .np
temp=pout(i,2) ! pout(i,2)=cax*temp-sax*pout(i,3)
pout(i,3)=sax*temp+cax*pout(i,3)
next i
end if
if ay then
for i=1 to .np
temp=pout(i,1) ! pout(i,1)=cay*temp-say*pout(i,3)
pout(i,3)=say*temp+cay*pout(i,3)
next i
end if
if az then
for i=1 to .np
temp=pout(i,1) ! pout(i,1)=caz*temp-saz*pout(i,2)
pout(i,2)=saz*temp+caz*pout(i,2)
next i
end if
end def
def trans(pin(,),pout(,),dx,dy,dz)
for i=1 to .np
pout(i,1)=pin(i,1)+dx
pout(i,2)=pin(i,2)+dy
pout(i,3)=pin(i,3)+dz
next i
end def
def project(pin(,),pout(,))
for i=1 to .np
fac=900/(900+pin(i,3))
pout(i,1)=fac*pin(i,1) ! pout(i,2)=fac*pin(i,2)
next i
end def
def disp (pp(,),ll(,))
for i=1 to .nl
p1=ll(i,1) ! p2=ll(i,2)
draw line pp(p1,1)+.cx,.cy-pp(p1,2) to pp(p2,1)+.cx,.cy-pp(p2,2)
next i
refresh
end def