Advertisement
briandorBriG

SphereRotation

Mar 14th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. -- Sphere rotation program
  2.  
  3. -- main.lua first
  4.  
  5. -- Use this function to perform your initial setup
  6. function setup()
  7.    
  8. --  displayMode(FULLSCREEN)
  9.     ballX =3D 300
  10.     ballY =3D 300
  11.     diameter =3D 200
  12.     rot =3D 0
  13.     watch("x")
  14.     watch("y")
  15.     parameter("rot",0,90)
  16. end
  17.  
  18. -- This function gets called once every frame
  19. function draw()
  20.     -- This sets a dark background color
  21.     background(86, 37, 90, 255)
  22.     strokeWidth(5)
  23.     stroke(186, 218, 20, 255)
  24.     Sphere:draw(ballX,ballY,ballZ,diameter)
  25.  
  26.  
  27. end
  28.  
  29.  
  30. -- Sphere.lua to follow
  31.  
  32. Sphere =3D class()
  33.  
  34. function Sphere:init()
  35.     -- you can accept and set parameters here
  36.     self.x =3D x
  37.     self.y =3D y
  38.     self.z =3D z
  39.     self.diameter =3D 50
  40. end
  41.  
  42. function Sphere:draw(x,y,diameter,diameter)
  43.     -- Codea does not automatically call this method
  44.     pushStyle()
  45.     pushMatrix()
  46.     fill(48, 181, 200, 255)
  47.     stroke(7, 8, 7, 255)
  48.     strokeWidth(1)
  49.     ellipseMode(CENTER)
  50.     ellipse(x,y,diameter,diameter)
  51.     noFill()
  52.     diff =3D diameter/10    
  53.     rotate(rot)
  54.     for loop =3D 1, 9 do
  55.         angle =3D loop*diff
  56.         ellipse(x,y,diameter,angle)
  57.         ellipse(x,y,angle,diameter)  
  58.     end  
  59.     popMatrix()
  60.     popStyle()
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement