How to resolve the algorithm Yin and yang step by step in the Modula-2 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Yin and yang step by step in the Modula-2 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 Modula-2 programming language
Source code in the modula-2 programming language
MODULE Taijitu;
FROM InOut IMPORT Write, WriteLn;
PROCEDURE YinYang(r: INTEGER);
VAR x, y: INTEGER;
PROCEDURE circle(x, y, c, r: INTEGER): BOOLEAN;
BEGIN
RETURN r*r >= (x DIV 2) * (x DIV 2) + (y-c) * (y-c);
END circle;
PROCEDURE pixel(x, y, r: INTEGER): CHAR;
BEGIN
IF circle(x, y, -r DIV 2, r DIV 6) THEN RETURN '#';
ELSIF circle(x, y, r DIV 2, r DIV 6) THEN RETURN '.';
ELSIF circle(x, y, -r DIV 2, r DIV 2) THEN RETURN '.';
ELSIF circle(x, y, r DIV 2, r DIV 2) THEN RETURN '#';
ELSIF circle(x, y, 0, r) THEN
IF x<0 THEN RETURN '.';
ELSE RETURN '#';
END;
ELSE RETURN ' ';
END;
END pixel;
BEGIN
FOR y := -r TO r DO
FOR x := -2*r TO 2*r DO
Write(pixel(x,y,r));
END;
WriteLn();
END;
END YinYang;
BEGIN
YinYang(4);
WriteLn();
YinYang(8);
END Taijitu.
You may also check:How to resolve the algorithm Runge-Kutta method step by step in the OCaml programming language
You may also check:How to resolve the algorithm Copy a string step by step in the Phix programming language
You may also check:How to resolve the algorithm Variable size/Get step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Runtime evaluation/In an environment step by step in the zkl programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the Zoea Visual programming language