Skip to content

Instantly share code, notes, and snippets.

@Bri-G
Created March 14, 2012 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bri-G/2036275 to your computer and use it in GitHub Desktop.
Save Bri-G/2036275 to your computer and use it in GitHub Desktop.
Rotation of a sphere
-- Sphere rotation program
-- main.lua first
-- Use this function to perform your initial setup
function setup()
-- displayMode(FULLSCREEN)
ballX =3D 300
ballY =3D 300
diameter =3D 200
rot =3D 0
watch("x")
watch("y")
parameter("rot",0,90)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(86, 37, 90, 255)
strokeWidth(5)
stroke(186, 218, 20, 255)
Sphere:draw(ballX,ballY,ballZ,diameter)
end
-- Sphere.lua to follow
Sphere =3D class()
function Sphere:init()
-- you can accept and set parameters here
self.x =3D x
self.y =3D y
self.z =3D z
self.diameter =3D 50
end
function Sphere:draw(x,y,diameter,diameter)
-- Codea does not automatically call this method
pushStyle()
pushMatrix()
fill(48, 181, 200, 255)
stroke(7, 8, 7, 255)
strokeWidth(1)
ellipseMode(CENTER)
ellipse(x,y,diameter,diameter)
noFill()
diff =3D diameter/10
rotate(rot)
for loop =3D 1, 9 do
angle =3D loop*diff
ellipse(x,y,diameter,angle)
ellipse(x,y,angle,diameter)
end
popMatrix()
popStyle()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment