shithub: slug

ref: fdf4c12f78354d0886bc1ff29f7605bb671f4a91
dir: /samples/bounce.lua/

View raw version
#!/bin/slug

function setup()
	size(400, 400)
end

x = math.random(400)
y = math.random(400)
vx = 1
vy = 1
function draw()
	background(200)
	fill(255, 100, 100)
	circle(x, y, 20)
	x = x + vx
	if x < 10 then
		x = 10
		vx = -vx
	elseif x > width - 10 then
		x = width - 10
		vx = -vx
	end
	y = y + vy
	if y < 10 then
		y = 10
		vy = -vy
	elseif y > height - 10 then
		y = height - 10
		vy = -vy
	end
end