Skip to content

Instantly share code, notes, and snippets.

@nna774
Last active January 24, 2025 18:14
Show Gist options
  • Save nna774/c012ff2ed4a49a200e0cf80652b37389 to your computer and use it in GitHub Desktop.
Save nna774/c012ff2ed4a49a200e0cf80652b37389 to your computer and use it in GitHub Desktop.
1012
def size = 400
def shake(base:, width:)
base + width / 2 - rand(width)
end
foots = 6.times.map { }
def setup
createCanvas(size, size)
noStroke
frameRate(1)
#noLoop
end
def draw
background("black")
k = lambda { shake(base: size/2, width: size / 8) }
o = Struct.new(:x, :y, :rect).new(k[], k[], size/5)
(["green", "magenta", "yellow"] * 2).each do |c|
b = Math::PI * rand(360) / 360
draw_foot(o: o, b: b, color: c)
end
fill("orange")
ellipse(o.x, o.y, o.rect)
end
# o is zero point, b is base
def draw_foot(o:, b:, color:)
f = make_foot(o: o, b: b)
#puts f[0]
f.each do |p|
fill(color)
ellipse(p[:x], p[:y], p[:radius])
end
end
def make_foot(o:, b:)
rand_base = 5
foot_r = 8
dr = foot_r / 3
db = foot_r / 2
r = o.rect / 2
t_base = 100
t = t_base / 2 + rand(t_base / 2)
b_direction = 1
r_direction = 1
points = []
t.times do |i|
points << { x: o.x + r * Math.cos(b), y: o.y + r * Math.sin(b), radius: foot_r }
if i % 10 == 0 && rand < 0.3
b_direction *= -1
end
if i % 5 == 0 && rand < 0.1
r_direction *= -1
end
r += dr * r_direction
b += rand(rand_base * 2) * Math::PI / 360 * b_direction
end
points
end
def move_foot
# どうしよう。。
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment