Author Topic: Spinning Tetraeder [CMLua]  (Read 2118 times)

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Spinning Tetraeder [CMLua]
« on: March 04, 2014, 05:23:27 PM »
Hi, this is the converted Yabasic tetrader part of the demo.yab.
Code: [Select]
-- tetraeder.yab converted to Lua
opoints = {{-1,-1,1}, 
          {1,-1,-1}, 
          {1,1,1}, 
          {-1,1,-1}}
         
triangles = {{1,2,4}, 
            {2,3,4}, 
            {1,3,4}, 
            {1,2,3}}

points={}
for i=1,4 do
points[i]={}
end
page = 0
phi=0;dphi=0.1;psi=0;dpsi=0.05
r=60;g=20;b=0
dr=0.5;dg=1.2;db=3;dm=0
paper (65535)
repeat
activepage (page)
cls()

phi=phi+dphi
psi=psi+dpsi
  for n=1, 4 do
    points[n][1]=opoints[n][1]*math.cos(phi)-opoints[n][2]*math.sin(phi)
    points[n][2]=opoints[n][2]*math.cos(phi)+opoints[n][1]*math.sin(phi)
    p2=          points[n][2]*math.cos(psi)-opoints[n][3]*math.sin(psi)
    points[n][3]=opoints[n][3]*math.cos(psi)+ points[n][2]*math.sin(psi)
    points[n][2]=p2
 end

r=r+dr
if (r<0 or r>60) then
    dr=-dr
end
g=g+dg
if (g<0 or g>60) then
 dg=-dg
end
b=b+db
if (b<0 or b>60) then
db=-db
end
dm=dm+0.01
m=120-80*math.sin(dm)

for n=1, 4 do
    p1=triangles[n][1]
    p2=triangles[n][2]
    p3=triangles[n][3]
    n1=points[p1][1]+points[p2][1]+points[p3][1]
    n2=points[p1][2]+points[p2][2]+points[p3][2]
    n3=points[p1][3]+points[p2][3]+points[p3][3]
    if (n3>0) then
      sp=n1*0.5-n2*0.7-n3*0.6
      ink ( hrgb( 60+r+30*sp,60+g+30*sp,60+b+30*sp))
      filltriangle (screenwidth()/2+m*points[p1][1],screenheight()/2+m*points[p1][2],screenwidth()/2+m*points[p2][1],screenheight()/2+m*points[p2][2],screenwidth()/2+m*points[p3][1],screenheight()/2+m*points[p3][2])
    end
end

visualpage (page)
page = page + 1
if page > 1 then
    page = 0
end
sleep (12)
until keypressed()
« Last Edit: March 04, 2014, 07:43:05 PM by Cybermonkey »