Skip to content

Instantly share code, notes, and snippets.

@fwip
Created July 27, 2019 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwip/2135e3b4aba42cd59f0e96d584215b7c to your computer and use it in GitHub Desktop.
Save fwip/2135e3b4aba42cd59f0e96d584215b7c to your computer and use it in GitHub Desktop.
an example on how to draw confetti in pico-8
function create_confetti()
v=1.4 --initial velocity
size=40
-- the center of the confetti
balloon_x=40
balloon_y=40
for i=1,100 do
local r=rnd(size) -- this is how far out from the center it starts
local n=rnd(1) -- this is the angle it goes at
confetti[i] = {
dx=v*r*cos(n), -- dx is delta-X, the rate of change in the x-direction
dy=20+v*r*sin(n), -- add 20 for a little boost, it looks better when they start going upward some
x=balloon_x+cos(n)*r,
y=balloon_y+sin(n)*r,
clr=3+rnd(12), -- random color
}
end
end
function update_confetti(dt)
local friction=.6
local gravity=.4
for c in all(confetti) do
-- calculate new position
c["x"] += c["dx"] * dt
c["y"] += c["dy"] * dt
-- slow down the confetti a bit
c["dx"] -= c["dx"] * friction * dt
c["dy"] -= c["dy"] * friction * dt
-- gravity pulls it down
c["dy"] += gravity
end
end
function draw_confetti()
for c in all(confetti) do
rect(c["x"], c["y"], c["x"], c["y"], c["clr"])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment