Skip to content

Instantly share code, notes, and snippets.

@treytomes
Last active April 18, 2024 18:40
Show Gist options
  • Save treytomes/934e330f0a299799b91137d2607a1f44 to your computer and use it in GitHub Desktop.
Save treytomes/934e330f0a299799b91137d2607a1f44 to your computer and use it in GitHub Desktop.
Building a simple scene graph, part 1
import "tc"
import "stringUtil"
Ellipse = {}
Ellipse.make = function(x, y, width, height, color=null, penSize=1)
if color == null then color == gfx.color
self.left = x - width / 2
self.bottom = y - height / 2
self.width = width
self.height = height
self.color = color
self.penSize = penSize
return self
end function
Ellipse.draw = function
gfx.drawEllipse self.left, self.bottom, self.width, self.height, self.color, self.penSize
end function
Ellipse.moveTo = function(x, y)
self.left = x - self.width / 2
self.bottom = y - self.height / 2
end function
Circle = new Ellipse
Circle.make = function(x, y, radius, color=null, penSize=1)
diameter = radius * 2
Ellipse.make(x, y, diameter, diameter, color, penSize)
return self
end function
Circle.getRadius = function
return self.width / 2
end function
Circle.setRadius = function(r)
self.width = r * 2
self.height = r * 2
end function
clear
ellipse = (new Ellipse).make(200, 200, 400, 150, color.red, 3)
circle = (new Circle).make(100, 300, 40, color.blue, 2)
isRunning = true
while isRunning
tc.flip
gfx.clear
ellipse.draw
circle.draw
circle.moveTo mouse.x, mouse.y
scrollDelta = key.axis("Mouse ScrollWheel")
circle.setRadius circle.getRadius + scrollDelta
end while
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment