Bubbles Tweetcart (PICO-8)

Today I made my first PICO-8 tweetcart! It’s the bubbles screensaver, but under 280 characters.

Here’s the source code:

l={}r=12v=115a=0::_::cls(12)a+=.003
for i=1,15do
if(#l<i)l[i]={x=i,y=v}
b=l[i]b.x=mid(r,b.x+cos(a),v)b.y=mid(r,b.y+sin(a),v)for g in all(l)do
j=g.x-b.x
k=g.y-b.y
d=sqrt(j^2+k^2)p=(24-d)/d
if(d>24)p=0
q=j*p
w=k*p
b.x-=q
b.y-=w
g.x+=q
g.y+=w
end
circ(b.x,b.y,r,7)end
flip()goto _

And here’s the unminified source code:

function _init()
	l = {} -- list of bubbles
	r = 12 -- bubble radius
	a = 0 -- bubble rotation angle
end

function _draw()
	cls(12)
	a += .003 -- slowly rotate all the bubbles counterclockwise
	
	for i=1, 15 do
		-- initialize the bubbles
		if #l<i then
			l[i] = { x=i, y=115 }
		end
		
		b = l[i]
		-- move the bubble, but clamp it to inside the screen
		b.x = mid(r,b.x+cos(a),115)
		b.y = mid(r,b.y+sin(a),115)
		-- check collisions
		for g in all(l) do
			dx = g.x-b.x
			dy = g.y-b.y
			dist = sqrt(dx^2+dy^2)
			p = (r*2 - dist) / dist
			if dist < r * 2 then -- push the bubbles apart
				ox = dx * p
				oy = dy * p
				b.x -= ox
				b.y -= oy
				g.x += ox
				g.y += oy
			end
		end
		circ(b.x, b.y, r, 7)
	end
end

Leave a comment

Your email address will not be published. Required fields are marked *

Your data is processed in accordance with my privacy policy. Comments are manually approved and may take a while to appear.