Yin and yang: Difference between revisions
Content deleted Content added
Added uBasic/4tH version |
|||
(44 intermediate revisions by 14 users not shown) | |||
Line 13:
{{trans|Python}}
<
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))</
{{out}}
Line 87:
</pre>
The code:
<
MOVE.W #1,D0
;base sprite number, needed by NEOGEO hardware
Line 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</
And here is the output: [https://ibb.co/fDxTXhY Screenshot of NEOGEO displaying two Yin-Yangs]
Line 222:
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<
INCLUDE "D2:CIRCLE.ACT" ;from the Action! Tool Kit
Line 283:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Yin_and_yang.png Screenshot from Atari 8-bit computer]
Line 291:
Uses the Cairo component of GtkAda to create and save as png
[[file:YinYangAda.png|right]]
<
with Cairo; use Cairo;
with Cairo.Png; use Cairo.Png;
Line 322:
Status := Write_To_Png (Surface, "YinYangAda.png");
pragma Assert (Status = Cairo_Status_Success);
end YinYang;</
=={{header|ALGOL 68}}==
Line 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.}}
<
CHAR black="#", white=".", clear=" ";
Line 365:
print yin yang(17);
print yin yang(8)
)</
{{out}}
<pre>
Line 423:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program yingyang.s */
Line 620:
.include "../affichage.inc"
</syntaxhighlight>
{{Output}}
<pre>
Line 649:
=={{header|Asymptote}}==
[[File:Yinyang-asymptote.svg|thumb|The resulting EPS, converted to SVG]]
<
fill(scale(6)*unitsquare, invisible);
Line 666:
add(yinyang((1 + 1/4, 4 + 3/4), 1));
add(yinyang((3 + 3/4, 2 + 1/4), 2));</
=={{header|AutoHotkey}}==
[[file:yin-yang-ahk.png|right]]
Requires the GDI+ Standard Library by tic: http://www.autohotkey.com/forum/viewtopic.php?t=32238
<
Yin_and_Yang(300, 300,A_ScriptDir "\YinYang2.png")
Line 707:
gdip_Shutdown(pToken)
return r
}</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f YIN_AND_YANG.AWK
# converted from PHL
Line 763:
return in_circle(0,0-radius/2,radius/6,x,y)
}
</syntaxhighlight>
{{out}}
<pre>
Line 821:
==={{header|AmigaBASIC}}===
[[File:Amigabasic yin yang.png|thumb|Output]]
A solution using standard subroutines in AmigaBASIC which are called with <code>GOSUB</code> and use global variables, like in most Basic dialects.
<syntaxhighlight lang="qbasic">pi=3.141592
s=.5
Line 843 ⟶ 844:
PSET (xp,yp)
PAINT (xp+size/4,yp)
RETURN</
But AmigaBASIC also supports subroutines with local variables. They are defined with <code>SUB…STATIC</code> and called with <code>CALL</code>.
This solution is not much shorter however, because we have to assign the values for the arguments to <code>CALL</code> to variables first! Also, <code>s</code> and <code>pi</code> have to be defined directly in the subroutine in this case.
<syntaxhighlight lang="qbasic">xp=320:yp=100:size=150
CALL DrawYY(xp,yp,size)
xp=500:yp=40:size=50
CALL DrawYY(xp,yp,size)
END
SUB DrawYY(xp,yp,size) STATIC:
pi=3.141592
s=.5
CIRCLE (xp,yp),size,,,,s
CIRCLE (xp,yp+size/4),size/8,,,,s
CIRCLE (xp,yp-size/4),size/8,,,,s
CIRCLE (xp,yp+size/4),size/2,,.5*pi,1.5*pi,s
CIRCLE (xp,yp-size/4),size/2,,1.5*pi,2*pi,s
CIRCLE (xp,yp-size/4),size/2,,0,.5*pi,s
PAINT (xp,yp-size/4)
PSET (xp,yp)
PAINT (xp+size/4,yp)
END SUB</syntaxhighlight>
==={{header|Applesoft BASIC}}===
<
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 865 ⟶ 890:
170 YC = YP + S / 2 : GOSUB 1FILLCIRCLE
180 HCOLOR = 0 : YC = YP : R = S : GOSUB 2CIRCLE
190 RETURN</
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
graphsize 800, 600
clg
Line 886 ⟶ 911:
call Taijitu(500, 300, 138)
end
</syntaxhighlight>
==={{header|BBC BASIC}}===
[[File:Yinyangbbc.gif|right]]
<
PROCyinyang(700, 400, 300)
END
Line 905 ⟶ 930:
CIRCLE FILL xpos%, ypos%+size%/2, size%/6+2
CIRCLE xpos%, ypos%, size%
ENDPROC</
==={{header|Commodore BASIC}}===
Line 913 ⟶ 938:
On a VIC-20 with the SuperExpander cartridge:
<
10 GRAPHIC 2
20 COLOR 0,1,1,1
Line 929 ⟶ 954:
160 PAINT 1,X-XR/2,Y
170 RETURN
</syntaxhighlight>
{{works with|Simons' BASIC}}
<
10 COLOUR 0,0
20 HIRES 1,0
Line 948 ⟶ 973:
160 PAINT X-XR/2,Y,1
170 RETURN
</syntaxhighlight>
{{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:
<
10 COLOR 0,1:COLOR 1,2:COLOR 4,1
20 GRAPHIC 1,1
Line 968 ⟶ 993:
160 PAINT 1,X-XR/2,Y
170 RETURN
</syntaxhighlight>
Images of the results can be seen [https://imgur.com/a/GCekCvC here].
==={{header|FreeBASIC}}===
<
Screen 19
Color ,7
Line 991 ⟶ 1,016:
Taijitu(500, 300, 138)
End
</syntaxhighlight>
==={{header|Gambas}}===
<
Dim hPictureBox As PictureBox
Dim siCount As Short
Line 1,016 ⟶ 1,041:
Next
End</
'''[http://www.cogier.com/gambas/Yin%20and%20yang_270.png Click here to view image]'''
==={{header|IS-BASIC}}===
<
110 GRAPHICS HIRES 2
120 SET PALETTE WHITE,BLACK
Line 1,033 ⟶ 1,058:
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</
==={{header|Liberty BASIC}}===
[[File:YinYangLB.gif||200px|thumb|right|Liberty BASIC Graphic Output]]
<
WindowHeight =440
Line 1,082 ⟶ 1,107:
[quit]
close #w
end</
==={{header|Locomotive Basic}}===
[[File:Cpcbasic yin yang.png|thumb|Output]]
<
20 xp=320:yp=200:size=150:gosub 100
30 xp=550:yp=350:size=40:gosub 100
Line 1,109 ⟶ 1,134:
2030 draw cx+cr*sin(i),cy+cr*cos(i)
2040 next
2050 return</
==={{header|PureBasic}}===
[[File:Yin And yang.png|300px]]
<
DrawingMode(#PB_2DDrawing_Outlined)
Circle(x, y, 2 * radius, #Black) ;outer circle
Line 1,134 ⟶ 1,159:
path$ = SaveFileRequester("Save image", "Yin And yang.png", "*.png", 0)
If path$ <> "": SaveImage(0, path$, #PB_ImagePlugin_PNG, 0, 2): EndIf
EndIf</
==={{header|uBasic/4tH}}===
<syntaxhighlight lang="text">Proc _YinYang (18)
End
Line 1,167 ⟶ 1,192:
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 (" "))</
==={{header|VBA}}===
<
ActiveSheet.Shapes.AddShape(msoShapeChord, Top, Left, Size, Size).Select
With Selection.ShapeRange
Line 1,209 ⟶ 1,234:
yinyang 200, 100, 100
yinyang 275, 175, 25
End Sub</
==={{header|Visual Basic .NET}}===
Line 1,218 ⟶ 1,243:
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).
<
Imports System.Windows.Forms
Line 1,304 ⟶ 1,329:
End Sub
End Class
End Module</
====SVG====
Line 1,311 ⟶ 1,336:
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 ;).
<
' Yep, VB.NET can import XML namespaces. All literals have xmlns changed, while xmlns:xlink is only
Line 1,351 ⟶ 1,376:
End Using
End Sub
End Module</
{{out}}
<
<!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,367 ⟶ 1,392:
<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></
====SVG (harder cheating)====
{{trans|Raku}}
<
Sub Main()
Console.OutputEncoding = Text.Encoding.Unicode
Line 1,378 ⟶ 1,403:
Console.WriteLine(<div><%= cheat_harder(700) %><%= cheat_harder(350) %></div>)
End Sub
End Module</
{{out}}
<
<span style="font-size:700%;">☯</span>
<span style="font-size:350%;">☯</span>
</div></
Rendered by RosettaCode (MediaWiki):
Line 1,391 ⟶ 1,416:
==={{header|Yabasic}}===
<
color 0,0,0
Line 1,439 ⟶ 1,464:
lx=x : rx=x : y=oy : m=-1 // m=-1 makes go upwards
next t
end sub</
Other solution:
<
backcolor 255,0,0
color 0,0,0
Line 1,461 ⟶ 1,486:
pause .025
next n
end sub</
==={{header|ZX Spectrum Basic}}===
Line 1,468 ⟶ 1,493:
This could be done with fewer fills by defining the outline with arcs instead of circles, but it'd be just as "fast".
<
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,539 ⟶ 1,564:
9070 NEXT x
9080 NEXT y
9090 RETURN</
[https://i.imgur.com/J1DK7qQl.png Resultant image at Imgur] (uses size=40 and position=40, then size=80 and position=160)
=={{header|BCPL}}==
<
let circle(x, y, c, r) = (r*r) >= (x/2) * (x/2) + (y-c) * (y-c)
Line 1,566 ⟶ 1,591:
$( yinyang(4)
yinyang(8)
$) </
{{out}}
<pre> ...
Line 1,597 ⟶ 1,622:
{{trans|PicoLisp}}
The radius is specified by the first value on the stack - set to 10 (55+) in this example.
<
@#!`g01:+1g07,+55$<v0-g010p07_
0g-20g+:*+30g:*`v ^_:2/:*:70g0
Line 1,604 ⟶ 1,629:
2+*:-g02-g00g07:_ 1v v!`*:g0
g-:*+00g:*`#v_$:0`!0\v0_:70g00
0#+g#1,#$< > 2 #^>#g>#04#1+#:</
{{out}}
Line 1,631 ⟶ 1,656:
=={{header|C}}==
Writes to stdout a SVG file with two yin-yangs (no, it's really just that big): [[File:yinyang-C.svg]]
<
void draw_yinyang(int trans, double scale)
Line 1,660 ⟶ 1,685:
printf("</svg>");
return 0;
}</
=={{header|C++}}==
{{trans|Java}}
<
bool circle(int x, int y, int c, int r) {
Line 1,705 ⟶ 1,730:
yinYang(18);
return 0;
}</
{{out}}
<pre> ...
Line 1,750 ⟶ 1,775:
(Cleaned up)
<
public partial class Form1 : Form
{
Line 1,782 ⟶ 1,807:
if (hasOutline) g.DrawEllipse(Pens.Black, pt.X, pt.Y, width, width);
}
}</
{{out}}
Line 1,794 ⟶ 1,819:
=={{header|CLU}}==
<
rep = null
Line 1,828 ⟶ 1,853:
stream$putl(po, taijitu$make(4))
stream$putl(po, taijitu$make(8))
end start_up</
{{out}}
<pre> ..
Line 1,860 ⟶ 1,885:
=={{header|D}}==
{{trans|Python}}
<
std.conv, std.typecons;
Line 1,896 ⟶ 1,921:
2.yinYang.writeln;
1.yinYang.writeln;
}</
{{out}}
<pre> .
Line 1,939 ⟶ 1,964:
A simpler alternative version:
{{trans|PicoLisp}}
<
import std.stdio, std.math;
Line 1,959 ⟶ 1,984:
void main() {
16.yinYang;
}</
{{out}}
<pre> ...
Line 1,994 ⟶ 2,019:
....###################
### </pre>
=={{header|EasyLang}}==
[https://easylang.online/show/#cod=VY/dCsIwDEbv8xTftbIapx30cWYso1jXEVHs20t13SbkIj8nJ2TSJJCgAoXAwBAASTEp5JsGleihZGgqaA5j7scBb2Ro5e/p5UunLqDFDgpmXm3OuTp++GEmHKNxvFWggS6aVfGrDjhVz8Lv//jNlZkvBkOXXm6Dpud4hbWWJPpeqf7ScoluqS2jYxzP9AE= Run it]
<syntaxhighlight lang=text>
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>
=={{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}}
{{libheader|SysUtils,StdCtrls}}
[[File:DelphiYinYang.png|frame|none]]
<syntaxhighlight lang="Delphi">
procedure DrawCircle(Canvas: TCanvas; Center: TPoint; Radius: integer);
{Draw circle at specified center and size (Radius)}
var R: TRect;
begin
R.TopLeft:=Center;
R.BottomRight:=Center;
InflateRect(R,Radius,Radius);
Canvas.Ellipse(R);
end;
procedure DrawYinYang(Canvas: TCanvas; Center: TPoint; Radius: integer);
{Draw Yin-Yang symbol at specified center and size (Radius)}
var X1,Y1,X2,Y2,X3,Y3,X4,Y4: integer;
var R2,R6: integer;
begin
R2:=Radius div 2;
R6:=Radius div 6;
{Draw outer circle}
DrawCircle(Canvas,Center,Radius);
{Draw bottom 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);
{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;
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}}
<
TColorFuncX = function (x : Integer) : Integer;
Line 2,131 ⟶ 2,467:
sq := new TSquareBoard(1);
sq.YinYang;
sq.Print;</
{{out}}
<pre>
Line 2,173 ⟶ 2,509:
#
</pre>
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Yin_and_yang}}
'''Solution'''
[[File:Fōrmulæ - Yin and yang 01.png]]
'''Test cases'''
[[File:Fōrmulæ - Yin and yang 02.png]]
[[File:Fōrmulæ - Yin and yang 03.png]]
=={{header|Forth}}==
Line 2,188 ⟶ 2,529:
{{works with|gforth|0.7.3}}
<
rot - dup *
rot dup * +
Line 2,213 ⟶ 2,554:
loop
loop drop
;</
{{out}}
Line 2,234 ⟶ 2,575:
..############
## 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,239 ⟶ 2,653:
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]]
<
import (
Line 2,290 ⟶ 2,704:
}
f.Close()
}</
=={{header|Haskell}}==
Line 2,298 ⟶ 2,712:
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>.
<
import Diagrams.Prelude
Line 2,315 ⟶ 2,729:
main = defaultMain $
pad 1.1 $
beside (2,-1) yinyang (yinyang # scale (1/4))</
=={{header|Icon}} and {{header|Unicon}}==
[[File:YinYang-unicon.PNG|thumb|Sample Output]]
<
procedure main()
Line 2,341 ⟶ 2,755:
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</
{{libheader|Icon Programming Library}}
Line 2,350 ⟶ 2,764:
Based on the Python implementation:
<
radii=. y*1 3 6
ranges=. i:each radii
Line 2,363 ⟶ 2,777:
M=. '.' ((_3 {:: cInds) <@:+"1 offset)} M
M=. '*' ((_3 {:: cInds) <@:-"1 offset)} M
)</
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,375 ⟶ 2,789:
Example use:
<syntaxhighlight lang="text"> yinyang 1
.
......*
Line 2,414 ⟶ 2,828:
..***********
.********
* </
=={{header|Java}}==
Line 2,422 ⟶ 2,836:
[[File:Java-yinyang-240.png | right]]
<
import java.awt.Color;
Line 2,502 ⟶ 2,916:
frame.setVisible(true);
}
}</
===Text===
Line 2,508 ⟶ 2,922:
{{works with|Java|1.8}}
<
import java.util.Map;
import java.util.Optional;
Line 2,590 ⟶ 3,004:
}
}
</syntaxhighlight>
Test:
Line 2,636 ⟶ 3,050:
=={{header|JavaScript}}==
Another way, a more JavaScript-style way.
<syntaxhighlight lang="javascript">
function Arc(posX,posY,radius,startAngle,endAngle,color){//Angle in radians.
this.posX=posX;
Line 2,696 ⟶ 3,110:
YingYang[0];
//In construction.
</syntaxhighlight>
===Text===
{{trans|ALGOL 68}}
<
var scale_x = 2,
scale_y = 1,
Line 2,765 ⟶ 3,179:
})()
console.log(YinYang(17))
console.log(YinYang(8))</
===SVG===
Line 2,772 ⟶ 3,186:
This is a SVG embedded in a HTML document;
it can be isolated from the HTML document too, making it a standalone SVG
<
<html>
Line 2,875 ⟶ 3,289:
</head>
</html></
===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,882 ⟶ 3,341:
The jq program presented here is adapted from the C version and produces the same image:
[[File:yinyang-C.svg]]
<syntaxhighlight lang="jq">
def svg:
"<svg width='100%' height='100%' version='1.1'
Line 2,911 ⟶ 3,370:
"</svg>" ;
draw</
To view the image, store the output in a file:
<
The image can then be viewed in a browser.
Line 2,920 ⟶ 3,379:
{{trans|Python}}
<
radii = (i * n for i in (1, 3, 6))
ranges = collect(collect(-r:r) for r in radii)
Line 2,940 ⟶ 3,399:
println(yinyang(4))
</syntaxhighlight>
=={{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.
<
import java.awt.Color
Line 3,016 ⟶ 3,475:
isVisible = true
}
}</
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{{SVG 580 580}
{YY 145 145 300}
Line 3,059 ⟶ 3,518:
http://lambdaway.free.fr/lambdawalks/data/lambdatalk_yinyang.png
</syntaxhighlight>
=={{header|Logo}}==
Line 3,066 ⟶ 3,525:
{{works with|MSW_Logo|6.5b}}
<
; 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 3,125 ⟶ 3,584:
forward 150
pendown
taijitu 75</
=={{header|Lua}}==
{{trans|C++}}
<
return (r * r) >= (x * x) / 4 + ((y - c) * (y - c))
end
Line 3,165 ⟶ 3,624:
end
yinYang(18)</
{{out}}
<pre> .
Line 3,204 ⟶ 3,663:
...####################
#</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">
with(plottools):
with(plots):
Line 3,218 ⟶ 3,750:
scaling = constrained, axes = none
);
</syntaxhighlight>
=={{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.
<
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]</
=={{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)
<
picture pic_;
path p_;
Line 3,255 ⟶ 3,787:
endfig;
end.</
=={{header|Modula-2}}==
<
FROM InOut IMPORT Write, WriteLn;
Line 3,295 ⟶ 3,827:
WriteLn();
YinYang(8);
END Taijitu.</
{{out}}
<pre> ..
Line 3,328 ⟶ 3,860:
Writes an SVG document to standard output: [[File:yinyang-NRX.svg]]
{{trans|C}}
<
options replace format comments java crossref savelog symbols binary
Line 3,358 ⟶ 3,890:
yy = String.format(" <use xlink:href='#y' transform='translate(%d,%d) scale(%g)'/>", -
[Object Integer(trans), Integer(trans), Double(scale)])
return yy</
=={{header|Nim}}==
{{trans|Ada}}
{{libheader|gintro}}
<
proc draw(ctx: Context; x, y, r: float) =
Line 3,386 ⟶ 3,918:
context.draw(35, 35, 30)
let status = surface.writeToPng("yin-yang.png")
assert status == Status.success</
=={{header|OCaml}}==
<
let draw_yinyang x y radius black white =
Line 3,421 ⟶ 3,953:
draw_yinyang w (h*2) (r*2) black white;
draw_yinyang (w*2) h r blue magenta;
ignore(read_key())</
run with:
Line 3,427 ⟶ 3,959:
=={{header|PARI/GP}}==
<
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]
))))
}</
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,441 ⟶ 3,973:
{{Trans|JavaScript}}
<
//Compiled with fpc
Program yingyang;
Line 3,507 ⟶ 4,039:
</syntaxhighlight>
{{out}}
<pre>
Line 3,555 ⟶ 4,087:
[[File:yinyang-perl.svg|thumb]]
<
my ($radius, $cx, $cy, $fill, $stroke) = @_;
print "<circle cx='$cx' cy='$cy' r='$radius' ",
Line 3,608 ⟶ 4,140:
yin_yang(100, 500, 500);
print "</svg>"</
Messy code. Note that the larger yin-yang is drawn recursively.
Line 3,614 ⟶ 4,146:
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/yinyang.htm here].
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Yin_and_yang.exw
-- =============================
--</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span>
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cd_canvas</span>
<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>
<span style="color: #000080;font-style:italic;">-- cdCanvasSector does not draw anti-aliased edges, but cdCanvasArc does, so over-draw...</span>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<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>
<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>
<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>
<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>
<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: #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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<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>
<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>
<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>
<span style="color: #008080;">else</span>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<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>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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,691 ⟶ 4,231:
{{trans|ALGOL 68}}
<
extern printf;
Line 3,756 ⟶ 4,296:
print_yin_yang(8);
return 0;
]</
{{out}}
Line 3,816 ⟶ 4,356:
=={{header|PicoLisp}}==
<
(>=
(* R R)
Line 3,839 ⟶ 4,379:
(if (lt0 X) "." "#") )
(T " ") ) ) )
(prinl) ) )</
{{out|Test}}
Line 3,884 ⟶ 4,424:
=={{header|Plain English}}==
<
Start up.
Clear the screen to the gray color.
Line 3,915 ⟶ 4,455:
Unmask everything.
Use the fat pen.
Draw the ellipse.</
{{out}}
[https://commons.wikimedia.org/wiki/File:Taijitu_symbols_drawn_with_Plain_English.png]
=={{header|PL/I}}==
<
yinyang: procedure(r);
circle: procedure(x, y, c, r) returns(bit);
Line 3,952 ⟶ 4,492:
put skip;
call yinyang(8);
end yinyang;</
{{out}}
<pre> ...
Line 3,984 ⟶ 4,524:
=={{header|PostScript}}==
{{out}} [[File:PSyinyang.png|thumb]]
<
%%BoundingBox: 0 0 400 400
Line 4,023 ⟶ 4,563:
6 circ 220 180 dis
showpage
%%EOF</
=={{header|POV-Ray}}==
[[File:Yys.png|thumb]]
<syntaxhighlight lang="pov-ray">
// ====== General Scene setup ======
#version 3.7;
Line 4,097 ⟶ 4,637:
#declare scl = scl*0.85;
#end</
=={{header|Prolog}}==
Works with SWI-Prolog and XPCE.
<
R is N * 100,
sformat(Title, 'Yin Yang ~w', [N]),
Line 4,157 ⟶ 4,697:
send(P, fill_pattern, Col).
:- pce_end_class.</
{{out}}
<pre> ?- ying_yang(1).
Line 4,172 ⟶ 4,712:
an ASCII representation of the Yin yang symbol.
{{works with|Python|3.x}}
<
def yinyang(n=3):
radii = [i * n for i in (1, 3, 6)]
Line 4,192 ⟶ 4,732:
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])</
;Sample generated symbols for <code>n = 2</code> and <code>n = 3</code>:
Line 4,240 ⟶ 4,780:
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]]
<
mode('logo')
Line 4,292 ⟶ 4,832:
goto(-150, -150)
taijitu(100)
hideturtle()</
=={{header|Quackery}}==
<
[ -1 4 turn
Line 4,324 ⟶ 4,864:
100 1 yinyang
420 1 fly
300 1 yinyang</
{{output}}
Line 4,332 ⟶ 4,872:
=={{header|R}}==
[[File:yin_yang.png|thumb|Output of this R program]]
<
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,346 ⟶ 4,886:
plot.yin.yang()
plot.yin.yang(1,7,1, add=T)
dev.off()</
=={{header|Racket}}==
[[File:Rosetta-yin-yang.png||200px|thumb|right]]
<
#lang racket
(require slideshow/pict)
Line 4,371 ⟶ 4,911:
(yin-yang 200)
</syntaxhighlight>
=={{header|Raku}}==
Line 4,379 ⟶ 4,919:
Translation / Modification of C and Perl examples.
<syntaxhighlight lang="raku"
say "<circle cx='$cx' cy='$cy' r='$rad' fill='$fill' stroke='$stroke' stroke-width='1'/>";
}
Line 4,403 ⟶ 4,943:
yin_yang(50, 300, 300);
say '</svg>';</
Seems like something of a cheat since it relies on a web browser /
Line 4,409 ⟶ 4,949:
If that's the case, we may as well cheat harder. ;-)
<syntaxhighlight lang="raku"
say '<div>', cheat_harder(700), cheat_harder(350), '</div>';</
<div><span style="font-size:700%;">☯</span><span style="font-size:350%;">☯</span></div>
Line 4,417 ⟶ 4,957:
=={{header|Rascal}}==
[[File:Yinyang.jpg||200px|thumb|right]]
<
import vis::Render;
import vis::Figure;
Line 4,435 ⟶ 4,975:
render(hcat([vcat([overlay([template, black, smallWhite, smallBlack], aspectRatio (1.0)), space(), space()]),
overlay([template, black, smallWhite, smallBlack], aspectRatio (1.0))]));
}</
=={{header|REXX}}==
{{trans|PHL}}
Code was added to this REXX program to try to preserve the aspect ratio when displaying the Yin-Yang 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,464 ⟶ 5,004:
end /*sy*/
say strip($, 'T') /*display one line of a Yin─Yang symbol*/
end /*sx*/; return</
{{out|output|text= when using the inputs of: <tt> 35 25 </tt>}}
Line 4,598 ⟶ 5,138:
[[File:yin_yang.shoes.png|thumb|Output of this Ruby Shoes program]]
{{libheader|Shoes}}
<
PI = Shoes::TWO_PI/2
Line 4,625 ⟶ 5,165:
yin_yang 190, 190, 360
yin_yang 410, 90, 90
end</
=={{header|Rust}}==
Creates an [[Media:YinYang rust.svg|svg file]] [[File:YinYang rust.svg|60px]]
'''[dependencies]'''<br>
svg = "0.
<
fn main() {
let doc = svg::Document::new()
.add(yin_yang(15.0, 1.0
.add(yin_yang(6.0,
svg::save("
}
/// th - the thickness of the outline around yang
Line 4,647 ⟶ 5,187:
+ &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")
}</
=={{header|Scala}}==
{{libheader|Scala}}
<
import scala.swing.{ MainFrame, Panel }
import java.awt.{ Color, Graphics2D }
Line 4,710 ⟶ 5,250:
super.main(args)
}
}</
=={{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,803 ⟶ 5,343:
plot2d(real(Arcs(7,:)),imag(Arcs(7,:)));
set(gca(),'axes_visible',['off','off','off']);</
=={{header|Seed7}}==
[[File:yinandyang.png|thumb|Output of the Seed7 program]]
<
include "float.s7i";
include "math.s7i";
Line 4,832 ⟶ 5,372:
yinYang(400, 250, 200);
readln(KEYBOARD);
end func;</
=={{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}}
<
say "<circle cx='#{cx}' cy='#{cy}' r='#{rad}' fill='#{fill}' stroke='#{stroke}' stroke-width='1'/>";
}
Line 4,859 ⟶ 5,452:
yin_yang(20, 120, 120);
say '</svg>';</
=={{header|SVG}}==
Line 4,866 ⟶ 5,459:
but we can translate and rescale a shape after defining it.
<
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
Line 4,899 ⟶ 5,492:
transform="translate(375, 375) scale(400, 400)"/>
</svg></
=={{header|Tcl}}==
[[File:yinyang-tcl.gif|thumb|Output of this Tcl program]]
{{libheader|Tk}}
<
package require Tk
Line 4,930 ⟶ 5,523:
pack [canvas .c -width 300 -height 300 -background gray50]
yinyang .c 110 110 90
yinyang .c 240 240 40</
=={{header|UNIX Shell}}==
{{works with|Bourne Again SHell}}
<
in_circle() { #(cx, cy, r, x y)
# return true if the point (x,y) lies within the circle of radius r centered
Line 4,973 ⟶ 5,566:
printf '\n'
done
}</
{{Output}}
Line 5,039 ⟶ 5,632:
===Text===
{{trans|AWK}}
<
return (x-centerX)*(x-centerX)+(y-centerY)*(y-centerY) <= radius*radius
}
Line 5,079 ⟶ 5,672:
yinAndYang.call(16)
yinAndYang.call(8)</
{{out}}
Line 5,138 ⟶ 5,731:
{{libheader|DOME}}
With a few minor changes, we can use the same code to draw these symbols in DOME.
<
import "graphics" for Canvas, Color
Line 5,197 ⟶ 5,790:
}
var Game = YinAndYang.new(600, 600)</
=={{header|XPL0}}==
[[File:YinXPL0.png|180px|thumb|right|Output]]
<
def Black=0, Red=4, White=$F;
Line 5,229 ⟶ 5,822:
if ChIn(1) then []; \wait for keystroke
SetVid(3); \restore normal text mode
]</
=={{header|zkl}}==
Writes to stdout a SVG file with two yin-yangs.
<
0'|<use xlink:href="#y" transform="translate(%d,%d) scale(%g)"/>|
.fmt(trans,trans,scale).print();
Line 5,257 ⟶ 5,850:
draw_yinyang(20, 0.05);
draw_yinyang( 8, 0.02);
print("</svg>");</
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}}
|