Sierpinski arrowhead curve: Difference between revisions

m
→‎{{header|REXX}}: added/changed some comments.
m (→‎{{header|REXX}}: added some comments.)
m (→‎{{header|REXX}}: added/changed some comments.)
Line 869:
say '═════════════════════════════════════════' /* " " separator.*/
call init /*initialize a bunch of variables. */
call arrowheadif order,1 //2 then do; call turn +60; call curve order, len, -60; end /*startCURVE at drawing arrowhead at orderodd? 1*/
call showGraph else call /*displaycurve order, Sierpinskilen, Arrowhead+60 curve /*Curve even.*/
 
showGraph: do row=minY to maxY; _a= /*show arrowhead graph 1 row @at a time.*/
do col=minX to maxX; _a= _a || @.col.row /*build a row of the graph. " " col " " " */
end /*col*/; say _a /*show " " " " row " " " */
end /*row*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
arrowheadcurve: procedure expose ($); parse arg order,len ,angle /*$: [↓] list Is ORDER odd? Turn +,of -exposed variables*/
if order==0 then ifcall order//2draw len then do; call turn +60; call curve order, len, -60; end /*Is ORDER zero? Then draw it.*/
else do; call curve order-1, len/2, -angle; call curve order, len,turn +60angle
return call curve order-1, len/*2, [↑]+angle; Is ORDER even? Turncall +.turn */angle
call curve order-1, len/2, -angle
end
return /*The CURVE funcction is recursive. /*only show the used parts.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
drawLinedraw: select select /*draw part of the curve using a char. */
curve: procedure expose ($); parse arg order,len,angle /*$: a list of variables. */
ifwhen orderheading== 0 then calldo; drawLine len @.x.y= '_'; x= x + 1; /*Is ORDER zero? Draw it. */end
when heading== 60 then do; @.x.y= '/'; elsex= dox + 1; call curve order-1, len/2, -angle; y= y - 1; call turn angleend
when heading==120 then do; x= x - 1; @.x.y= '\'; y= cally curve order-1, len/2, +angle1; call turn angleend
when heading==180 then do; x= x - 1; @.x.y= '_'; call curve order-1, len/2, -angle end
when heading==240 then do; x= x - 1; y= y end + 1; @.x.y= '/*Is'; ORDER ¬0? Turn -, +, -*/end
returnwhen heading==300 then do; y= y + 1; @.x.y= '\'; x= x + 1; /* [↑] CURVE is recursive.*/end
end /*select*/ /*curve character is based on direction*/
minX= min(minX, X); maxX= max(maxX, X) /*save minthe minimum and maxmaximum of X. */
minY= min(minY, Y); maxY= max(maxY, Y) /* " " /* " " " " " Y. */
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
init: $= '@. heading maxX maxY minX minY x y'; @.=" "; heading= 0; len= 1
drawLine: select /*draw part of the curve using a char. */
!= 2e7+1; when heading=x= !; 0 then do; @.x.y= '_'!; x= x +maxX= 1!; maxY= !; minX= !; minY= end!
return</lang>
when heading== 60 then do; @.x.y= '/'; x= x + 1; y= y - 1; end
when heading==120 then do; x= x - 1; @.x.y= '\'; y= y - 1; end
when heading==180 then do; x= x - 1; @.x.y= '_'; end
when heading==240 then do; x= x - 1; y= y + 1; @.x.y= '/'; end
when heading==300 then do; y= y + 1; @.x.y= '\'; x= x + 1; end
end /*select*/ /*curve character is based on direction*/
minX= min(minX, X); maxX= max(maxX, X) /*save min and max of X. */
minY= min(minY, Y); maxY= max(maxY, Y) /* " " " " " Y. */
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
turn: parse arg angle; heading= (heading + angle)//360 /*normalize angleheading <360º (±)*/
init: $= '@. heading maxX maxY minX minY x y'; @.=" "; heading= 0
if heading<0 then !heading= 2e7heading +1; 360 x= !; y= !; /*positize the angle. maxX= !; maxY= !; minX= !; minY= !*/
return</lang>
{{out|output|text=&nbsp; when using the default input value of: &nbsp; &nbsp; <tt> 5 </tt>}}
/*──────────────────────────────────────────────────────────────────────────────────────*/
showGraph: do row=minY to maxY; _= /*show graph 1 row @ a time*/
do col=minX to maxX; _= _ || @.col.row /*build a row of the graph.*/
end /*col*/; say _ /*show " " " " " */
end /*row*/
return /*only show the used parts.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
turn: parse arg angle; heading= (heading + angle)//360 /*normalize angle <360º (±)*/
if heading<0 then heading= heading + 360 /*positize the angle. */
return</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Sierpinski arrowhead curve of order 5