Last active
April 18, 2024 18:40
-
-
Save treytomes/934e330f0a299799b91137d2607a1f44 to your computer and use it in GitHub Desktop.
Building a simple scene graph, part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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