Skip to content

Commit c59bab6

Browse files
committed
randomorientation
1 parent 08f5e21 commit c59bab6

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/artist.jl

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ function randommask(args...; maskshape=:rand, kargs...)
9595
return randomstar(equalwh(args...)...; kargs...)
9696
end
9797
end
98+
function showcallshape(args...; kargs...)
99+
ags = [string(args[1]), repr.(args[2:end])..., ("$k=$(repr(v))" for (k, v) in kargs)...]
100+
println("shape(", join(ags, ", "), ")")
101+
end
98102
function randombox(w, h; cornerradius=:rand, keeparea=false, kargs...)
99103
if cornerradius == :rand
100104
r = rand() * 0.5 - 0.05 # up to 0.45
@@ -105,7 +109,7 @@ function randombox(w, h; cornerradius=:rand, keeparea=false, kargs...)
105109
end
106110
sc = keeparea ? sqrt(w*h/box_area(w, h, cornerradius=r)) : 1
107111
w = round(Int, w*sc); h = round(Int, h*sc); r = round(Int, r*sc)
108-
println("shape(box, $w, $h, cornerradius=$r", join([", $k=$(repr(v))" for (k, v) in kargs]), ")")
112+
showcallshape(box, w, h; cornerradius=r, kargs...)
109113
return shape(box, w, h; cornerradius=r, kargs...)
110114
end
111115
function randomsquircle(w, h; rt=:rand, keeparea=false, kargs...)
@@ -124,32 +128,44 @@ function randomsquircle(w, h; rt=:rand, keeparea=false, kargs...)
124128
end
125129
sc = keeparea ? sqrt(w*h/squircle_area(w, h, rt=rt)) : 1
126130
w = round(Int, w*sc); h = round(Int, h*sc)
127-
println("shape(squircle, $w, $h, rt=$rt", join([", $k=$(repr(v))" for (k, v) in kargs]), ")")
131+
showcallshape(squircle, w, h, rt=rt; kargs...)
128132
return shape(squircle, w, h, rt=rt; kargs...)
129133
end
130134
function randomellipse(w, h; keeparea=false, kargs...)
131135
sc = keeparea ? sqrt(w*h/ellipse_area(w, h)) : 1
132136
w = round(Int, w*sc); h = round(Int, h*sc)
133-
println("shape(ellipse, $w, $h", join([", $k=$(repr(v))" for (k, v) in kargs]), ")")
137+
showcallshape(ellipse, w, h; kargs...)
134138
return shape(ellipse, w, h; kargs...)
135139
end
136-
function randomngon(w, h; npoints=:rand, keeparea=false, kargs...)
140+
function randomorientation(n)
141+
if n == 3
142+
ori = rand((0, π/2, π/3))
143+
elseif n % 2 == 0
144+
ori = rand((0, π/n))
145+
else
146+
ori = 0
147+
end
148+
return ori
149+
end
150+
function randomngon(w, h; npoints=:rand, orientation=:rand, keeparea=false, kargs...)
137151
npoints = npoints == :rand ? rand(3:12) : npoints
152+
orientation = orientation == :rand ? randomorientation(npoints) : orientation
138153
sc = keeparea ? sqrt(w*h/ngon_area(w, h, npoints=npoints)) : 1
139154
w = round(Int, w*sc); h = round(Int, h*sc)
140-
println("shape(ngon, $w, $h, npoints=$npoints", join([", $k=$(repr(v))" for (k, v) in kargs]), ")")
141-
return shape(ngon, w, h; npoints=npoints, kargs...)
155+
showcallshape(ngon, w, h; npoints=npoints, orientation=orientation, kargs...)
156+
return shape(ngon, w, h; npoints=npoints, orientation=orientation, kargs...)
142157
end
143-
function randomstar(w, h; npoints=:rand, starratio=:rand, keeparea=false, kargs...)
158+
function randomstar(w, h; npoints=:rand, starratio=:rand, orientation=:rand, keeparea=false, kargs...)
144159
npoints = npoints == :rand ? rand(5:12) : npoints
160+
orientation = orientation == :rand ? randomorientation(npoints) : orientation
145161
if starratio == :rand
146162
starratio = cos/npoints) * (0.7 + 0.25rand())
147163
starratio = round(starratio, digits=3)
148164
end
149165
sc = keeparea ? sqrt(w*h/star_area(w, h, npoints=npoints, starratio=starratio)) : 1
150166
w = round(Int, w*sc); h = round(Int, h*sc)
151-
println("shape(star, $w, $h, npoints=$npoints, starratio=$starratio", join([", $k=$(repr(v))" for (k, v) in kargs]), ")")
152-
return shape(star, w, h; npoints=npoints, starratio=starratio, kargs...)
167+
showcallshape(star, w, h; npoints=npoints, starratio=starratio, orientation=orientation, kargs...)
168+
return shape(star, w, h; npoints=npoints, starratio=starratio, orientation=orientation, kargs...)
153169
end
154170
function randomangles()
155171
a = rand((-1, 1)) .* rand((0, (0, 90), (0, 90, 45), (0, 90, 45, -45), (0, 45, -45), (45, -45), -90:90, 0:90))

0 commit comments

Comments
 (0)