Yin and yang: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(16 intermediate revisions by 3 users not shown)
Line 1,995:
### </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}}==
Line 2,059 ⟶ 2,089:
 
=={{header|Dart}}==
===Text===
<syntaxhighlight lang="dart">
/* Imports and Exports */
Line 2,146 ⟶ 2,177:
###
</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}}==
Line 3,181 ⟶ 3,269:
 
</html></syntaxhighlight>
===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 5,014 ⟶ 5,147:
 
=={{header|Rust}}==
Creates an [[Media:YinYang rust.svg|svg file]] [[File:YinYang rust.svg|60px]]
'''[dependencies]'''<br>
svg = "0.1012.0"
<syntaxhighlight lang="rust">use svg::node::element::Path;
 
Line 5,219 ⟶ 5,352:
readln(KEYBOARD);
end func;</syntaxhighlight>
 
=={{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}}==
Line 5,425 ⟶ 5,611:
===Text===
{{trans|AWK}}
<syntaxhighlight lang="ecmascriptwren">var inCircle = Fn.new { |centerX, centerY, radius, x, y|
return (x-centerX)*(x-centerX)+(y-centerY)*(y-centerY) <= radius*radius
}
Line 5,524 ⟶ 5,710:
{{libheader|DOME}}
With a few minor changes, we can use the same code to draw these symbols in DOME.
<syntaxhighlight lang="ecmascriptwren">import "dome" for Window
import "graphics" for Canvas, Color
 
9,476

edits