Yin and yang: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|68000 Assembly}}: explained macros)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(47 intermediate revisions by 14 users not shown)
Line 13:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F yinyang(n = 3)
V radii = [1, 3, 6].map(i -> i * @n)
V ranges = radii.map(r -> Array(-r .. r))
Line 33:
 
print(yinyang(2))
print(yinyang(1))</langsyntaxhighlight>
 
{{out}}
Line 78:
=={{header|68000 Assembly}}==
{{works with|NEOGEO}}
The NEOGEO's hardware-supported sprite scaling helps a lot with this task. Each sprite has a shrink variable that is written to offset 0x8000 in video memory. A value of 0x0FFF is full-size, and the sprite gets smaller as the value decreases. (A sprite's tiles must be drawn in ROM at full size.)
This code uses the following macros:
<pre>
Line 87:
</pre>
The code:
<langsyntaxhighlight lang="68000devpac"> pushall
MOVE.W #1,D0
;base sprite number, needed by NEOGEO hardware
;the yin-yang is 8 sprites total, it is important that
;two different sprite objects do not overlap!
 
MOVE.W #$F800,D4 ;x position on screen
MOVE.W #$1000,D5 ;y position on screen
Line 111 ⟶ 112:
generateOAM:
;this is just boilerplate required to show hardware sprites to the screen, it's not really relevant to the task.
;INPUT: D0 = SPRITENUM.
; all this does is copy the sprite data to video memory.
 
;INPUT: D0 = SPRITENUM.
; D4 = Y POS
; D5 = X POS
; D7 = SHRINK FACTOR (SIZE PARAMETER)
; THESE VALUES ARE PASSED IN USING THE ABOVE REGISTERS
pushWord D0
ADD.W #$8000,D0 ;VRAM OFFSET FOR SPRITE 1
LEA YinYang_Data,A0 ;LOAD ADDRESS OF SPRITE METADATA
MOVE.B (A0)+,D2 ;SPRITE WIDTH - 8 SPRITES PER OBJECT
; (A NEOGEO SPRITE IS ALWAYS 1 TILE WIDE BUT CAN BE OF ARBITRARY HEIGHT)
MOVE.B (A0)+,D3 ;SPRITE HEIGHT
 
MOVE.B (A0)+,D3 ;SPRITE HEIGHT - 8 TILES PER SPRITE
AND.W #$00FF,D3 ;BYTE SANITIZE SPRITE HEIGHT
 
Line 127 ⟶ 134:
 
MOVE.W D0,$3C0000 ;SET SCB2DESTINATION ADDRESS OF SIZE PARAMETER
MOVE.W D7,$3C0002 ;SETWRITE SHRINKSIZE PARAMETER TO VRAM
;AUTO INCS TO $8201 WHICH IS WHERE Y POS MUST BE STORED.
Line 134 ⟶ 141:
MOVE.W D4,D1 ;GET Y POS
OR.W D3,D1 ;COMBINE WITH SPRITE HEIGHT,SINCE NEOGEO STORES THEM TOGETHER AS ONE UNIT.
MOVE.W D1,$3C0002 ;STORE IN SCB3VRAM
;AUTO INCS TO $8401 WHICH IS WHERE X POS MUST BE STORED.
MOVE.W D5,D1 ;GET X POS
MOVE.W D1,$3C0002 ;STORE IN SCB4VRAM
CMP.B #1,D2 ;IS THIS SPRITE EXACTLY ONE TILE WIDE?
CMP.B #1,D2
BEQ skipChainedOAM ;A 1-WIDE SPRITE NEEDS NO CHAINED SPRITES.
; IN THIS EXAMPLE THE YIN-YANGS ARE 8 TILES WIDE, THIS BRANCH IS NEVER TAKEN.
pushWord D2
SUBQ.B #2,D2 ;DBRAWE CORRECTIONNEED ANDTO SKIPLOOP ANCHOR(SPRITE_WIDTH-2) SPRITETIMES.
 
 
Line 152 ⟶ 160:
MOVE.W D0,$3C0000 ;SET VRAM DESTINATION.
MOVE.W D7,$3C0002 ;EACH STRIP HAS ITS OWN SHRINK VALUE.
MOVE.W #$0040,$3C0002 ;MARK THIS SPRITE AS CHAINED. CHAINED SPRITES MOVE AND SCALE AS ONE UNIT.
MOVE.W #$0000,$3C0002 ;DUMMY MOVE FOR PADDING.
DBRA D2,loop_generateChainedOAM
popWord D2
Line 188 ⟶ 196:
YinYang_Data:
DC.B 8,8 ;SPRITE WIDTH,SPRITE HEIGHT
DC.W $0FFF ;SHRINK (NOT USED HERE, WAS PASSED BY CALLING FUNCTION)
DC.W $F800 ;Y (NOT USED HERE, WAS PASSED BY CALLING FUNCTION)
DC.W $2000 ;X (NOT USED HERE, WAS PASSED BY CALLING FUNCTION)
 
YinYang_Tile: ;EACH NUMBER REPRESENTS A TILE IN THE CHARACTER ROM
;THESE VALUES ARE ARBITRARY AND WILL DIFFER DEPENDING ON HOW THE YIN-YANG PIXEL ART IS STORED IN YOUR CARTRIDGE.
DC.W $0060,$0068,$0070,$0078,$0080,$0088,$0090,$0098
DC.W $0061,$0069,$0071,$0079,$0081,$0089,$0091,$0099
Line 209 ⟶ 215:
DC.W $0100,$0100,$0100,$0100,$0100,$0100,$0100,$0100
DC.W $0100,$0100,$0100,$0100,$0100,$0100,$0100,$0100
DC.W $0100,$0100,$0100,$0100,$0100,$0100,$0100,$0100</langsyntaxhighlight>
 
And here is the output: [https://ibb.co/fDxTXhY Screenshot of NEOGEO displaying two Yin-Yangs]
 
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<syntaxhighlight lang="action!">INCLUDE "H6:REALMATH.ACT"
INCLUDE "D2:CIRCLE.ACT" ;from the Action! Tool Kit
 
PROC YinYang(INT x BYTE y BYTE r)
INT i,a,b,rr,r2,rr2,r5,rr5,y1,y2
REAL tmp1,tmp2
 
Circle(x,y,r,1)
 
rr=r*r
r2=r/2 rr2=rr/4
Color=1
FOR i=0 TO r
DO
a=rr-i*i
IntToReal(a,tmp1)
Sqrt(tmp1,tmp2)
a=RealToInt(tmp2)
 
b=rr2-(i-r2)*(i-r2)
IntToReal(b,tmp1)
Sqrt(tmp1,tmp2)
b=RealToInt(tmp2)
 
Plot(x+b,y-i) DrawTo(x+a,y-i)
Plot(x-b,y+i) DrawTo(x+a,y+i)
OD
 
r5=r/5
rr5=rr/25
y1=y-r2 y2=y+r2
FOR i=0 TO r5
DO
a=rr5-i*i
IntToReal(a,tmp1)
Sqrt(tmp1,tmp2)
a=RealToInt(tmp2)
 
Color=1
Plot(x-a,y1-i) DrawTo(x+a,y1-i)
Plot(x-a,y1+i) DrawTo(x+a,y1+i)
 
Color=0
Plot(x-a,y2-i) DrawTo(x+a,y2-i)
Plot(x-a,y2+i) DrawTo(x+a,y2+i)
OD
RETURN
 
PROC Main()
BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
 
Graphics(8+16)
MathInit()
COLOR1=$00
COLOR2=$0F
 
YinYang(180,120,60)
YinYang(100,40,30)
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Yin_and_yang.png Screenshot from Atari 8-bit computer]
 
=={{header|Ada}}==
Line 217 ⟶ 291:
Uses the Cairo component of GtkAda to create and save as png
[[file:YinYangAda.png|right]]
<langsyntaxhighlight Adalang="ada">with Glib; use Glib;
with Cairo; use Cairo;
with Cairo.Png; use Cairo.Png;
Line 248 ⟶ 322:
Status := Write_To_Png (Surface, "YinYangAda.png");
pragma Assert (Status = Cairo_Status_Success);
end YinYang;</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 254 ⟶ 328:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due use of Currying.}}
<langsyntaxhighlight lang="algol68">INT scale x=2, scale y=1;
CHAR black="#", white=".", clear=" ";
 
Line 291 ⟶ 365:
print yin yang(17);
print yin yang(8)
)</langsyntaxhighlight>
{{out}}
<pre>
Line 349 ⟶ 423:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program yingyang.s */
Line 546 ⟶ 620:
.include "../affichage.inc"
 
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 575 ⟶ 649:
=={{header|Asymptote}}==
[[File:Yinyang-asymptote.svg|thumb|The resulting EPS, converted to SVG]]
<langsyntaxhighlight lang="asymptote">unitsize(1 inch);
 
fill(scale(6)*unitsquare, invisible);
Line 592 ⟶ 666:
 
add(yinyang((1 + 1/4, 4 + 3/4), 1));
add(yinyang((3 + 3/4, 2 + 1/4), 2));</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
[[file:yin-yang-ahk.png|right]]
Requires the GDI+ Standard Library by tic: http://www.autohotkey.com/forum/viewtopic.php?t=32238
<langsyntaxhighlight AHKlang="ahk">Yin_and_Yang(50, 50, A_ScriptDir "\YinYang1.png")
Yin_and_Yang(300, 300,A_ScriptDir "\YinYang2.png")
 
Line 633 ⟶ 707:
gdip_Shutdown(pToken)
return r
}</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f YIN_AND_YANG.AWK
# converted from PHL
Line 689 ⟶ 763:
return in_circle(0,0-radius/2,radius/6,x,y)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 748 ⟶ 822:
==={{header|AmigaBASIC}}===
 
<langsyntaxhighlight lang="amigabasic">pi=3.141592
s=.5
 
Line 769 ⟶ 843:
PSET (xp,yp)
PAINT (xp+size/4,yp)
RETURN</langsyntaxhighlight>
 
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight ApplesoftBasiclang="applesoftbasic">0 GOTO 6
1Y=R:D=1-R:X=0:FORC=0TO1STEP0:M=D>=0:Y=Y-M:D=D-Y*2*M:D=D+X*2+3:HPLOTXC-X,YC+YTOXC+X,YC+Y:HPLOTXC-Y,YC+XTOXC+Y,YC+X:HPLOTXC-X,YC-YTOXC+X,YC-Y:HPLOTXC-Y,YC-XTOXC+Y,YC-X:X=X+1:C=X>=Y:NEXTC:RETURN
2Y=R:D=1-R:X=0:FORC=0TO1STEP0:M=D>=0:Y=Y-M:D=D-Y*2*M:D=D+X*2+3:HPLOTXC-X,YC+Y:HPLOTXC+X,YC+Y:HPLOTXC-Y,YC+X:HPLOTXC+Y,YC+X:HPLOTXC-X,YC-Y:HPLOTXC+X,YC-Y:HPLOTXC-Y,YC-X:HPLOTXC+Y,YC-X:X=X+1:C=X>=Y:NEXTC:RETURN
Line 791 ⟶ 865:
170 YC = YP + S / 2 : GOSUB 1FILLCIRCLE
180 HCOLOR = 0 : YC = YP : R = S : GOSUB 2CIRCLE
190 RETURN</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
<lang BASIC256>
graphsize 800, 600
clg
Line 812 ⟶ 886:
call Taijitu(500, 300, 138)
end
</syntaxhighlight>
</lang>
 
==={{header|BBC BASIC}}===
[[File:Yinyangbbc.gif|right]]
<langsyntaxhighlight lang="bbcbasic"> PROCyinyang(200, 200, 100)
PROCyinyang(700, 400, 300)
END
Line 831 ⟶ 905:
CIRCLE FILL xpos%, ypos%+size%/2, size%/6+2
CIRCLE xpos%, ypos%, size%
ENDPROC</langsyntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 839 ⟶ 913:
On a VIC-20 with the SuperExpander cartridge:
 
<langsyntaxhighlight lang="basic">0 REM VIC-20 WITH SUPEREXPANDER
10 GRAPHIC 2
20 COLOR 0,1,1,1
Line 855 ⟶ 929:
160 PAINT 1,X-XR/2,Y
170 RETURN
</syntaxhighlight>
</lang>
 
{{works with|Simons' BASIC}}
 
<langsyntaxhighlight lang="basic">0 REM C64 WITH SIMONS' BASIC
10 COLOUR 0,0
20 HIRES 1,0
Line 874 ⟶ 948:
160 PAINT X-XR/2,Y,1
170 RETURN
</syntaxhighlight>
</lang>
 
{{works with|Commodore BASIC|3.5,7.0}}
Using the built-in graphics statements available in BASIC 3.5 on the Commodore TED computers (C-16, Plus/4) or BASIC 7.0 on the C-128:
 
<langsyntaxhighlight lang="basic">0 REM BASIC 3.5,7.0
10 COLOR 0,1:COLOR 1,2:COLOR 4,1
20 GRAPHIC 1,1
Line 894 ⟶ 968:
160 PAINT 1,X-XR/2,Y
170 RETURN
</syntaxhighlight>
</lang>
 
Images of the results can be seen [https://imgur.com/a/GCekCvC here].
 
==={{header|FreeBASIC}}===
<langsyntaxhighlight lang="freebasic">
Screen 19
Color ,7
Line 917 ⟶ 991:
Taijitu(500, 300, 138)
End
</syntaxhighlight>
</lang>
 
==={{header|Gambas}}===
<langsyntaxhighlight lang="gambas">Public Sub Form_Open()
Dim hPictureBox As PictureBox
Dim siCount As Short
Line 942 ⟶ 1,016:
Next
 
End</langsyntaxhighlight>
 
'''[http://www.cogier.com/gambas/Yin%20and%20yang_270.png Click here to view image]'''
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "YinYang.bas"
110 GRAPHICS HIRES 2
120 SET PALETTE WHITE,BLACK
Line 959 ⟶ 1,033:
200 SET INK 0:PLOT X,Y+R/2,ELLIPSE R/2,R/2,
210 SET INK 1:PLOT X,Y,ELLIPSE R,R,
220 END DEF</langsyntaxhighlight>
 
==={{header|Liberty BASIC}}===
[[File:YinYangLB.gif||200px|thumb|right|Liberty BASIC Graphic Output]]
<langsyntaxhighlight lang="lb"> WindowWidth =410
WindowHeight =440
 
Line 1,008 ⟶ 1,082:
[quit]
close #w
end</langsyntaxhighlight>
 
==={{header|Locomotive Basic}}===
 
<langsyntaxhighlight lang="locobasic">10 mode 2:deg:defint a-z:ink 0,26:ink 1,0:border 26
20 xp=320:yp=200:size=150:gosub 100
30 xp=550:yp=350:size=40:gosub 100
Line 1,035 ⟶ 1,109:
2030 draw cx+cr*sin(i),cy+cr*cos(i)
2040 next
2050 return</langsyntaxhighlight>
 
==={{header|PureBasic}}===
[[File:Yin And yang.png|300px]]
<langsyntaxhighlight PureBasiclang="purebasic">Procedure Yin_And_Yang(x, y, radius)
DrawingMode(#PB_2DDrawing_Outlined)
Circle(x, y, 2 * radius, #Black) ;outer circle
Line 1,060 ⟶ 1,134:
path$ = SaveFileRequester("Save image", "Yin And yang.png", "*.png", 0)
If path$ <> "": SaveImage(0, path$, #PB_ImagePlugin_PNG, 0, 2): EndIf
EndIf</langsyntaxhighlight>
 
==={{header|uBasic/4tH}}===
<syntaxhighlight lang="text">Proc _YinYang (18)
End
 
_YinYang
Param (1)
Local (2)
 
For b@ = -a@ To a@
For c@ = -2*a@ To 2*a@
Print Chr(FUNC(_Pixel (c@, b@, a@)));
Next
Print
Next
Return
 
_Circle
Param (4)
Local (1)
 
e@ = ((a@/2) * (a@/2)) + ((b@-c@) * (b@-c@))
Return ((d@ * d@) + 1 > e@)
 
_Pixel
Param (3)
 
If FUNC(_Circle (a@, b@, -c@ / 2, c@ / 6)) Then Return (Ord ("#"))
If FUNC(_Circle (a@, b@, c@ / 2, c@ / 6)) Then Return (Ord ("."))
If FUNC(_Circle (a@, b@, -c@ / 2, c@ / 2)) Then Return (Ord ("."))
If FUNC(_Circle (a@, b@, c@ / 2, c@ / 2)) Then Return (Ord ("#"))
If FUNC(_Circle (a@, b@, 0, c@)) Then Return (Iif (a@ < 0, Ord ("."), Ord ("#")))
Return (Ord (" "))</syntaxhighlight>
==={{header|VBA}}===
<langsyntaxhighlight lang="vb">Private Sub yinyang(Top As Integer, Left As Integer, Size As Integer)
ActiveSheet.Shapes.AddShape(msoShapeChord, Top, Left, Size, Size).Select
With Selection.ShapeRange
Line 1,103 ⟶ 1,209:
yinyang 200, 100, 100
yinyang 275, 175, 25
End Sub</langsyntaxhighlight>
 
==={{header|Visual Basic .NET}}===
Line 1,112 ⟶ 1,218:
Shows a form with the symbols drawn on it if no command line arguments are given; otherwise, the first and only argument is an integer representing the width and height of the PNG image to generate. The raw data of the generated image is written to the console (redirect to a file to view).
 
<langsyntaxhighlight lang="vbnet">Imports System.Drawing
Imports System.Windows.Forms
 
Line 1,198 ⟶ 1,304:
End Sub
End Class
End Module</langsyntaxhighlight>
 
====SVG====
Line 1,205 ⟶ 1,311:
Uses minimal string literals by favoring proper use of the .NET <code>System.Linq.Xml</code> classes (and VB.NET's XML literals, of course ;).
 
<langsyntaxhighlight lang="vbnet">Imports System.IO
 
' Yep, VB.NET can import XML namespaces. All literals have xmlns changed, while xmlns:xlink is only
Line 1,245 ⟶ 1,351:
End Using
End Sub
End Module</langsyntaxhighlight>
 
{{out}}
<langsyntaxhighlight lang="xml"><?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" width="30" height="30" xmlns="http://www.w3.org/2000/svg">
Line 1,261 ⟶ 1,367:
<use xlink:href="#y" transform="translate(20,20) scale(0.05)" xmlns:xlink="http://www.w3.org/1999/xlink" />
<use xlink:href="#y" transform="translate(8,8) scale(0.02)" xmlns:xlink="http://www.w3.org/1999/xlink" />
</svg></langsyntaxhighlight>
 
====SVG (harder cheating)====
{{trans|Raku}}
 
<langsyntaxhighlight lang="vbnet">Module Program
Sub Main()
Console.OutputEncoding = Text.Encoding.Unicode
Line 1,272 ⟶ 1,378:
Console.WriteLine(<div><%= cheat_harder(700) %><%= cheat_harder(350) %></div>)
End Sub
End Module</langsyntaxhighlight>
 
{{out}}
<langsyntaxhighlight lang="html5"><div>
<span style="font-size:700%;">☯</span>
<span style="font-size:350%;">☯</span>
</div></langsyntaxhighlight>
 
Rendered by RosettaCode (MediaWiki):
Line 1,285 ⟶ 1,391:
 
==={{header|Yabasic}}===
<langsyntaxhighlight Yabasiclang="yabasic">open window 640, 480
 
color 0,0,0
Line 1,333 ⟶ 1,439:
lx=x : rx=x : y=oy : m=-1 // m=-1 makes go upwards
next t
end sub</langsyntaxhighlight>
Other solution:
<langsyntaxhighlight Yabasiclang="yabasic">open window 640, 480
backcolor 255,0,0
color 0,0,0
Line 1,355 ⟶ 1,461:
pause .025
next n
end sub</langsyntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
Line 1,362 ⟶ 1,468:
This could be done with fewer fills by defining the outline with arcs instead of circles, but it'd be just as "fast".
 
<langsyntaxhighlight lang="zxbasic">10 CLS
20 LET i=0
30 PRINT "Recommended size is a multiple of 4 between 40 and 80": REM smaller sizes don't render properly and larger ones don't fit
Line 1,433 ⟶ 1,539:
9070 NEXT x
9080 NEXT y
9090 RETURN</langsyntaxhighlight>
 
[https://i.imgur.com/J1DK7qQl.png Resultant image at Imgur] (uses size=40 and position=40, then size=80 and position=160)
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let circle(x, y, c, r) = (r*r) >= (x/2) * (x/2) + (y-c) * (y-c)
Line 1,460 ⟶ 1,566:
$( yinyang(4)
yinyang(8)
$) </langsyntaxhighlight>
{{out}}
<pre> ...
Line 1,491 ⟶ 1,597:
{{trans|PicoLisp}}
The radius is specified by the first value on the stack - set to 10 (55+) in this example.
<langsyntaxhighlight lang="befunge">55+:#. 00p:2*10p:2/20p6/30p01v
@#!`g01:+1g07,+55$<v0-g010p07_
0g-20g+:*+30g:*`v ^_:2/:*:70g0
Line 1,498 ⟶ 1,604:
2+*:-g02-g00g07:_ 1v v!`*:g0
g-:*+00g:*`#v_$:0`!0\v0_:70g00
0#+g#1,#$< > 2 #^>#g>#04#1+#:</langsyntaxhighlight>
 
{{out}}
Line 1,525 ⟶ 1,631:
=={{header|C}}==
Writes to stdout a SVG file with two yin-yangs (no, it's really just that big): [[File:yinyang-C.svg]]
<langsyntaxhighlight Clang="c">#include <stdio.h>
 
void draw_yinyang(int trans, double scale)
Line 1,554 ⟶ 1,660:
printf("</svg>");
return 0;
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{trans|Java}}
<langsyntaxhighlight lang="cpp">#include <iostream>
 
bool circle(int x, int y, int c, int r) {
Line 1,599 ⟶ 1,705:
yinYang(18);
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> ...
Line 1,644 ⟶ 1,750:
(Cleaned up)
 
<langsyntaxhighlight lang="csharp">
public partial class Form1 : Form
{
Line 1,676 ⟶ 1,782:
if (hasOutline) g.DrawEllipse(Pens.Black, pt.X, pt.Y, width, width);
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,686 ⟶ 1,792:
 
Image: [https://upload.wikimedia.org/wikipedia/commons/a/af/Yin_and_yang_problem_c_sharp.png Yin_and_yang_problem_c_sharp.png]
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">taijitu = cluster is make
rep = null
circle = proc (x,y,c,r: int) returns (bool)
return (r**2 >= (x/2)**2 + (y-c)**2)
end circle
pixel = proc (x,y,r: int) returns (char)
if circle(x,y,-r/2,r/6) then return('#')
elseif circle(x,y, r/2,r/6) then return('.')
elseif circle(x,y,-r/2,r/2) then return('.')
elseif circle(x,y, r/2,r/2) then return('#')
elseif circle(x,y, 0, r) then
if x<0 then return('.') else return('#') end
end
return(' ')
end pixel
make = proc (r: int) returns (string)
chars: array[char] := array[char]$predict(1, r*r*2+r)
for y: int in int$from_to(-r, r) do
for x: int in int$from_to(-2*r, 2*r) do
array[char]$addh(chars, pixel(x,y,r))
end
array[char]$addh(chars, '\n')
end
return (string$ac2s(chars))
end make
end taijitu
 
start_up = proc ()
po: stream := stream$primary_output()
stream$putl(po, taijitu$make(4))
stream$putl(po, taijitu$make(8))
end start_up</syntaxhighlight>
{{out}}
<pre> ..
........##
......##....##
..........####
..........#######
....##########
..####..######
..########
##
 
..
............##
..................####
............##......######
..........######......####
..............##......########
......................########
....................##########
..................###############
..........####################
........######################
........######..##############
....######......##########
......######..############
....##################
..############
##</pre>
 
=={{header|D}}==
{{trans|Python}}
<langsyntaxhighlight lang="d">import std.stdio, std.algorithm, std.array, std.math, std.range,
std.conv, std.typecons;
 
Line 1,725 ⟶ 1,896:
2.yinYang.writeln;
1.yinYang.writeln;
}</langsyntaxhighlight>
{{out}}
<pre> .
Line 1,768 ⟶ 1,939:
A simpler alternative version:
{{trans|PicoLisp}}
<langsyntaxhighlight lang="d">void yinYang(in int r) {
import std.stdio, std.math;
 
Line 1,788 ⟶ 1,959:
void main() {
16.yinYang;
}</langsyntaxhighlight>
{{out}}
<pre> ...
Line 1,823 ⟶ 1,994:
....###################
### </pre>
 
 
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=VY/dCsIwDEbv8xTftbIapx30cWYso1jXEVHs20t13SbkIj8nJ2TSJJCgAoXAwBAASTEp5JsGleihZGgqaA5j7scBb2Ro5e/p5UunLqDFDgpmXm3OuTp++GEmHKNxvFWggS6aVfGrDjhVz8Lv//jNlZkvBkOXXm6Dpud4hbWWJPpeqf7ScoluqS2jYxzP9AE= Run it]
 
<syntaxhighlight>
proc circ r c . .
color c
circle r
.
proc yinyang x y r . .
move x y
circ 2 * r 000
color 999
circseg 2 * r 90 -90
move x y - r
circ r 000
circ r / 3 999
move x y + r
circ r 999
circ r / 3 000
.
background 555
clear
yinyang 20 20 6
yinyang 50 60 14
</syntaxhighlight>
 
{{out}}
<pre>
</pre>
 
=={{header|Evaldraw}}==
 
===(x,y,r,g,b) 2D graphing mode===
 
{{trans|xpl0}}
 
Inspired by the xpl0 solution. First out is the implicit 2D function mode.
<syntaxhighlight lang="c">
(x,y,&r,&g,&b) {
r=255; g=0; b=0;
// Notice rad is radius square
YinYang(x-8,y+8,7,r,g,b);
YinYang(x-25,y+24,15,r,g,b);
}//main
 
YinYang(x,y,rad,&r,&g,&b) {
circ0 = Circle(x, y, rad);
circ1 = Circle(x, y-rad/2, rad/2);
circ2 = Circle(x, y-rad/2, rad/6);
circ3 = Circle(x, y+rad/2, rad/2);
circ4 = Circle(x, y+rad/2, rad/6);
if (circ0 <= rad) { if (x<0) { r=g=b=255; } else {r=g=b=0; } }
if (circ1 <= rad/6) { r=g=b=255; }
if (circ2 <= rad/6) { r=g=b=0; }
if (circ3 <= rad/2) { r=g=b=0; }
if (circ4 <= rad/6) { r=g=b=255; }
}
 
Circle(x,y,r) { return (x^2+y^2)-r^2 }</syntaxhighlight>
 
===General program mode===
{{trans|xpl0}}
Another solution is to use the general () program mode.
[[File:Evaldraw yin and yang.gif|thumb|alt=Compilation message visible. Shows assembly code size at time spent.|2 half circles and 4 filled circles can be used to draw the yin and the yang ]]
<syntaxhighlight lang="c">()
{
cls(0x646464);
YinYang(80, 80, 70);
YinYang(240, 240, 150);
}
 
circle(x0, y0, r, col_left, col_right) {
for(y=-r; y<r; y++)
for(x=-r; x<r; x++) {
if (x^2 + y^2 <= r^2) {
if (x<0) setcol(col_left); else setcol(col_right);
setpix(x+x0, y+y0);
}
}
}
 
YinYang(x0, y0, r) {
white = rgb(255,255,255);
black = 0;
circle(x0, y0, r, white, black);
circle(x0, y0-r/2, r/2, white, white);
circle(x0, y0-r/2, r/6, black, black);
circle(x0, y0+r/2, r/2, black, black);
circle(x0, y0+r/2, r/6, white, white);
}
</syntaxhighlight>
 
=={{header|Dart}}==
===Text===
<syntaxhighlight lang="dart">
/* Imports and Exports */
import 'dart:io';
 
/* Main Block */
int main() {
yinYang(18);
return 0;
}
 
/* Function Definitions */
bool circle(int x, int y, int c, int r) {
return (r * r) >= ((x = x ~/ 2) * x) + ((y = y - c) * y);
}
 
String pixel(int x, int y, int r) {
if (circle(x, y, -r ~/ 2, r ~/ 6)) {
return '#';
}
if (circle(x, y, r ~/ 2, r ~/ 6)) {
return '.';
}
if (circle(x, y, -r ~/ 2, r ~/ 2)) {
return '.';
}
if (circle(x, y, r ~/ 2, r ~/ 2)) {
return '#';
}
if (circle(x, y, 0, r)) {
if (x < 0) {
return '.';
} else {
return '#';
}
}
return ' ';
}
 
void yinYang(int r) {
for (int y = -r; y <= r; y++) {
for (int x = -2 * r; x <= 2 * r; x++) {
stdout.write(pixel(x, y, r));
}
stdout.write('\n');
}
}
</syntaxhighlight>
 
{{out}}
<pre> ...
.....................##
.............................######
.................................######
.......................................########
...........................................########
..........................###................##########
........................###########............############
........................###########............############
........................###############............############
............................###########............################
............................###########............################
................................###................################
.....................................................##################
...................................................####################
.................................................######################
...............................................########################
.............................................##########################
......................................###################################
..........................#############################################
........................###############################################
......................#################################################
....................###################################################
..................#####################################################
................################...################################
................############...........############################
................############...........############################
............############...............########################
............############...........########################
............############...........########################
..........################...##########################
........###########################################
........#######################################
......#################################
......#############################
..#####################
###
</pre>
===Flutter===
[[File:YinYang-flutter.png]]<br>
[https://dartpad.dev/?id=c54bafac1d8f46c07db626dca64e13e4 Watch/play online DartPad]
<syntaxhighlight lang="dart">import 'dart:math' show pi;
import 'package:flutter/material.dart';
 
Path yinYang(double r, double x, double y, [double th = 1.0]) {
cR(double dY, double radius) => Rect.fromCircle(center: Offset(x, y + dY), radius: radius);
return Path()
..fillType = PathFillType.evenOdd
..addOval(cR(0, r + th))
..addOval(cR(r / 2, r / 6))
..addOval(cR(-r / 2, r / 6))
..addArc(cR(0, r), -pi / 2, -pi)
..addArc(cR(r / 2, r / 2), pi / 2, pi)
..addArc(cR(-r / 2, r / 2), pi / 2, -pi);
}
 
void main() => runApp(CustomPaint(painter: YinYangPainter()));
 
class YinYangPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final fill = Paint()..style = PaintingStyle.fill;
canvas
..drawColor(Colors.white, BlendMode.src)
..drawPath(yinYang(50.0, 60, 60), fill)
..drawPath(yinYang(20.0, 140, 30), fill);
}
 
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
</syntaxhighlight>
===Flutter (without CustomPaint)===
[https://dartpad.dev/?id=e0502d089330620c9866ef5fc2310042 Run online in DartPad]
<syntaxhighlight lang="dart">import 'package:flutter/material.dart';
 
const color = [Colors.black, Colors.white];
 
Widget cR(int iColor, double r, {Widget? child}) => DecoratedBox(
decoration: BoxDecoration(color: color[iColor], shape: BoxShape.circle),
child: SizedBox.square(dimension: r * 2, child: Center(child: child)));
 
Widget yinYang(double r, [double th = 1.0]) => Padding(
padding: const EdgeInsets.all(5),
child: ClipOval(
child: cR(0, r + th,
child: cR(1, r,
child: Stack(alignment: Alignment.center, children: [
Container(color: color[0], margin: EdgeInsets.only(left: r)),
Column(children: List.generate(2, (i) => cR(1 - i, r / 2, child: cR(i, r / 6))))
])))));
 
void main() => runApp(MaterialApp(
home: ColoredBox(color: color[1], child: Wrap(children: [yinYang(50), yinYang(20)]))));
</syntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
Instructions: Create an empty project. Paste code below and adjust the interface section for the form. Then assign 'FormCreate' to TForm1.OnCreate and 'FormPaint' to TForm1.OnPaint.
{{libheader|SysUtils,StdCtrls}}
<lang delphi>procedure DrawYinAndYang(Canv: TCanvas; R: TRect);
[[File:DelphiYinYang.png|frame|none]]
begin
Canv.Brush.Color := clWhite;
Canv.Pen.Color := clWhite;
Canv.Pie(R.Left, R.Top, R.Right, R.Bottom,
(R.Right + R.Left) div 2, R.Top, (R.Right + R.Left) div 2, R.Bottom);
Canv.Brush.Color := clBlack;
Canv.Pen.Color := clBlack;
Canv.Pie(R.Left, R.Top, R.Right, R.Bottom,
(R.Right + R.Left) div 2, R.Bottom, (R.Right + R.Left) div 2, R.Top);
Canv.Brush.Color := clWhite;
Canv.Pen.Color := clWhite;
Canv.Ellipse((R.Right + 3 * R.Left) div 4, R.Top,
(3 * R.Right + R.Left) div 4, (R.Top + R.Bottom) div 2);
Canv.Brush.Color := clBlack;
Canv.Pen.Color := clBlack;
Canv.Ellipse((R.Right + 3 * R.Left) div 4, (R.Top + R.Bottom) div 2,
(3 * R.Right + R.Left) div 4, R.Bottom);
 
<syntaxhighlight lang="Delphi">
Canv.Brush.Color := clWhite;
Canv.Pen.Color := clWhite;
Canv.Ellipse((7 * R.Right + 9 * R.Left) div 16, (11 * R.Bottom + 5 * R.Top) div 16,
(9 * R.Right + 7 * R.Left) div 16, (13 * R.Bottom + 3 * R.Top) div 16);
Canv.Brush.Color := clBlack;
Canv.Pen.Color := clBlack;
Canv.Ellipse((7 * R.Right + 9 * R.Left) div 16, (3 * R.Bottom + 13 * R.Top) div 16,
(9 * R.Right + 7 * R.Left) div 16, (5 * R.Bottom + 11 * R.Top) div 16);
end;
 
 
procedure TForm1.FormCreate(Sender: TObject);
procedure DrawCircle(Canvas: TCanvas; Center: TPoint; Radius: integer);
{Draw circle at specified center and size (Radius)}
var R: TRect;
begin
R.TopLeft:=Center;
ClientWidth := 400;
R.BottomRight:=Center;
ClientHeight := 400;
InflateRect(R,Radius,Radius);
Canvas.Ellipse(R);
end;
 
procedure DrawYinYang(Canvas: TCanvas; Center: TPoint; Radius: integer);
procedure TForm1.FormPaint(Sender: TObject);
{Draw Yin-Yang symbol at specified center and size (Radius)}
var
var X1,Y1,X2,Y2,X3,Y3,X4,Y4: integer;
R: TRect;
var R2,R6: integer;
begin
R2:=Radius div 2;
R := ClientRect;
R6:=Radius div 6;
Canvas.Brush.Color := clGray;
Canvas.FillRect(R)Pen.Width:=3;
 
{Draw outer circle}
InflateRect(R, -50, -50);
DrawCircle(Canvas,Center,Radius);
OffsetRect(R, -40, -40);
DrawYinAndYang(Canvas, R);
 
{Draw bottom half circle}
InflateRect(R, -90, -90);
X1:=Center.X - R2; Y1:=Center.Y;
OffsetRect(R, 170, 170);
X2:=Center.X + R2; Y2:=Center.Y + Radius;
DrawYinAndYang(Canvas, R);
X3:=Center.X; Y3:=Center.Y;
X4:=Center.X; Y4:=Center.Y + Radius;
Canvas.Arc(X1,Y1, X2,Y2, X3,Y3, X4, Y4);
 
{Draw top half circle}
X1:=Center.X - R2; Y1:=Center.Y;
X2:=Center.X + R2; Y2:=Center.Y - Radius;
X3:=Center.X; Y3:=Center.Y;
X4:=Center.X; Y4:=Center.Y- Radius;
Canvas.Arc(X1,Y1, X2,Y2, X3,Y3, X4, Y4);
 
{Fill right half with black}
Canvas.Brush.Color:=clBlack;
Canvas.FloodFill(Center.X,Center.Y+5,clWhite, fsSurface);
 
{Draw top small circle}
DrawCircle(Canvas, Point(Center.X, Center.Y-R2), R6);
 
{Draw bottom small circle}
Canvas.Brush.Color:=clWhite;
DrawCircle(Canvas, Point(Center.X, Center.Y+R2), R6);
end;
</lang>
 
 
{{output?}}
procedure ShowYinYang(Image: TImage);
begin
DrawYinYang(Image.Canvas,Point(75,75),50);
DrawYinYang(Image.Canvas,Point(200,200),100);
Image.Invalidate;
end;
 
 
 
</syntaxhighlight>
{{out}}
<pre>
 
Elapsed Time: 0.595 ms.
 
</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc circle(int x, c, y, r) bool:
r*r >= (x/2)*(x/2) + (y-c)*(y-c)
corp
 
proc pixel(int x, y, r) char:
if circle(x, y, -r/2, r/6) then '\#'
elif circle(x, y, r/2, r/6) then '.'
elif circle(x, y, -r/2, r/2) then '.'
elif circle(x, y, r/2, r/2) then '\#'
elif circle(x, y, 0, r) then
if x<0 then '.' else '\#' fi
else ' '
fi
corp
 
proc yinyang(int r) void:
int x, y;
for y from -r upto r do
for x from -2*r upto 2*r do
write(pixel(x, y, r))
od;
writeln()
od
corp
 
proc main() void:
yinyang(4);
yinyang(8)
corp</syntaxhighlight>
{{out}}
<pre> ...
.........##
......###....##
...........####
..........#######
....###########
..####...######
..#########
###
...
.............##
...................####
............###......######
..........#######......####
..............###......########
.......................########
.....................##########
..................###############
..........#####################
........#######################
........######...##############
....######.......##########
......######...############
....###################
..#############
###</pre>
 
=={{header|DWScript}}==
 
{{Trans|D}}
<langsyntaxhighlight lang="delphi">type
TColorFuncX = function (x : Integer) : Integer;
 
Line 1,960 ⟶ 2,446:
sq := new TSquareBoard(1);
sq.YinYang;
sq.Print;</langsyntaxhighlight>
{{out}}
<pre>
Line 2,002 ⟶ 2,488:
#
</pre>
 
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Yin_and_yang}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
 
[[File:Fōrmulæ - Yin and yang 01.png]]
 
'''Test cases'''
 
[[File:Fōrmulæ - Yin and yang 02.png]]
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Yin and yang 03.png]]
In '''[https://formulae.org/?example=Yin_and_yang this]''' page you can see the program(s) related to this task and their results.
 
=={{header|Forth}}==
Line 2,017 ⟶ 2,508:
{{works with|gforth|0.7.3}}
 
<langsyntaxhighlight lang="forth">: circle ( x y r h -- f )
rot - dup *
rot dup * +
Line 2,042 ⟶ 2,533:
loop
loop drop
;</langsyntaxhighlight>
 
{{out}}
Line 2,063 ⟶ 2,554:
..############
## ok</pre>
{{works with|4tH v3.64}}
4tH has a graphics library, which makes it quite easy to generate this picture using graphics commands only.
<syntaxhighlight lang="text">[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</syntaxhighlight>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
 
_window = 1
begin enum output 1
_imageView1
_imageView2
end enum
 
local fn YinYangImage( size as float ) as ImageRef
CFDictionaryRef attributes = @{NSFontAttributeName:fn FontWithName( @"Menlo", size ), NSBackgroundColorAttributeName:fn ColorClear}
CFMutableAttributedStringRef aString = fn MutableAttributedStringWithAttributes( @"\u262F", attributes )
ImageRef image = fn ImageWithSize( fn AttributedStringSize( aString ) )
ImageLockFocus( image )
GraphicsContextSaveGraphicsState
AttributedStringDrawAtPoint( aString, fn CGPointMake( 0, 0 ) )
GraphicsContextRestoreGraphicsState
ImageUnlockFocus( image )
end fn = image
 
void local fn BuildWindow
CGRect r = fn CGRectMake( 0, 0, 300, 200 )
window _window, @"Rosetta Code Yin and Yang", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
WindowSetBackgroundColor( _window, fn ColorWhite )
ImageRef yinyang = fn YinYangImage( 250.0 )
r = fn CGRectMake( 20, 10, 170, 180 )
imageview _imageView1, YES, yinyang, r, NSImageScaleNone, NSImageAlignCenter, NSImageFrameNone, _window
r = fn CGRectMake( 190, 90, 100, 100 )
imageview _imageView2, YES, yinyang, r, NSImageScaleProportionallyDown, NSImageAlignCenter, NSImageFrameNone, _window
end fn
 
void local fn DoDialog( ev as long, tag as long, wnd as long )
select ( ev )
case _windowWillClose : end
end select
end fn
 
on dialog fn DoDialog
 
fn BuildWindow
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:FutureBasic Yin and Yang.png]]
 
 
Line 2,068 ⟶ 2,632:
There are some emerging third-party 2D graphics libraries for Go; meanwhile, here is an SVG solution using only standard libraries.
[[file:GoYinYang.svg|right]]
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,119 ⟶ 2,683:
}
f.Close()
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
Line 2,127 ⟶ 2,691:
Depending on the command-line arguments, the program can generate SVG, PNG, PDF or PostScript output.
The sample output was created with the command <tt>yinyang -o YinYang-Haskell.svg</tt>.
<langsyntaxhighlight lang="haskell">{-# LANGUAGE NoMonomorphismRestriction #-}
 
import Diagrams.Prelude
Line 2,144 ⟶ 2,708:
main = defaultMain $
pad 1.1 $
beside (2,-1) yinyang (yinyang # scale (1/4))</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
[[File:YinYang-unicon.PNG|thumb|Sample Output]]
<langsyntaxhighlight Iconlang="icon">link graphics
 
procedure main()
Line 2,170 ⟶ 2,734:
WAttrib(W,"fg="||lhs) & FillCircle(W,C,C-R/2,R/8) # dots
WAttrib(W,"fg="||rhs) & FillCircle(W,C,C+R/2,R/8)
end</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 2,179 ⟶ 2,743:
Based on the Python implementation:
 
<langsyntaxhighlight lang="j">yinyang=:3 :0
radii=. y*1 3 6
ranges=. i:each radii
Line 2,192 ⟶ 2,756:
M=. '.' ((_3 {:: cInds) <@:+"1 offset)} M
M=. '*' ((_3 {:: cInds) <@:-"1 offset)} M
)</langsyntaxhighlight>
 
Note: although the structure of this program is based on the python implementation, some [[Yin_and_yang/J|details]] are different. In particular, in the python implementation, the elements of squares and circles have no x,y structure -- they are flat list of coordinates.
Line 2,204 ⟶ 2,768:
Example use:
 
<syntaxhighlight lang="text"> yinyang 1
.
......*
Line 2,243 ⟶ 2,807:
..***********
.********
* </langsyntaxhighlight>
 
=={{header|Java}}==
Line 2,251 ⟶ 2,815:
[[File:Java-yinyang-240.png | right]]
 
<langsyntaxhighlight lang="java">package org.rosettacode.yinandyang;
 
import java.awt.Color;
Line 2,331 ⟶ 2,895:
frame.setVisible(true);
}
}</langsyntaxhighlight>
 
===Text===
Line 2,337 ⟶ 2,901:
{{works with|Java|1.8}}
 
<langsyntaxhighlight lang="java">import java.util.Collection;
import java.util.Map;
import java.util.Optional;
Line 2,419 ⟶ 2,983:
}
}
</syntaxhighlight>
</lang>
 
Test:
Line 2,465 ⟶ 3,029:
=={{header|JavaScript}}==
Another way, a more JavaScript-style way.
<syntaxhighlight lang="javascript">
<lang JavaScript>
function Arc(posX,posY,radius,startAngle,endAngle,color){//Angle in radians.
this.posX=posX;
Line 2,525 ⟶ 3,089:
YingYang[0];
//In construction.
</syntaxhighlight>
</lang>
 
===Text===
{{trans|ALGOL 68}}
<langsyntaxhighlight JavaScriptlang="javascript">YinYang = (function () {
var scale_x = 2,
scale_y = 1,
Line 2,594 ⟶ 3,158:
})()
console.log(YinYang(17))
console.log(YinYang(8))</langsyntaxhighlight>
 
===SVG===
Line 2,601 ⟶ 3,165:
This is a SVG embedded in a HTML document;
it can be isolated from the HTML document too, making it a standalone SVG
<langsyntaxhighlight JavaScriptlang="javascript"><!DOCTYPE html>
<html>
 
Line 2,704 ⟶ 3,268:
</head>
 
</html></langsyntaxhighlight>
===SVG (path evenodd)===
Run this script from the browser console (F12) or from the <script> tag in the body of the html document.
<syntaxhighlight lang="javascript">function svgEl(tagName, attrs) {
const el = document.createElementNS('http://www.w3.org/2000/svg', tagName);
for (const key in attrs) el.setAttribute(key, attrs[key]);
return el;
}
 
function yinYang(r, x, y, th = 1) {
const cR = (dY, rad) => `M${x},${y + dY + rad} a${rad},${rad},0,1,1,.1,0z `;
const arc = (dY, rad, cw = 1) => `A${rad},${rad},0,0,${cw},${x},${y + dY} `;
const d = cR(0, r + th) + cR(r / 2, r / 6) + cR(-r / 2, r / 6)
+ `M${x},${y} ` + arc(r, r / 2, 0) + arc(-r, r) + arc(0, r / 2);
return svgEl('path', {d, 'fill-rule': 'evenodd'});
}
 
const dialog = document.body.appendChild(document.createElement('dialog'));
const svg = dialog.appendChild(svgEl('svg', {width: 170, height: 120}));
 
svg.appendChild(yinYang(50.0, 60, 60));
svg.appendChild(yinYang(20.0, 140, 30));
dialog.showModal();
</syntaxhighlight>
===Canvas===
{{trans|Flutter}}
Run this script from the browser console (F12) or from the <script> tag of an html document.
<syntaxhighlight lang="javascript">function yinYang(r, x, y, th = 1) {
const PI = Math.PI;
const path = new Path2D();
const cR = (dY, radius) => { path.arc(x, y + dY, radius, 0, PI * 2); path.closePath() };
cR(0, r + th);
cR(r / 2, r / 6);
cR(-r / 2, r / 6);
path.arc(x, y, r, PI / 2, -PI / 2);
path.arc(x, y - r / 2, r / 2, -PI / 2, PI / 2);
path.arc(x, y + r / 2, r / 2, -PI / 2, PI / 2, true);
return path;
}
 
document.documentElement.innerHTML = '<canvas width="170" height="120"/>';
const canvasCtx = document.querySelector('canvas').getContext('2d');
 
canvasCtx.fill(yinYang(50.0, 60, 60), 'evenodd');
canvasCtx.fill(yinYang(20.0, 140, 30), 'evenodd');
</syntaxhighlight>
 
=={{header|jq}}==
Line 2,711 ⟶ 3,320:
The jq program presented here is adapted from the C version and produces the same image:
[[File:yinyang-C.svg]]
<syntaxhighlight lang="jq">
<lang jq>
def svg:
"<svg width='100%' height='100%' version='1.1'
Line 2,740 ⟶ 3,349:
"</svg>" ;
 
draw</langsyntaxhighlight>
To view the image, store the output in a file:
<langsyntaxhighlight lang="sh">$ jq -M -r -n -f yin_and_yang.jq > yin_and_yang.svg</langsyntaxhighlight>
The image can then be viewed in a browser.
 
Line 2,749 ⟶ 3,358:
{{trans|Python}}
 
<langsyntaxhighlight lang="julia">function yinyang(n::Int=3)
radii = (i * n for i in (1, 3, 6))
ranges = collect(collect(-r:r) for r in radii)
Line 2,769 ⟶ 3,378:
 
println(yinyang(4))
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
This is based on the Java entry but I've adjusted the code so that the program displays big and small yin-yangs of a predetermined size in the same frame. Consequently, the program only needs to be run once and doesn't require a command line argument.
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.awt.Color
Line 2,845 ⟶ 3,454:
isVisible = true
}
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
 
<syntaxhighlight lang="scheme">
<lang Scheme>
{{SVG 580 580}
{YY 145 145 300}
Line 2,888 ⟶ 3,497:
http://lambdaway.free.fr/lambdawalks/data/lambdatalk_yinyang.png
 
</syntaxhighlight>
</lang>
 
=={{header|Logo}}==
Line 2,895 ⟶ 3,504:
{{works with|MSW_Logo|6.5b}}
 
<langsyntaxhighlight lang="logo">to taijitu :r
; Draw a classic Taoist taijitu of the given radius centered on the current
; turtle position. The "eyes" are placed along the turtle's heading, the
Line 2,954 ⟶ 3,563:
forward 150
pendown
taijitu 75</langsyntaxhighlight>
 
=={{header|Lua}}==
{{trans|C++}}
<langsyntaxhighlight lang="lua">function circle(x, y, c, r)
return (r * r) >= (x * x) / 4 + ((y - c) * (y - c))
end
Line 2,994 ⟶ 3,603:
end
 
yinYang(18)</langsyntaxhighlight>
{{out}}
<pre> .
Line 3,033 ⟶ 3,642:
...####################
#</pre>
=={{header|M2000 Interpreter}}==
Using Drawing {} to make a emf file, which can play with various sizes and rotation.
[[File:Yin and yan.png|thumb|ScreenShotYinYang]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<syntaxhighlight lang="m2000 interpreter">
Module YinYang {
cls 5,0
Gradient 0, 5
Double
Print Over
Cursor 0,0
Report 2, "阴阳 Yin and yang 음양"
Normal
Drawing {
circle fill 0, 3000,1, 0
circle fill 15, 3000,1,0, pi/2, -pi/2
step 0, -1500
circle fill 15, 1500,1,15
width 4 {
circle fill 0, 500,1,0
}
step 0, 3000
circle fill 0, 1500,1,0
width 4 {
circle fill 15, 500,1,15
step 0, -1500
circle 3000,1,0
}
} as A
Move 6000, 5000-1500
Image A, 6000
Move 2000, 5000
Image A, 3000
Move 2000+1500, 5000+1500
hold // hold surface to release by statement release
Mouse.Icon Hide
i=0
every 10 {
if inkey$=" " or mouse=2 then exit
release
move mouse.x, mouse.y
Image A, 3000, ,i : i+=5:if i>355 then i=0
Refresh 20
if mouse=1 then hold
}
Mouse.Icon Show
filename$="yin and yang.emf"
// save to file
Open filename$ for output as #f
Put #f, A, 1
Close #f
// open mspaing
win "mspaint", quote$(dir$+filename$)
}
YinYang
</syntaxhighlight>
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">
<lang Maple>
with(plottools):
with(plots):
Line 3,047 ⟶ 3,729:
scaling = constrained, axes = none
);
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
[[File:Mathca.png|thumb|200px]]
Mathematica's ability to symbolically build up graphics is often underrated. The following function will create a yin-yang symbol with the parameter size indicating the diameter in multiples of 40 pixels.
<langsyntaxhighlight Mathematicalang="mathematica">YinYang[size_] :=
Graphics[{{Circle[{0, 0}, 2]}, {Disk[{0, 0},
2, {90 Degree, -90 Degree}]}, {White, Disk[{0, 1}, 1]}, {Black,
Disk[{0, -1}, 1]}, {Black, Disk[{0, 1}, 1/4]}, {White,
Disk[{0, -1}, 1/4]}}, ImageSize -> 40 size]</langsyntaxhighlight>
 
=={{header|Metapost}}==
[[File:Mp-Yingyang.jpg||200px|thumb|right|Metapost output (once converted to jpg)]]
The "function" yinyang returns a picture (a primitive type) that can be drawn (and transformed of course in any way)
<langsyntaxhighlight lang="metapost">vardef yinyang(expr u) =
picture pic_;
path p_;
Line 3,084 ⟶ 3,766:
endfig;
 
end.</langsyntaxhighlight>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">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.</syntaxhighlight>
{{out}}
<pre> ..
........##
......##....##
..........####
..........#######
....##########
..####..######
..########
##
 
..
............##
..................####
............##......######
..........######......####
..............##......########
......................########
....................##########
..................###############
..........####################
........######################
........######..##############
....######......##########
......######..############
....##################
..############
## </pre>
 
=={{header|NetRexx}}==
Writes an SVG document to standard output: [[File:yinyang-NRX.svg]]
{{trans|C}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
 
options replace format comments java crossref savelog symbols binary
Line 3,119 ⟶ 3,869:
yy = String.format(" <use xlink:href='#y' transform='translate(%d,%d) scale(%g)'/>", -
[Object Integer(trans), Integer(trans), Double(scale)])
return yy</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|Ada}}
{{libheader|gintro}}
<langsyntaxhighlight Nimlang="nim">import gintro/cairo
 
proc draw(ctx: Context; x, y, r: float) =
Line 3,147 ⟶ 3,897:
context.draw(35, 35, 30)
let status = surface.writeToPng("yin-yang.png")
assert status == Status.success</langsyntaxhighlight>
 
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml">open Graphics
 
let draw_yinyang x y radius black white =
Line 3,182 ⟶ 3,932:
draw_yinyang w (h*2) (r*2) black white;
draw_yinyang (w*2) h r blue magenta;
ignore(read_key())</langsyntaxhighlight>
 
run with:
Line 3,188 ⟶ 3,938:
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="pari">YinYang(r)={ for(y=-r,r, print(concat(apply( x->
if( x^2+y^2>r^2, " ",
[y<0,y>0,x>0][logint((x^2+(abs(y)-r/2)^2)<<8\r^2+1,2)\3+1], "#", "."
), [-r..r]
))))
}</langsyntaxhighlight>
 
If outside the big circle, we leave blank, else we distinguish three cases depending on D = (x/r)^2+(|y/r|-1/2)^2 or rather log_2(D)+8: Less than 3 (D < 1/32: small circles), black iff y < 0; between 3 and 6 (1/32 < D < 1/4: rings around circles), black iff y > 0; beyond 6 (D > 1/4: left or right half outside rings), black iff x > 0. In all other cases white.
Line 3,202 ⟶ 3,952:
 
{{Trans|JavaScript}}
<langsyntaxhighlight Pascallang="pascal">//Written for TU Berlin
//Compiled with fpc
Program yingyang;
Line 3,268 ⟶ 4,018:
 
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,316 ⟶ 4,066:
[[File:yinyang-perl.svg|thumb]]
 
<langsyntaxhighlight lang="perl">sub circle {
my ($radius, $cx, $cy, $fill, $stroke) = @_;
print "<circle cx='$cx' cy='$cy' r='$radius' ",
Line 3,369 ⟶ 4,119:
yin_yang(100, 500, 500);
 
print "</svg>"</langsyntaxhighlight>
 
Messy code. Note that the larger yin-yang is drawn recursively.
Line 3,375 ⟶ 4,125:
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
<lang Phix>-- demo\rosetta\Yin_and_yang.exw
You can run this online [http://phix.x10.mx/p2js/yinyang.htm here].
include pGUI.e
<!--<syntaxhighlight lang="phix">(phixonline)-->
 
<span style="color: #000080;font-style:italic;">--
Ihandle dlg, canvas
-- demo\rosetta\Yin_and_yang.exw
cdCanvas cd_canvas
-- =============================
 
--</span>
procedure cdCanvasSecArc(cdCanvas hCdCanvas, atom xc, atom yc, atom w, atom h, atom angle1, atom angle2)
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
-- cdCanvasSector does not draw anti-aliased edges, but cdCanvasArc does, so over-draw...
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
cdCanvasSector(hCdCanvas, xc, yc, w, h, angle1, angle2)
cdCanvasArc (hCdCanvas, xc, yc, w, h, angle1, angle2)
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span>
end procedure
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cd_canvas</span>
 
procedure yinyang(atom cx, cy, r)
<span style="color: #008080;">procedure</span> <span style="color: #000000;">cdCanvasSecArc</span><span style="color: #0000FF;">(</span><span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">hCdCanvas</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">xc</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">yc</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">w</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">h</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">angle1</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">angle2</span><span style="color: #0000FF;">)</span>
cdCanvasArc(cd_canvas, cx, cy, r, r, 0, 360)
<span style="color: #000080;font-style:italic;">-- cdCanvasSector does not draw anti-aliased edges, but cdCanvasArc does, so over-draw...</span>
cdCanvasSecArc(cd_canvas, cx, cy, r, r, 270, 90)
<span style="color: #7060A8;">cdCanvasSector</span><span style="color: #0000FF;">(</span><span style="color: #000000;">hCdCanvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xc</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">yc</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">w</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle2</span><span style="color: #0000FF;">)</span>
cdCanvasSecArc(cd_canvas, cx, cy-r/4, r/2-1, r/2-1, 0, 360)
<span style="color: #7060A8;">cdCanvasArc</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">hCdCanvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">xc</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">yc</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">w</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">h</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle2</span><span style="color: #0000FF;">)</span>
cdCanvasSetForeground(cd_canvas, CD_WHITE)
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
cdCanvasSecArc(cd_canvas, cx, cy+r/4, r/2-1, r/2-1, 0, 360)
cdCanvasSecArc(cd_canvas, cx, cy-r/4, r/8, r/8, 0, 360)
<span style="color: #008080;">procedure</span> <span style="color: #000000;">yinyang</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">)</span>
cdCanvasSetForeground(cd_canvas, CD_BLACK)
<span style="color: #7060A8;">cdCanvasArc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
cdCanvasSecArc(cd_canvas, cx, cy+r/4, r/8, r/8, 0, 360)
<span style="color: #000000;">cdCanvasSecArc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">270</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">90</span><span style="color: #0000FF;">)</span>
end procedure
<span style="color: #000000;">cdCanvasSecArc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">-</span><span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
 
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_WHITE</span><span style="color: #0000FF;">)</span>
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
<span style="color: #000000;">cdCanvasSecArc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
<span style="color: #000000;">cdCanvasSecArc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">-</span><span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
integer r = min(width,height)-40
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_BLACK</span><span style="color: #0000FF;">)</span>
integer cx = floor(width/2)
<span style="color: #000000;">cdCanvasSecArc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
integer cy = floor(height/2)
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
cdCanvasActivate(cd_canvas)
cdCanvasClear(cd_canvas)
<span style="color: #008080;">function</span> <span style="color: #000000;">redraw_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">)</span>
yinyang(cx-r*.43,cy+r*.43,r/6)
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">width</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">height</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">),</span>
yinyang(cx,cy,r)
<span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">min</span><span style="color: #0000FF;">(</span><span style="color: #000000;">width</span><span style="color: #0000FF;">,</span><span style="color: #000000;">height</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">40</span><span style="color: #0000FF;">,</span>
cdCanvasFlush(cd_canvas)
<span style="color: #000000;">cx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">width</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">),</span>
return IUP_DEFAULT
<span style="color: #000000;">cy</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">height</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #7060A8;">cdCanvasActivate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">)</span>
 
<span style="color: #7060A8;">cdCanvasClear</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">)</span>
function map_cb(Ihandle ih)
<span style="color: #000000;">yinyang</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">-</span><span style="color: #000000;">r</span><span style="color: #0000FF;">*.</span><span style="color: #000000;">43</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">r</span><span style="color: #0000FF;">*.</span><span style="color: #000000;">43</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">6</span><span style="color: #0000FF;">)</span>
atom res = IupGetDouble(NULL, "SCREENDPI")/25.4
<span style="color: #000000;">yinyang</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r</span><span style="color: #0000FF;">)</span>
IupGLMakeCurrent(canvas)
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">)</span>
cd_canvas = cdCreateCanvas(CD_GL, "10x10 %g", {res})
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
cdCanvasSetBackground(cd_canvas, CD_WHITE)
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
cdCanvasSetForeground(cd_canvas, CD_BLACK)
return IUP_DEFAULT
<span style="color: #008080;">function</span> <span style="color: #000000;">map_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #7060A8;">IupGLMakeCurrent</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
 
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
function canvas_resize_cb(Ihandle /*canvas*/)
<span style="color: #000000;">cd_canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_IUP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
integer {canvas_width, canvas_height} = IupGetIntInt(canvas, "DRAWSIZE")
<span style="color: #008080;">else</span>
atom res = IupGetDouble(NULL, "SCREENDPI")/25.4
<span style="color: #004080;">atom</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetDouble</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"SCREENDPI"</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">25.4</span>
cdCanvasSetAttribute(cd_canvas, "SIZE", "%dx%d %g", {canvas_width, canvas_height, res})
<span style="color: #000000;">cd_canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_GL</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"10x10 %g"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
return IUP_DEFAULT
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end function
<span style="color: #7060A8;">cdCanvasSetBackground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_WHITE</span><span style="color: #0000FF;">)</span>
 
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_BLACK</span><span style="color: #0000FF;">)</span>
procedure main()
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
IupOpen()
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
 
canvas = IupGLCanvas()
<span style="color: #008080;">function</span> <span style="color: #000000;">canvas_resize_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*canvas*/</span><span style="color: #0000FF;">)</span>
IupSetAttribute(canvas, "RASTERSIZE", "340x340") -- initial size
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">canvas_width</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas_height</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">)</span>
IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
<span style="color: #004080;">atom</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetDouble</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"SCREENDPI"</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">25.4</span>
IupSetCallback(canvas, "RESIZE_CB", Icallback("canvas_resize_cb"))
<span style="color: #7060A8;">cdCanvasSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"SIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"%dx%d %g"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">canvas_width</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas_height</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
 
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
dlg = IupDialog(canvas)
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
IupSetAttribute(dlg, "TITLE", "Yin and Yang")
IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
 
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
IupMap(dlg)
<span style="color: #000000;">canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGLCanvas</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"RASTERSIZE=340x340"</span><span style="color: #0000FF;">)</span>
IupSetAttribute(canvas, "RASTERSIZE", NULL) -- release the minimum limitation
<span style="color: #7060A8;">IupSetCallbacks</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"MAP_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"map_cb"</span><span style="color: #0000FF;">),</span>
IupShowXY(dlg,IUP_CENTER,IUP_CENTER)
<span style="color: #008000;">"RESIZE_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"canvas_resize_cb"</span><span style="color: #0000FF;">),</span>
IupMainLoop()
<span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"redraw_cb"</span><span style="color: #0000FF;">)})</span>
IupClose()
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`TITLE="Yin and Yang"`</span><span style="color: #0000FF;">)</span>
end procedure
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
 
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"RASTERSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- release the minimum limitation</span>
main()</lang>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
 
=={{header|PHL}}==
Line 3,452 ⟶ 4,210:
{{trans|ALGOL 68}}
 
<langsyntaxhighlight lang="phl">module circles;
 
extern printf;
Line 3,517 ⟶ 4,275:
print_yin_yang(8);
return 0;
]</langsyntaxhighlight>
 
{{out}}
Line 3,577 ⟶ 4,335:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de circle (X Y C R)
(>=
(* R R)
Line 3,600 ⟶ 4,358:
(if (lt0 X) "." "#") )
(T " ") ) ) )
(prinl) ) )</langsyntaxhighlight>
 
{{out|Test}}
Line 3,645 ⟶ 4,403:
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Clear the screen to the gray color.
Line 3,676 ⟶ 4,434:
Unmask everything.
Use the fat pen.
Draw the ellipse.</langsyntaxhighlight>
{{out}}
[https://commons.wikimedia.org/wiki/File:Taijitu_symbols_drawn_with_Plain_English.png]
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">yinyang: procedure options(main);
yinyang: procedure(r);
circle: procedure(x, y, c, r) returns(bit);
Line 3,713 ⟶ 4,471:
put skip;
call yinyang(8);
end yinyang;</langsyntaxhighlight>
{{out}}
<pre> ...
Line 3,745 ⟶ 4,503:
=={{header|PostScript}}==
{{out}} [[File:PSyinyang.png|thumb]]
<langsyntaxhighlight PostScriptlang="postscript">%!PS-Adobe-3.0
%%BoundingBox: 0 0 400 400
 
Line 3,784 ⟶ 4,542:
6 circ 220 180 dis
showpage
%%EOF</langsyntaxhighlight>
 
=={{header|POV-Ray}}==
[[File:Yys.png|thumb]]
 
<syntaxhighlight lang="pov-ray">
<lang POV-Ray>
// ====== General Scene setup ======
#version 3.7;
Line 3,858 ⟶ 4,616:
 
#declare scl = scl*0.85;
#end</langsyntaxhighlight>
 
=={{header|Prolog}}==
Works with SWI-Prolog and XPCE.
 
<langsyntaxhighlight Prologlang="prolog">ying_yang(N) :-
R is N * 100,
sformat(Title, 'Yin Yang ~w', [N]),
Line 3,918 ⟶ 4,676:
send(P, fill_pattern, Col).
 
:- pce_end_class.</langsyntaxhighlight>
{{out}}
<pre> ?- ying_yang(1).
Line 3,933 ⟶ 4,691:
an ASCII representation of the Yin yang symbol.
{{works with|Python|3.x}}
<langsyntaxhighlight lang="python">import math
def yinyang(n=3):
radii = [i * n for i in (1, 3, 6)]
Line 3,953 ⟶ 4,711:
m[(x,y+3*n)] = '·'
m[(x,y-3*n)] = '*'
return '\n'.join(''.join(m[(x,y)] for x in reversed(ranges[-1])) for y in ranges[-1])</langsyntaxhighlight>
 
;Sample generated symbols for <code>n = 2</code> and <code>n = 3</code>:
Line 4,001 ⟶ 4,759:
This was inspired by the Logo example but diverged as some of the Python turtle graphics primitives such as filling and the drawing of arcs work differently.
[[File:Yinyang.GIF||200px|thumb|right|Python turtle graphics program output]]
<langsyntaxhighlight lang="python">from turtle import *
 
mode('logo')
Line 4,053 ⟶ 4,811:
goto(-150, -150)
taijitu(100)
hideturtle()</langsyntaxhighlight>
 
=={{header|Quackery}}==
<langsyntaxhighlight Quackerylang="quackery">[ $ "turtleduck.qky" loadfile ] now!
 
[ -1 4 turn
Line 4,085 ⟶ 4,843:
100 1 yinyang
420 1 fly
300 1 yinyang</langsyntaxhighlight>
 
{{output}}
Line 4,093 ⟶ 4,851:
=={{header|R}}==
[[File:yin_yang.png|thumb|Output of this R program]]
<langsyntaxhighlight lang="r">plot.yin.yang <- function(x=5, y=5, r=3, s=10, add=F){
suppressMessages(require("plotrix"))
if(!add) plot(1:10, type="n", xlim=c(0,s), ylim=c(0,s), xlab="", ylab="", xaxt="n", yaxt="n", bty="n", asp=1)
Line 4,107 ⟶ 4,865:
plot.yin.yang()
plot.yin.yang(1,7,1, add=T)
dev.off()</langsyntaxhighlight>
 
=={{header|Racket}}==
[[File:Rosetta-yin-yang.png||200px|thumb|right]]
<langsyntaxhighlight lang="racket">
#lang racket
(require slideshow/pict)
Line 4,132 ⟶ 4,890:
 
(yin-yang 200)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 4,140 ⟶ 4,898:
Translation / Modification of C and Perl examples.
 
<syntaxhighlight lang="raku" perl6line>sub circle ($rad, $cx, $cy, $fill = 'white', $stroke = 'black' ){
say "<circle cx='$cx' cy='$cy' r='$rad' fill='$fill' stroke='$stroke' stroke-width='1'/>";
}
Line 4,164 ⟶ 4,922:
yin_yang(50, 300, 300);
 
say '</svg>';</langsyntaxhighlight>
 
Seems like something of a cheat since it relies on a web browser /
Line 4,170 ⟶ 4,928:
If that's the case, we may as well cheat harder. ;-)
 
<syntaxhighlight lang="raku" perl6line>sub cheat_harder ($scale) { "<span style=\"font-size:$scale%;\">&#x262f;</span>"; }
 
say '<div>', cheat_harder(700), cheat_harder(350), '</div>';</langsyntaxhighlight>
 
<div><span style="font-size:700%;">&#x262f;</span><span style="font-size:350%;">&#x262f;</span></div>
Line 4,178 ⟶ 4,936:
=={{header|Rascal}}==
[[File:Yinyang.jpg||200px|thumb|right]]
<langsyntaxhighlight Rascallang="rascal">import util::Math;
import vis::Render;
import vis::Figure;
Line 4,196 ⟶ 4,954:
render(hcat([vcat([overlay([template, black, smallWhite, smallBlack], aspectRatio (1.0)), space(), space()]),
overlay([template, black, smallWhite, smallBlack], aspectRatio (1.0))]));
}</langsyntaxhighlight>
 
=={{header|REXX}}==
{{trans|PHL}}
Code was added to this REXX program to try to preserve the aspect ratio when displaying the Yin-Yang symbol.
<langsyntaxhighlight lang="rexx">/*REXX program creates & displays an ASCII art version of the Yin─Yang (taijitu) symbol.*/
parse arg s1 s2 . /*obtain optional arguments from the CL*/
if s1=='' | s1=="," then s1= 17 /*Not defined? Then use the default. */
Line 4,225 ⟶ 4,983:
end /*sy*/
say strip($, 'T') /*display one line of a Yin─Yang symbol*/
end /*sx*/; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the inputs of: &nbsp; &nbsp; <tt> 35 &nbsp; 25 </tt>}}
 
Line 4,359 ⟶ 5,117:
[[File:yin_yang.shoes.png|thumb|Output of this Ruby Shoes program]]
{{libheader|Shoes}}
<langsyntaxhighlight lang="ruby">Shoes.app(:width => 470, :height => 380) do
PI = Shoes::TWO_PI/2
 
Line 4,386 ⟶ 5,144:
yin_yang 190, 190, 360
yin_yang 410, 90, 90
end</langsyntaxhighlight>
 
=={{header|Rust}}==
Creates an [[Media:YinYang rust.svg|svg file]] [[File:YinYang rust.svg|60px]]
'''[dependencies]'''<br>
svg = "0.12.0"
<syntaxhighlight lang="rust">use svg::node::element::Path;
 
fn main() {
let doc = svg::Document::new()
.add(yin_yang(15.0, 1.0))
.add(yin_yang(6.0, 0.7).set("transform", "translate(30)"));
svg::save("YinYang_rust.svg", &doc.set("viewBox", (-20, -20, 60, 40))).unwrap();
}
/// th - the thickness of the outline around yang
fn yin_yang(r: f32, th: f32) -> Path {
let (cr, cw, ccw) = (",0,1,1,.1,0z", ",0,0,1,0,", ",0,0,0,0,");
let d = format!("M0,{0} a{0},{0}{cr} M0,{1} ", r + th, -r / 3.0) // main_circle
+ &format!("a{0},{0}{cr} m0,{r} a{0},{0}{cr} M0,0 ", r / 6.0) // eyes
+ &format!("A{0},{0}{ccw}{r} A{r},{r}{cw}-{r} A{0},{0}{cw}0", r / 2.0); // yang
Path::new().set("d", d).set("fill-rule", "evenodd")
}</syntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
<langsyntaxhighlight lang="scala">import scala.swing.Swing.pair2Dimension
import scala.swing.{ MainFrame, Panel }
import java.awt.{ Color, Graphics2D }
Line 4,449 ⟶ 5,229:
super.main(args)
}
}</langsyntaxhighlight>
 
=={{header|Scilab}}==
This script uses complex numbers, as in <math>x + i\,y</math>, to represent <math>(x,y)</math> coordinates. [[wp:Euler's formula|Euler's formula]] is used to calculate points over in a circumference. The output is a single graphic window with two images of Yin and yang.
 
<syntaxhighlight lang="text">R = 1; //outer radius of first image
scale = 0.5; //scale of the second image
 
Line 4,542 ⟶ 5,322:
 
plot2d(real(Arcs(7,:)),imag(Arcs(7,:)));
set(gca(),'axes_visible',['off','off','off']);</langsyntaxhighlight>
 
=={{header|Seed7}}==
[[File:yinandyang.png|thumb|Output of the Seed7 program]]
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
Line 4,571 ⟶ 5,351:
yinYang(400, 250, 200);
readln(KEYBOARD);
end func;</langsyntaxhighlight>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl>program yin_yang;
print(taijitu 4);
print(taijitu 8);
op taijitu(r);
return +/[+/[pixel(x,y,r) : x in [-2*r..2*r]] + "\n" : y in [-r..r]];
end op;
proc pixel(x,y,r);
return if circle(x,y,-r/2,r/6) then '#'
elseif circle(x,y,r/2,r/6) then '.'
elseif circle(x,y,-r/2,r/2) then '.'
elseif circle(x,y,r/2,r/2) then '#'
elseif circle(x,y,0,r) then
if x<0 then '.' else '#' end
else ' '
end;
end proc;
proc circle(x,c,y,r);
return r*r >= (x/2)**2 + (y-c)**2;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre> .
.........##
.....###...##
...........####
.........########
....###########
..###...#####
..#########
#
 
.
.............##
.................####
...........###......#####
...........#####......#####
.............###......#######
......................#########
.....................##########
.................################
..........#####################
.........######################
.......######...#############
.....######.....###########
.....######...###########
....#################
..#############
#</pre>
 
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">func circle (rad, cx, cy, fill='white', stroke='black') {
say "<circle cx='#{cx}' cy='#{cy}' r='#{rad}' fill='#{fill}' stroke='#{stroke}' stroke-width='1'/>";
}
Line 4,598 ⟶ 5,431:
yin_yang(20, 120, 120);
 
say '</svg>';</langsyntaxhighlight>
 
=={{header|SVG}}==
Line 4,605 ⟶ 5,438:
but we can translate and rescale a shape after defining it.
 
<langsyntaxhighlight lang="xml"><?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
Line 4,638 ⟶ 5,471:
transform="translate(375, 375) scale(400, 400)"/>
 
</svg></langsyntaxhighlight>
 
=={{header|Tcl}}==
[[File:yinyang-tcl.gif|thumb|Output of this Tcl program]]
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
package require Tk
 
Line 4,669 ⟶ 5,502:
pack [canvas .c -width 300 -height 300 -background gray50]
yinyang .c 110 110 90
yinyang .c 240 240 40</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
{{works with|Bourne Again SHell}}
<langsyntaxhighlight lang="sh">#!/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
Line 4,712 ⟶ 5,545:
printf '\n'
done
}</langsyntaxhighlight>
 
{{Output}}
Line 4,778 ⟶ 5,611:
===Text===
{{trans|AWK}}
<langsyntaxhighlight ecmascriptlang="wren">var inCircle = Fn.new { |centerX, centerY, radius, x, y|
return (x-centerX)*(x-centerX)+(y-centerY)*(y-centerY) <= radius*radius
}
Line 4,818 ⟶ 5,651:
 
yinAndYang.call(16)
yinAndYang.call(8)</langsyntaxhighlight>
 
{{out}}
Line 4,877 ⟶ 5,710:
{{libheader|DOME}}
With a few minor changes, we can use the same code to draw these symbols in DOME.
<langsyntaxhighlight ecmascriptlang="wren">import "dome" for Window
import "graphics" for Canvas, Color
 
Line 4,936 ⟶ 5,769:
}
 
var Game = YinAndYang.new(600, 600)</langsyntaxhighlight>
 
=={{header|XPL0}}==
[[File:YinXPL0.png|180px|thumb|right|Output]]
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
 
def Black=0, Red=4, White=$F;
Line 4,968 ⟶ 5,801:
if ChIn(1) then []; \wait for keystroke
SetVid(3); \restore normal text mode
]</langsyntaxhighlight>
 
=={{header|zkl}}==
Writes to stdout a SVG file with two yin-yangs.
<langsyntaxhighlight lang="zkl">fcn draw_yinyang(trans,scale){
0'|<use xlink:href="#y" transform="translate(%d,%d) scale(%g)"/>|
.fmt(trans,trans,scale).print();
Line 4,996 ⟶ 5,829:
draw_yinyang(20, 0.05);
draw_yinyang( 8, 0.02);
print("</svg>");</langsyntaxhighlight>
A here doc (#<<<) could be used to wrap the HTML but, depending on the editor used, the formatting may not be what you want (eg "\n" vs "\r\n").
{{out}}
9,476

edits