Advertisement
Guest User

Here's my 1 line of code

a guest
Dec 10th, 2013
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. displayMode(FULLSCREEN) function setup() spriteMode(CENTER) Player:init() end function draw() background(0, 0, 0, 255) Player:draw() end Player = class() function Player:init() player = System(WIDTH/2, HEIGHT/2, 100, 1) player:addPlanet(player, 400, 150, 50, 0, 0.02) player:addMoon(player.planets[1], 50, 20, 0, 0.1) player:addPlanet(player, 150, 300, 50, 117, 0.015) player:addMoon(player.planets[2], 50, 20, 43, 0.09) player.planets[1].col = color(53, 67, 202, 255) player.planets[2].col = color(43, 138, 77, 255) end function Player:draw() player:draw() end System = class() function System:init(x, y, r, s) self.x = x self.y = y self.s = s self.radius = r self.moons = {} self.planets = {} end function System:draw() fill(255, 255, 0, 255) ellipse(self.x, self.y, self.radius) for i = 1, #self.planets do self.planets[i]:draw() end for i = 1, #self.moons do self.moons[i]:draw() end end function System:addMoon(parent, distance, radius, startangle, speed) self.moons[#self.moons+1] = Moon(parent, distance, radius, startangle, speed) end function System:addPlanet(parent, max, min, radius, startangle, speed) self.planets[#self.planets + 1] = Planet(parent, max, min, radius, startangle, speed) end Planet = class() function Planet:init(parent, max, min, radius, startangle, speed) self.parent = parent self.x = self.parent.x + max self.y = self.parent.y self.max = max self.min = min self.radius = radius self.col = color(0, 0, 255, 255) self.angle = startangle self.speed = speed end function Planet:draw() self.angle = self.angle + self.speed self:rotate() fill(self.col) ellipse(self.x, self.y, self.radius) end function Planet:rotate() self.x = self.max * math.cos(self.angle) self.y = self.min * math.sin(self.angle) self.x, self.y = self.parent.x + self.x, self.parent.y + self.y end Moon = class() function Moon:init(parent, distance, radius, startangle, speed) self.parent = parent self.x = self.parent.x + distance self.y = self.parent.y self.distance = distance self.radius = radius self.angle = startangle self.speed = speed end function Moon:rotate() self.x = self.distance * math.cos(self.angle) self.y = self.distance * math.sin(self.angle) self.x, self.y = self.parent.x + self.x, self.parent.y + self.y end function Moon:draw() self.angle = self.angle + self.speed self:rotate() fill(128, 114, 114, 255) ellipse(self.x, self.y, self.radius) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement