Yin and Yang

Rosetta Code task- "Create a function that given a variable representing size, generates a Yin and yang also known as a Taijitu symbol scaled to that size. Generate and display the symbol generated for two different (small) sizes. Rosetta Code, Yin & Yang

Generalised to give colour options, and callable as a function, see second version below.....

Note that the first version uses the less efficient up -goto -down, while the second uses 'place'. (Thanks, Stefan) and replaces the boxfilled with piefilled, allowing more than one YinYang to be placed on a window ( thanks Alyce!).

nomainwin

WindowWidth  =410
WindowHeight =440

open "Yin & Yang" for graphics_nf_nsb as #w

#w "trapclose [quit]"

call YinYang 200, 200, 200
call YinYang 120,  50,  50

wait

sub YinYang x, y, size

#w "up ; goto "; x; " "; y
#w "backcolor black ; color black"
#w "down ; circlefilled "; size /2

#w "color 255 255 255 ; backcolor 255 255 255"
#w "up   ; goto ";      x -size /2; " "; y -size /2
#w "down ; boxfilled "; x;          " "; y +size /2

#w "up ; goto "; x; " "; y -size /4
#w "down ; backcolor black ; color black   ; circlefilled "; size  /4
#w "up ; goto "; x; " "; y -size /4
#w "down ; backcolor white ; color white ; circlefilled "; size /12

#w "up ; goto "; x; " "; y +size /4
#w "down ; backcolor white ; color white ; circlefilled "; size  /4
#w "up ; goto "; x; " "; y +size /4
#w "down ; backcolor black ; color black ; circlefilled "; size /12

#w "up ; goto "; x; " "; y
#w "down ; color black ; circle "; size /2

#w "flush"

end sub

scan

wait

[quit]
close #w
end

Version 2

nomainwin

WindowWidth  =410
WindowHeight =440

open "Yin & Yang" for graphics_nf_nsb as #w

#w "trapclose [quit]"

#w "down"

for i =1 to 100
x     =20 +400 *rnd( 1)
y     =20 +400 *rnd( 1)
size  =20 + 50 *rnd( 1)

r     =int( 256 *rnd( 1))
g     =int( 256 *rnd( 1))
b     =int( 256 *rnd( 1))
c1\$   =str\$( r)      +" " +str\$( g)      +" " +str\$( b)
c2\$   =str\$( 255 -r) +" " +str\$( 255 -g) +" " +str\$( 255 -b)

call YinYang x, y, size, c1\$, c2\$
next i

wait
'   ________________________________________________________________

sub YinYang x, y, size, c1\$, c2\$

#w "place "; x; " "; y
#w "backcolor ";  c1\$; " ; color ";  c1\$
#w "circlefilled "; size /2

#w "color "; c2\$; " ; backcolor "; c2\$
#w "piefilled "; size; " "; size; " 90 180"

#w "rule ";  _R2_COPYPEN
#w "place "; x; " "; y -size /4
#w "backcolor ";  c1\$; " ; color ";  c1\$; " ; circlefilled "; size  /4

#w "place "; x; " "; y -size /4
#w "backcolor ";  c2\$; " ; color ";  c2\$; " ; circlefilled "; size /12

#w "place "; x; " "; y +size /4
#w "backcolor ";  c2\$; " ; color ";  c2\$; " ; circlefilled "; size  /4

#w "place "; x; " "; y +size /4
#w "backcolor ";  c1\$; " ; color ";  c1\$; " ; circlefilled "; size /12

#w "place "; x; " "; y
#w "color black ; circle "; size /2

#w "flush"

end sub

scan

wait

[quit]
close #w
end