def setup
@motif =
@center =
@count =5
@size =80
@inverted =
createCanvas(windowWidth, windowWidth)
end
def draw
background(255)
translate(width / 2, height / 2)
r = width * 0.38
noFill
stroke(0)
strokeWeight(r * 0.08)
circle(0, 0, r * 2)
strokeWeight(r * 0.022)
circle(0, 0, r * 1.82)
s = r * 0.87 * @size / 100
if @inverted
noFill
stroke(0)
strokeWeight(r * 0.02)
else
fill(0)
noStroke
end
case @motif
when "maru"
draw_maru(s)
when "hishi"
draw_hishi(s)
when "hana"
draw_hana(s)
when "ougi"
draw_ougi(s)
when "uroko"
draw_uroko(s)
end
center_d = s * 0.35
case @center
when "white"
fill(255)
noStroke
circle(0, 0, center_d)
when "black"
fill(0)
noStroke
circle(0, 0, center_d)
when "ring"
noFill
stroke(0)
strokeWeight(r * 0.02)
circle(0, 0, center_d)
end
end
def draw_maru(s)
petal_r = s * 0.31
dist = s * 0.69
@count.times do |i|
a = TWO_PI / @count * i - HALF_PI
circle(cos(a) * dist, sin(a) * dist, petal_r * 2)
end
end
def draw_hishi(s)
@count.times do |i|
a = TWO_PI / @count * i
ca = cos(a)
sa = sin(a)
px = -sa
py = ca
d = s * 0.93
w = s * 0.14
quad(0, 0, ca * d * 0.5 + px * w, sa * d * 0.5 + py * w, ca * d, sa * d, ca * d * 0.5 - px * w, sa * d * 0.5 - py * w)
end
end
def draw_hana(s)
@count.times do |i|
a = TWO_PI / @count * i - HALF_PI
ca = cos(a)
sa = sin(a)
px = -sa
py = ca
tip = s
w = s * 0.26
beginShape
steps = 12
(steps + 1).times do |st|
t = st.to_f / steps
d = tip * t
pw = sin(t * PI) * w
vertex(ca * d + px * pw, sa * d + py * pw)
end
steps.downto(0) do |st|
t = st.to_f / steps
d = tip * t
pw = sin(t * PI) * w
vertex(ca * d - px * pw, sa * d - py * pw)
end
endShape(CLOSE)
end
end
def draw_ougi(s)
span = TWO_PI / @count * 0.35
d = s * 1.86
@count.times do |i|
a = TWO_PI / @count * i - HALF_PI
arc(0, 0, d, d, a - span, a + span, PIE)
end
end
def draw_uroko(s)
tip_d = s * 0.93
base_d = s * 0.3
base_w = s * 0.28
@count.times do |i|
a = TWO_PI / @count * i - HALF_PI
ca = cos(a)
sa = sin(a)
px = -sa
py = ca
triangle(ca * tip_d, sa * tip_d, ca * base_d + px * base_w, sa * base_d + py * base_w, ca * base_d - px * base_w, sa * base_d - py * base_w)
end
end