Skip to content

Instantly share code, notes, and snippets.

@serpent7776
Created December 29, 2016 13:23
Show Gist options
  • Select an option

  • Save serpent7776/0a6b5b3dbe676e8cccd877d33ef8aea9 to your computer and use it in GitHub Desktop.

Select an option

Save serpent7776/0a6b5b3dbe676e8cccd877d33ef8aea9 to your computer and use it in GitHub Desktop.

Revisions

  1. serpent7776 created this gist Dec 29, 2016.
    33 changes: 33 additions & 0 deletions main.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    function love.load()
    canvas = love.graphics.newCanvas(800, 600)
    x = 400
    y = 300
    r = 10
    vx = math.random() * 100
    vy = math.random() * 100
    end

    function love.update(dt)
    x = x + vx * dt
    y = y + vy * dt
    if x < 0 or x > 800 - r then
    vx = - vx
    end
    if y < 0 or y > 600 - r then
    vy = - vy
    end
    end

    function love.draw()
    love.graphics.setCanvas(canvas)
    love.graphics.setBlendMode("alpha")
    love.graphics.setColor(0, 0, 0, 5)
    love.graphics.rectangle("fill", 0, 0, 800, 600)
    love.graphics.setColor(255, 255, 255, 255)
    love.graphics.rectangle("fill", x, y, r, r)
    -- draw
    love.graphics.setCanvas()
    love.graphics.clear()
    love.graphics.setBlendMode("alpha", "premultiplied")
    love.graphics.draw(canvas)
    end