Re: Code Doodles!
Posted: Mon May 26, 2014 2:37 am
This is something inspired by one of the first things I ever did in Love.
It's simple, but it looks pretty cool.
It's simple, but it looks pretty cool.
Code: Select all
-- CrackedP0t's First Code Doodle
-- Arrow keys to maneuver, space for new rectangles
function makerects()
rects = {}
for i=1, math.random(10,20) do
table.insert(rects, {x = math.random(0-winw, winw*2), y = math.random(0-winh, winh*2), width = math.random(20, 200), height = math.random(20, 200), color = {math.random(255),math.random(255),math.random(255),255}})
end
end
function love.load()
love.window.setTitle("CrackedP0t's First Code Doodle")
winh = love.window.getHeight()
winw = love.window.getWidth()
love.window.setMode(winw, winh, {resizable = true})
camera = {x = 0, y = 0}
math.randomseed(os.time())
makerects()
end
function love.update(dt)
winh = love.window.getHeight()
winw = love.window.getWidth()
if love.keyboard.isDown(" ") then makerects() end
if love.keyboard.isDown("left") then camera.x = camera.x + 10 end
if love.keyboard.isDown("right") then camera.x = camera.x - 10 end
if love.keyboard.isDown("up") then camera.y = camera.y + 10 end
if love.keyboard.isDown("down") then camera.y = camera.y - 10 end
end
function love.draw()
love.graphics.translate(camera.x, camera.y)
for _, rect in ipairs(rects) do
love.graphics.setColor(rect.color)
love.graphics.rectangle("line", rect.x, rect.y, rect.width, rect.height)
love.graphics.line(winw/2 - camera.x,winh/2 - camera.y, rect.x, rect.y)
love.graphics.line(winw/2 - camera.x,winh/2 - camera.y, rect.x + rect.width, rect.y)
love.graphics.line(winw/2 - camera.x,winh/2 - camera.y, rect.x + rect.width, rect.y + rect.height)
love.graphics.line(winw/2 - camera.x,winh/2 - camera.y, rect.x, rect.y + rect.height)
end
end