How to resolve the algorithm Yin and yang step by step in the UNIX Shell programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Yin and yang step by step in the UNIX Shell 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 UNIX Shell programming language
Source code in the unix programming language
#!/usr/bin/env bash
in_circle() { #(cx, cy, r, x y)
# return true if the point (x,y) lies within the circle of radius r centered
# on (cx,cy)
# (but really scaled to an ellipse with vertical minor semiaxis r and
# horizontal major semiaxis 2r)
local -i cx=$1 cy=$2 r=$3 x=$4 y=$5
local -i dx dy
(( dx=(x-cx)/2, dy=y-cy, dx*dx + dy*dy <= r*r ))
}
taijitu() { #radius
local -i radius=${1:-17}
local -i x1=0 y1=0 r1=radius # outer circle
local -i x2=0 y2=-radius/2 r2=radius/6 # upper eye
local -i x3=0 y3=-radius/2 r3=radius/2 # upper half
local -i x4=0 y4=+radius/2 r4=radius/6 # lower eye
local -i x5=0 y5=+radius/2 r5=radius/2 # lower half
local -i x y
for (( y=radius; y>=-radius; --y )); do
for (( x=-2*radius; x<=2*radius; ++x)); do
if ! in_circle $x1 $y1 $r1 $x $y; then
printf ' '
elif in_circle $x2 $y2 $r2 $x $y; then
printf '#'
elif in_circle $x3 $y3 $r3 $x $y; then
printf '.'
elif in_circle $x4 $y4 $r4 $x $y; then
printf '.'
elif in_circle $x5 $y5 $r5 $x $y; then
printf '#'
elif (( x <= 0 )); then
printf '.'
else
printf '#'
fi
done
printf '\n'
done
}
You may also check:How to resolve the algorithm Test a function step by step in the ACL2 programming language
You may also check:How to resolve the algorithm Steffensen's method step by step in the ATS programming language
You may also check:How to resolve the algorithm Phrase reversals step by step in the Scala programming language
You may also check:How to resolve the algorithm Read entire file step by step in the Objeck programming language
You may also check:How to resolve the algorithm Binary strings step by step in the zkl programming language