Creative Coding 習作 2024/5/23 - RubyKaigi 2024 写経
code:ruby
def setup
createCanvas(400, 400)
background("#fced4f")
frameRate(5)
end
def draw
translate(width / 2, height / 2)
rotate(HALF_PI - frameCount)
draw_frame
draw_minsa
draw_ruby
end
def draw_frame
strokeWeight(3)
fill("#9cee60")
ellipse(0, 0, 280)
fill(255)
ellipse(0, 0, 250)
fill("#9cee60")
ellipse(0, 0, 190)
fill(255)
ellipse(0, 0, 170)
end
def draw_minsa
noStroke
fill(0)
rect_count = 10
3.times do |t|
radius = 100 + 10 * t
interval_angle = TWO_PI / rect_count
rect_count.times do |i|
angle = i * interval_angle
x = radius * cos(angle)
y = radius * sin(angle)
push
translate(x, y)
rotate(angle)
rectMode(CENTER)
if t.even?
if i.odd?
rect(0, 0, 10, 10)
else
rect(0, 0 - 10, 10, 10)
rect(0, 0 + 10, 10, 10)
end
else
if i.even?
rect(0, 0, 10, 10)
else
rect(0, 0 - 10, 10, 10)
rect(0, 0 + 10, 10, 10)
end
end
pop
end
end
end
def draw_ruby
stroke(0)
fill("#ec6158")
rotate(TWO_PI + frameCount)
beginShape()
vertex(-45, 45)
vertex(-45, -45)
vertex(-10, -70)
vertex(65, 0)
vertex(-10, 70)
endShape(CLOSE)
line(-45, 45, -10, 25)
line(-45, 0, -10, 25)
line(-45, 0, -10, -25)
line(-45, -45, -10, -25)
line(-10, 70, -10, -70)
line(-10, 25, 65, 0)
line(-10, -25, 65, 0)
end
https://scrapbox.io/files/66529d7cff6267001c4a5949.png