@@ -95,6 +95,10 @@ function randommask(args...; maskshape=:rand, kargs...)
95
95
return randomstar (equalwh (args... )... ; kargs... )
96
96
end
97
97
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
98
102
function randombox (w, h; cornerradius= :rand , keeparea= false , kargs... )
99
103
if cornerradius == :rand
100
104
r = rand () * 0.5 - 0.05 # up to 0.45
@@ -105,7 +109,7 @@ function randombox(w, h; cornerradius=:rand, keeparea=false, kargs...)
105
109
end
106
110
sc = keeparea ? sqrt (w* h/ box_area (w, h, cornerradius= r)) : 1
107
111
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... )
109
113
return shape (box, w, h; cornerradius= r, kargs... )
110
114
end
111
115
function randomsquircle (w, h; rt= :rand , keeparea= false , kargs... )
@@ -124,32 +128,44 @@ function randomsquircle(w, h; rt=:rand, keeparea=false, kargs...)
124
128
end
125
129
sc = keeparea ? sqrt (w* h/ squircle_area (w, h, rt= rt)) : 1
126
130
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... )
128
132
return shape (squircle, w, h, rt= rt; kargs... )
129
133
end
130
134
function randomellipse (w, h; keeparea= false , kargs... )
131
135
sc = keeparea ? sqrt (w* h/ ellipse_area (w, h)) : 1
132
136
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... )
134
138
return shape (ellipse, w, h; kargs... )
135
139
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... )
137
151
npoints = npoints == :rand ? rand (3 : 12 ) : npoints
152
+ orientation = orientation == :rand ? randomorientation (npoints) : orientation
138
153
sc = keeparea ? sqrt (w* h/ ngon_area (w, h, npoints= npoints)) : 1
139
154
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... )
142
157
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... )
144
159
npoints = npoints == :rand ? rand (5 : 12 ) : npoints
160
+ orientation = orientation == :rand ? randomorientation (npoints) : orientation
145
161
if starratio == :rand
146
162
starratio = cos (π/ npoints) * (0.7 + 0.25 rand ())
147
163
starratio = round (starratio, digits= 3 )
148
164
end
149
165
sc = keeparea ? sqrt (w* h/ star_area (w, h, npoints= npoints, starratio= starratio)) : 1
150
166
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... )
153
169
end
154
170
function randomangles ()
155
171
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