File:Снежинка Коха2.png

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Снежинка_Коха2.png(496 × 493 pixels, file size: 23 KB, MIME type: image/png)

Captions

Captions

Koch snowflake

Summary[edit]

Description
English: Koch snowflake
English: Снежинка Коха2
Date
Source Own work
Author Владислав Молдован

pascal src code[edit]

uses GraphABC;

procedure RLine(x, y, x1, y1: real) := Line(Round(x), Round(y), Round(x1), Round(y1));

function GetAngle(x, y, x2, y2: real): real;
begin
  var angle := Abs(RadToDeg(ArcTan((y2 - y) / (x2 - x))));
  if (x2 = x) and (y2 = y) then
    Result := 0
  else
    if x2 > x then
      if y2 > y then Result := angle else Result := 360 - angle
    else
      if y2 > y then Result := 180 - angle else Result := 180 + angle;
end;

function Distance(x, y, x1, y1: real) := Sqrt(Sqr(x1 - x) + Sqr(y1 - y)); 

procedure Draw(x, y, x1, y1: real);
begin
  if Distance(x, y, x1, y1) > 1 then
  begin
    var dx := (x1 - x) / 3;
    var dy := (y1 - y) / 3;
    
    var x2 := x + dx;
    var y2 := y + dy;
    
    var angle := DegToRad(GetAngle(x, y, x1, y1) - 60);
    var r := Distance(x, y, x2, y2);
    
    var x3 := x2 + r * Cos(angle);
    var y3 := y2 + r * Sin(angle);
    
    var x4 := x + dx * 2;
    var y4 := y + dy * 2;
    
    Draw(x, y, x2, y2);
    Draw(x2, y2, x3, y3);
    Draw(x3, y3, x4, y4);
    Draw(x4, y4, x1, y1);
  end
  else
    RLine(x, y, x1, y1);
end;

begin
  SetWindowSize(500, 500);
  SetWindowIsFixedSize(true);
  ClearWindow(clBlack);
  LockDrawing();
  
  SetPenColor(clCyan);
  Draw(100, 100, 400, 100);
  Draw(400, 100, 400, 400);
  Draw(400, 400, 100, 400);
  Draw(100, 400, 100, 100);
  Redraw();
end.

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current07:02, 17 September 2017Thumbnail for version as of 07:02, 17 September 2017496 × 493 (23 KB)Владислав Молдован (talk | contribs)User created page with UploadWizard

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file:

Metadata