Reputation: 327
Any idea how to draw this in Postscript using for loop and ifelse conditional?
My idea was to make a large red circle, then a smaller white circle and a smaller red circle again... Also we can see that the color is getting darker so it should also be saved as a variable that gets darker.
50 50 translate
/coordinate_system {0.5 0.3 0 0 setcmykcolor
gsave
2 setlinewidth 500 0 moveto 0 0 lineto 0 500 lineto stroke
grestore
gsave
0.3 setlinewidth
9 { 30 100 moveto 500 100 lineto stroke 0 50 translate } repeat
grestore
gsave
0.3 setlinewidth
10 { 100 20 moveto 100 500 lineto stroke 50 0 translate } repeat
grestore
gsave
/tekst 3 string def /Helvetica findfont 10 scalefont setfont
100 100 500 { /y exch def 5 y 2 sub moveto y tekst cvs show } for
90 100 500 { /x exch def x 5 moveto x 10 add tekst cvs show } for
grestore
0 setgray } bind def
/s { mark pstack pop } def
coordinate_system
And this is the code so far...
100 100 translate
%100 -3 0 {{1 0 0 setrgbcolor exch 0 exch 0 360 arc stroke}{0 0 0 setrgbcolor exch 0 exch 0 360 arc stroke} ifelse} for
3 4 lt {1 0 0 setrgbcolor 0 0 50 0 360 arc stroke}{0 0 0 setrgbcolor 0 0 100 0 360 arc stroke} ifelse
Upvotes: 2
Views: 418
Reputation: 3765
The following code loops for i = 1, 2, ..., 10
. I am using i
to control the radius and color of the circle.
/i 1 def
{
i 0.1 mul 0 0 setrgbcolor % RGB (i*0.1, 0, 0)
i 10 gt { exit } if % exit the loop if i > 10
300 300 % center at 300 300
20 i mul % radius 20*i
drawcircle
/i i 1 add def % i = i + 1
} loop
drawcircle
code:
/drawcircle % XO YO R
{
newpath
0 360 arc
closepath
stroke
} bind def
3 setlinewidth
My output (cropped a bit) is:
Upvotes: 2