How to resolve the algorithm Yin and yang step by step in the Forth programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Yin and yang step by step in the Forth programming language

Table of Contents

Problem Statement

One well-known symbol of the philosophy of duality known as yin and yang is the taijitu.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Yin and yang step by step in the Forth programming language

Source code in the forth programming language

: circle ( x y r h -- f )
rot - dup *
rot   dup * +
swap  dup * swap
< invert
;

: pixel ( r x y -- r c )
2dup 4 pick 6 / 5 pick 2 / negate circle if 2drop '#' exit then
2dup 4 pick 6 / 5 pick 2 /        circle if 2drop '.' exit then
2dup 4 pick 2 / 5 pick 2 / negate circle if 2drop '.' exit then
2dup 4 pick 2 / 5 pick 2 /        circle if 2drop '#' exit then
2dup 4 pick     0 circle if
   drop 0< if '.' exit else '#' exit then
   then
2drop bl
;

: yinyang ( r -- )
dup dup 1+ swap -1 * do
   cr
   dup dup 2 * 1+ swap -2 * do
      I 2 / J  pixel emit
   loop
loop drop
;


[PRAGMA] usestackflood                 \ don't use additional memory for fill
include lib/graphics.4th               \ load the graphics library
include lib/gcircle.4th                \ we need a full circle
include lib/garccirc.4th               \ we need a partial circle
include lib/gflood.4th                 \ we need a flood fill

600 pic_width ! 600 pic_height !       \ set canvas size
color_image 255 whiteout black         \ paint black on white

300 300 296 circle                     \ make the large circle
152 300  49 circle                     \ make the top small circle
448 300  49 circle                     \ make the bottom small circle

152 300 149 -15708 31416 arccircle     \ create top teardrop
448 300 148  15708 31416 arccircle     \ create bottom teardrop

150 300 flood                          \ fill the top small circle
500 300 flood                          \ fill the bottom teardrop

300 300 295 circle                     \ let's make it a double line width

s" gyinyang.ppm" save_image            \ save the image


  

You may also check:How to resolve the algorithm Loops/Downward for step by step in the Amazing Hopper programming language
You may also check:How to resolve the algorithm Averages/Pythagorean means step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Averages/Simple moving average step by step in the Ring programming language
You may also check:How to resolve the algorithm Sudoku step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Filter step by step in the Lua programming language