Yin and yang: Difference between revisions

282 bytes removed ,  11 months ago
m (→‎{{header|Rust}}: improved output)
Line 1,996:
 
=={{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}}
<syntaxhighlight lang="delphi">procedure DrawYinAndYang(Canv: TCanvas; R: TRect);
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);
 
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;
 
<syntaxhighlight lang="Delphi">
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;
 
 
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>
{{output?}}
 
=={{header|DWScript}}==
465

edits