aUCBLogo Demos and Tests / drawturtletest2
			
				
			
			be drawturtletest2
   singleshot=Name? "framenr
   cs
   size=50
   sizex=size*0.8
   sizebottom=size*0.4
   skin=hsb 30 .4 .75
   black=rgb 0 0 0
   white=rgb 1 1 1
   bmp1=loadImage "rockbricks.jpg
   tex1=Texture bmp1
   bmp2=loadImage "turtleskin.png
   tex2=Texture bmp2
   enableTexture
   nn=20
   shapes=Array nn
   Armour
   for [i 1 nn]
   [   clearScreen
      shapes.i=Graphic
      [   Texture tex1
         (reRandom 0)
         Armour::draw
         Texture tex2
         drawBody   
         drawHead
         drawFrontLegs 30*sin 360*i/nn
         drawBackLegs -30*sin 360*i/nn+90
;         disableTexture
      ]
      updateGraph
   ]
   orthographic
   clearScreen
   showTurtle
   setTurtleShapes shapes
   PenDown
   disableTexture
   setPC "blue
   setPS 0
   repeat 100
   [   forward 10
      right 3.6
      updateGraph
   ]
;   rotatescene2
   bury "drawturtletest2
   be Armour
      unperspective
      WindowMode
      deltax=16.5
      deltay=deltax*(sqrt 3)
      maxxi=13
      maxyi=9
      circleSize=90
      x0=deltax*(2*(maxxi+1)-3)/2
      y0=deltay*((round (maxyi+maxxi/2)/2)+1/2)
      point=[]
      polys=[]
      nr=int 0
      for [yi 0 maxyi]
      [   x=-x0
         y=-y0+deltay*yi
         for [xi 0 maxxi]
         [   nr=nr+1
            setPixel list x y  0
            push "point list x y
            x=x+deltax
            
            nr=nr+1
            setPixel list x y  0
            push "point list x y
            if yi > 0 and2 xi < maxxi and2 xi > 0
            [   poly=[]
               push "poly nr-2
               push "poly nr-1
               push "poly nr
               nr2=nr-2*(maxxi+1)+1
               push "poly nr2
               push "poly nr2-1
               push "poly nr2-2
               push "polys poly
            ]
            x=x+deltax/2
            y=y+deltay/2
         ]   
      ]
      polyCircle=[]
      foreach polys
      [   poly=[]
         isset=false
         until [isset or2 repCount > 6]
         [   if (round norm point.((?).repcount)) < circleSize
            [   push "poly (?).repcount
               isset=true
            ]
         ]
         foreach ?
         [   if (round norm point.?) < circleSize
            [   push "poly ?
            ]
         ]
         if poly != [] [push "polyCircle poly]
      ]
      polys=polyCircle
      drawPolys
      pu home pd
      circle circleSize
      cs
      top=[]
      foreach point
      [   p=?
         x=sizex*p.1/circleSize
         y=size*p.2/circleSize
         ifelse p.2 > 0
         [   z=sizex*((cos p.1)*(cos p.2)+0.5*(cos p.1)*sqr sin p.2)
         ][   z=sizex*((cos p.1)*(cos p.2)+0.3*(cos p.1)*sqr sin p.2)
         ]
         queue "top (list x y z)
      ]
      bottom=[]
      foreach point
      [   p=?
         x=sizex*p.1/circleSize
         y=size*p.2/circleSize
         z=size/180*45-sizebottom*(sqrt cos p.1)*sqrt cos p.2
         queue "bottom (list x y z)
      ]
      perspective
      setLightAmbient hsb 0 0 .4
      setLightSpecular "white
      setMaterialSpecular "white
      setMaterialShininess 20
   
      be drawPolys
         foreach polys
         [   setpc hsb 60+random 80 .8 0.4+0.3*rnd
            pu 
            setPos point.((?).1) 
            pd
            PolyStart
               foreach ? [setPos point.?]
            PolyEnd
         ]
      end
   
      be draw
         Texture tex1
         foreach polys
         [   setpc hsb 30+random 40 .6 0.6+0.2*rnd
            pu 
            setPosXYZ top.((?).1) 
            pd
            PolyStart
               foreach ? 
               [   setTexXY top.(?).1/sizex*2 top.(?).2/sizex*2
                  setPosXYZ top.?
               ]
            PolyEnd
            
            setpc hsb 100+random 40 .2 0.4+0.2*rnd
            pu 
            setPosXYZ bottom.((?).1) 
            pd
            PolyStart
               foreach ? 
               [   setTexXY top.(?).1/sizex*2 top.(?).2/sizex*2
                  setPosXYZ bottom.?
               ]
            PolyEnd
         ]
         pu home pd
      end
   end
   
   be drawBody
      setpc skin
      SurfaceStart
      for [p2 -90 90 10]
      [   y=size*0.95*sin p2
         p10=70
         for [p1 -p10 p10 10]
         [   x=sizex*0.8*p1/p10*cos p2
            ifelse p2 > 0
            [   z=sizex*0.8*((cos p1)*(cos p2)+0.5*(cos p1)*sqr sin p2)
            ][   z=sizex*0.7*((cos p1)*(cos p2)+0.3*(cos p1)*sqr sin p2)
            ]
            setTexXY x/sizex*2 y/sizex*2
            setXYZ x y z
         ]
         for [p1 p10 -p10 -10]
         [   x=sizex*0.8*p1/p10*cos p2
            z=size*0.31-sizebottom*0.8*(sqrt cos p1)*sqrt cos p2
            setTexXY x/sizex*2 y/sizex*2
            setXYZ x y z
         ]
         p1=-p10
         x=sizex*0.8*p1/p10*cos p2
         z=sizex*0.8*((cos p1)*(cos p2)+0.5*(cos p1)*sqr sin p2)
         setTexXY x/sizex*2 y/sizex*2
         setXYZ x y z
         SurfaceColumn
      ]
      SurfaceEnd
   end
   
   be drawHead
      pu setXYZ 0 size*0.9 0 pd
      SurfaceStart
      for [y size*0.90 size*1.1 10]
      [   for [phi -180 180 5]
         [   x=sizex*0.14*cos phi
            z=sizex*(0.16*(sin phi)+0.35)
            setTexXY x/sizex*2 y/sizex*2
            setXYZ x y z
         ]
         SurfaceColumn
         y0=y
      ]
      for [theta -10 90 10]
      [   y=y0+size*(0.2*(sin theta)+0.3)
         for [phi -180 180 5]
         [   x=sizex*0.16*(cos phi)*cos theta
            ifelse (phi== -30 or2 phi== -180+30) and2 theta > 10
            [   setpc black
            ][   setpc skin
            ]
            ifelse phi > 0
            [   z=sizex*(0.20*((sin phi)*(sqr cos theta)
                              +0.45*(sin phi)*sqr sin theta)+0.35)
            ][   z=sizex*(0.20*((sin phi)*(sqr cos theta)
                              +0.6*(sin phi)*sqr sin theta)+0.35)
            ]
            setTexXY x/sizex*2 y/sizex*2
            setXYZ x y z
         ]
         SurfaceColumn
      ]
      SurfaceEnd
      drawEyes
   
      be drawEyes
         disableTexture
         pu setxyz sizex*0.10 y0+size*0.37 sizex*0.47 pd
         setpc white
         sphere sizex*0.03
         pu setxy sizex*0.11 y0+size*0.38 pd
         setpc black
         sphere sizex*0.018
         pu setxyz -sizex*0.10 y0+size*0.37 sizex*0.47 pd
         setpc white
         sphere sizex*0.03
         pu setxy -sizex*0.11 y0+size*0.38 pd
         setpc black
         sphere sizex*0.018
         enableTexture
      end
   end
   be drawFrontLegs ang
      setpc skin
      sizel=sizex*0.13
      sizelr=sizel*0.8
      pu setXYZ sizex*0.5 size*0.7 sizex*0.25 pd
      seth 70+ang
      SurfaceStart
      for [l 1 10]
      [   drawRing l
         pu fd sizelr down 10 pd
         SurfaceColumn
      ]
      SurfaceEnd
      pu up 10 back sizelr pd
      sphere sizel
      pu home
      setXYZ -sizex*0.5 size*0.7 sizex*0.25 pd
      seth -70+ang
      SurfaceStart
      for [l 1 10]
      [   drawRing l
         pu fd sizelr down 10 pd
         SurfaceColumn
      ]
      SurfaceEnd
      pu up 10 back sizelr pd
      sphere sizel
   
      be drawRing l
         up 90
         for [phi -180 180 20]
         [   pu fd sizel pd
            setTexXY l/5 phi/360
            fd 0 
            pu back sizel
            rt 20
         ]
         lt 20
         down 90
      end
   end
   be drawBackLegs ang
      setpc skin
      sizel=sizex*0.13
      sizelr=sizel*0.8
      pu Home
      setXYZ sizex*0.5 -size*0.7 sizex*0.25 pd
      seth 110+ang
      SurfaceStart
      for [l 1 10]
      [   drawRing l
         pu fd sizelr down 10 pd
         SurfaceColumn
      ]
      SurfaceEnd
      pu up 10 back sizelr pd
      sphere sizel
      pu home
      setXYZ -sizex*0.5 -size*0.7 sizex*0.25 pd
      seth -110+ang
      SurfaceStart
      for [l 1 10]
      [   drawRing l
         pu fd sizelr down 10 pd
         SurfaceColumn
      ]
      SurfaceEnd
      pu up 10 back sizelr pd
      sphere sizel
   
      be drawRing l
         up 90
         for [phi -180 180 20]
         [   pu fd sizel pd 
            setTexXY l/5 phi/360
            fd 0 
            pu back sizel
            rt 20
         ]
         lt 20
         down 90
      end
   end
end