Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- left click: move towards
- -- right click: set center
- -- wheel: rotation speed
- -- play around with these values:
- local pennum = 800 -- higher == more awesomeness but more lag
- local mousegrav = 0.04 -- higher == higher attraction towards mouse
- local rotation = 2 -- rotation speed
- local fadeout = 0.2 -- higher == less after-image
- local wobbly = 0 -- higher == more random target
- local time = 0
- local targetx = 401
- local targety = 301
- function hsl2rgb(h, s, l)
- local r, g, b = 0, 0, 0
- if s == 0 then
- r = l
- g = l
- b = l
- else
- local function hue2rgb(p, q, t)
- if t < 0 then t = t + 1 end
- if t > 1 then t = t - 1 end
- if t < 1/6 then return p + (q - p) * 6 * t end
- if t < 1/2 then return q end
- if t < 2/3 then return p + (q - p) * (2/3 - t) * 6 end
- return p
- end
- local q = (l < 0.5) and (l * (1 + s)) or (l + s - l * s)
- local p = 2 * l - q
- r = hue2rgb(p, q, h + 1/3)
- g = hue2rgb(p, q, h)
- b = hue2rgb(p, q, h - 1/3)
- end
- return math.floor(r * 255), math.floor(g * 255), math.floor(b * 255)
- end
- function love.load()
- -- love.graphics.setLineStyle("rough") -- ugly
- canvas = love.graphics.newCanvas()
- pens = {}
- for i = 1, pennum do
- pens[i] = {
- x = 400,
- y = 300,
- lx = 400,
- ly = 300
- }
- end
- end
- function love.draw()
- love.graphics.setCanvas(canvas)
- love.graphics.setColor(0, 0, 0, 255 * fadeout)
- love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
- for i, v in ipairs(pens) do
- love.graphics.setColor(hsl2rgb(i / pennum, 1, math.min(time / 2, 0.5)))
- love.graphics.line(v.lx, v.ly, v.x, v.y)
- end
- love.graphics.setCanvas()
- love.graphics.setColor(255, 255, 255)
- love.graphics.draw(canvas, 0, 0)
- love.graphics.print("FPS: " .. love.timer.getFPS())
- end
- function love.update(dt)
- if wobbly ~= 0 then
- targetx = (targetx + (math.random() * 800) * wobbly) / (1 + wobbly)
- targety = (targety + (math.random() * 600) * wobbly) / (1 + wobbly)
- end
- if love.mouse.isDown("r") then
- targetx, targety = love.mouse.getPosition()
- end
- for i, v in ipairs(pens) do
- v.lx = v.x
- v.ly = v.y
- local x, y = v.x, v.y
- local r = math.cos(time * (i / pennum)) * rotation * dt * ((targetx / 800) + (targety / 600))
- local nx = targetx + (x - targetx) * math.cos(r) - (y - targety) * math.sin(r)
- local ny = targety + (x - targetx) * math.sin(r) + (y - targety) * math.cos(r)
- x = (x + nx) / 2
- y = (y + ny) / 2
- if love.mouse.isDown("l") then
- local mx, my = love.mouse.getPosition()
- --local nx = mx + (x - mx) * math.cos(r) - (y - my) * math.sin(r)
- --local ny = my + (x - mx) * math.sin(r) + (y - my) * math.cos(r)
- x = (x + mx * mousegrav) / (1 + mousegrav)
- y = (y + my * mousegrav) / (1 + mousegrav)
- end
- v.x, v.y = x, y
- end
- time = time + dt
- end
- function love.mousepressed(x, y, b)
- if b == "wd" then
- rotation = rotation - 1
- elseif b == "wu" then
- rotation = rotation + 1
- end
- end
- function love.keypressed(k)
- if k == "escape" then
- love.event.push("quit")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement