Koch curve: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 7: Line 7:
{{libheader|Action! Tool Kit}}
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
{{libheader|Action! Real Math}}
<lang Action!>INCLUDE "H6:REALMATH.ACT"
<syntaxhighlight lang="action!">INCLUDE "H6:REALMATH.ACT"


DEFINE MAXSIZE="20"
DEFINE MAXSIZE="20"
Line 125: Line 125:
DO UNTIL CH#$FF OD
DO UNTIL CH#$FF OD
CH=$FF
CH=$FF
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Koch_curve.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Koch_curve.png Screenshot from Atari 8-bit computer]
Line 131: Line 131:
=={{header|Ada}}==
=={{header|Ada}}==
{{libheader|APDF}}
{{libheader|APDF}}
<lang Ada>with Ada.Command_Line;
<syntaxhighlight lang="ada">with Ada.Command_Line;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
with Ada.Text_IO;
Line 191: Line 191:
Rule => Even_Odd);
Rule => Even_Odd);
Doc.Close;
Doc.Close;
end Koch_Curve;</lang>
end Koch_Curve;</syntaxhighlight>


=={{header|BASIC256}}==
=={{header|BASIC256}}==
<lang BASIC256>global RtoD, DtoR
<syntaxhighlight lang="basic256">global RtoD, DtoR
RtoD = 180 / Pi
RtoD = 180 / Pi
DtoR = Pi / 180
DtoR = Pi / 180
Line 242: Line 242:


imgsave "Koch_curve.jpg", "jpg"
imgsave "Koch_curve.jpg", "jpg"
end</lang>
end</syntaxhighlight>


=={{header|Amazing Hopper}}==
=={{header|Amazing Hopper}}==
Line 250: Line 250:
or
or
./src/kock_curve.com > kockcurve.svg
./src/kock_curve.com > kockcurve.svg
<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#!/usr/bin/hopper
#!/usr/bin/hopper


Line 338: Line 338:
{output}
{output}
back
back
</syntaxhighlight>
</lang>




Line 344: Line 344:
{{trans|Go}}
{{trans|Go}}
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
Requires [https://www.autohotkey.com/boards/viewtopic.php?t=6517 Gdip Library]
<lang AutoHotkey>gdip1()
<syntaxhighlight lang="autohotkey">gdip1()
KochX := 0, KochY := 0
KochX := 0, KochY := 0
Koch(0, 0, A_ScreenWidth, A_ScreenHeight, 4, Arr:=[])
Koch(0, 0, A_ScreenWidth, A_ScreenHeight, 4, Arr:=[])
Line 424: Line 424:
Gdip_Shutdown(pToken)
Gdip_Shutdown(pToken)
ExitApp
ExitApp
Return</lang>
Return</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
Interactive program which takes the width, height (of the Graphics window) and recursion level of the Koch curve as inputs, prints out usage on incorrect invocation. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
Interactive program which takes the width, height (of the Graphics window) and recursion level of the Koch curve as inputs, prints out usage on incorrect invocation. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
<syntaxhighlight lang="c">
<lang C>
#include<graphics.h>
#include<graphics.h>
#include<stdlib.h>
#include<stdlib.h>
Line 489: Line 489:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


=={{header|C++}}==
=={{header|C++}}==
The output of this program is an SVG file depicting a Koch snowflake.
The output of this program is an SVG file depicting a Koch snowflake.
<lang cpp>// See https://en.wikipedia.org/wiki/Koch_snowflake
<syntaxhighlight lang="cpp">// See https://en.wikipedia.org/wiki/Koch_snowflake
#include <fstream>
#include <fstream>
#include <iostream>
#include <iostream>
Line 560: Line 560:
koch_curve_svg(out, 600, 5);
koch_curve_svg(out, 600, 5);
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 567: Line 567:
=={{header|Factor}}==
=={{header|Factor}}==
The approach taken is to generate a [[Thue-Morse]] sequence. Using turtle graphics, move forward for each 0 encountered and rotate 60 degrees for each 1 encountered. Remarkably, this produces a Koch curve.
The approach taken is to generate a [[Thue-Morse]] sequence. Using turtle graphics, move forward for each 0 encountered and rotate 60 degrees for each 1 encountered. Remarkably, this produces a Koch curve.
<lang factor>USING: accessors images images.testing images.viewer kernel
<syntaxhighlight lang="factor">USING: accessors images images.testing images.viewer kernel
literals math math.constants math.functions sequences ;
literals math math.constants math.functions sequences ;
IN: rosetta-code.koch-curve
IN: rosetta-code.koch-curve
Line 607: Line 607:
] 2with each image-window ;
] 2with each image-window ;


MAIN: koch-curve</lang>
MAIN: koch-curve</syntaxhighlight>
{{out}}
{{out}}
[https://i.imgur.com/MVS8QiS.png]
[https://i.imgur.com/MVS8QiS.png]
Line 613: Line 613:
=={{header|Forth}}==
=={{header|Forth}}==
{{works with|4tH v3.64}}
{{works with|4tH v3.64}}
<lang>include lib/graphics.4th
<syntaxhighlight lang="text">include lib/graphics.4th
include lib/math.4th
include lib/math.4th
include lib/enter.4th
include lib/enter.4th
Line 648: Line 648:
450 500 115 300 r> koch
450 500 115 300 r> koch


s" gkoch.ppm" save_image \ save the image</lang>
s" gkoch.ppm" save_image \ save the image</syntaxhighlight>
=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>
<syntaxhighlight lang="freebasic">
Const Pi = 4 * Atn(1)
Const Pi = 4 * Atn(1)
Const RtoD = 180 / Pi
Const RtoD = 180 / Pi
Line 696: Line 696:
Sleep
Sleep
End
End
</syntaxhighlight>
</lang>


=={{header|Go}}==
=={{header|Go}}==
{{libheader|Go Graphics}}
{{libheader|Go Graphics}}
{{trans|Ring}}
{{trans|Ring}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 741: Line 741:
dc.Stroke()
dc.Stroke()
dc.SavePNG("koch.png")
dc.SavePNG("koch.png")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 752: Line 752:
Generates SVG for a Koch snowflake. To view, save to a text file with an .svg extension, and open in a browser.
Generates SVG for a Koch snowflake. To view, save to a text file with an .svg extension, and open in a browser.


<lang haskell>import Data.Bifunctor (bimap)
<syntaxhighlight lang="haskell">import Data.Bifunctor (bimap)
import Text.Printf (printf)
import Text.Printf (printf)


Line 853: Line 853:
)
)
)
)
xys</lang>
xys</syntaxhighlight>


=={{header|IS-BASIC}}==
=={{header|IS-BASIC}}==
<lang IS-BASIC>100 PROGRAM "Koch.bas"
<syntaxhighlight lang="is-basic">100 PROGRAM "Koch.bas"
110 OPTION ANGLE DEGREES
110 OPTION ANGLE DEGREES
120 SET 22,1:SET 23,0:SET 24,42:SET 25,26
120 SET 22,1:SET 23,0:SET 24,42:SET 25,26
Line 877: Line 877:
290 PLOT LEFT A;FORWARD D;
290 PLOT LEFT A;FORWARD D;
300 END IF
300 END IF
310 END DEF</lang>
310 END DEF</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==


<lang J>seg=: [ + [: +/\ (0,1r3*1,(^j.(,-)_2 o.1r2),1) * -~
<syntaxhighlight lang="j">seg=: [ + [: +/\ (0,1r3*1,(^j.(,-)_2 o.1r2),1) * -~
koch=: [: ,/ 2 seg/\ ]
koch=: [: ,/ 2 seg/\ ]


require'plot'
require'plot'
tri=: ^ j. 4r3 * (_2 o. 0) * i._4
tri=: ^ j. 4r3 * (_2 o. 0) * i._4
plot koch ^: 5 tri</lang>
plot koch ^: 5 tri</syntaxhighlight>


[[j:File:Koch-snowflake.png|example]]
[[j:File:Koch-snowflake.png|example]]
Line 897: Line 897:


{{Trans|Haskell}}{{Trans|Python}}
{{Trans|Haskell}}{{Trans|Python}}
<lang javascript>(() => {
<syntaxhighlight lang="javascript">(() => {
'use strict';
'use strict';


Line 1,024: Line 1,024:
// MAIN ---
// MAIN ---
return main();
return main();
})();</lang>
})();</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==
Line 1,037: Line 1,037:
depending on the location of the included file, and the command-line
depending on the location of the included file, and the command-line
options used.
options used.
<lang jq>include "turtle" {search: "."};
<syntaxhighlight lang="jq">include "turtle" {search: "."};


def rules:
def rules:
Line 1,066: Line 1,066:


koch_curve(5)
koch_curve(5)
| draw(1200)</lang>
| draw(1200)</syntaxhighlight>




=={{header|Julia}}==
=={{header|Julia}}==
Multiple snowflake plots. Copied from https://www.juliabloggers.com/koch-snowflakes-for-the-holidays/.
Multiple snowflake plots. Copied from https://www.juliabloggers.com/koch-snowflakes-for-the-holidays/.
<lang Julia>using Plots
<syntaxhighlight lang="julia">using Plots


function pointskoch(points, maxk, α = sqrt(3)/2)
function pointskoch(points, maxk, α = sqrt(3)/2)
Line 1,241: Line 1,241:
#large_koch()
#large_koch()
koch_julia()
koch_julia()
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Ring}}
{{trans|Ring}}
This incorporates code from other relevant tasks in order to provide a runnable example. The image produced is saved to disk where it can be viewed with a utility such as EOG.
This incorporates code from other relevant tasks in order to provide a runnable example. The image produced is saved to disk where it can be viewed with a utility such as EOG.
<lang scala>// Version 1.2.41
<syntaxhighlight lang="scala">// Version 1.2.41


import java.awt.Color
import java.awt.Color
Line 1,327: Line 1,327:
ImageIO.write(image, "jpg", kFile)
ImageIO.write(image, "jpg", kFile)
}
}
}</lang>
}</syntaxhighlight>


{{output}}
{{output}}
Line 1,335: Line 1,335:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<lang scheme>
<syntaxhighlight lang="scheme">
{def koch
{def koch
{lambda {:d :n}
{lambda {:d :n}
Line 1,362: Line 1,362:
The output is a "square of Koch" which can be seen in
The output is a "square of Koch" which can be seen in
http://lambdaway.free.fr/lambdawalks/?view=koch
http://lambdaway.free.fr/lambdawalks/?view=koch
</syntaxhighlight>
</lang>


=={{header|Logo}}==
=={{header|Logo}}==
Line 1,394: Line 1,394:


Make "startup [zzz]
Make "startup [zzz]
</syntaxhighlight>
</lang>


=={{header|Lua}}==
=={{header|Lua}}==
Using the Bitmap class [[Bitmap#Lua|here]], with an ASCII pixel representation, then extending with <code>line()</code> as [[Bitmap/Bresenham%27s_line_algorithm#Lua|here]], then extending further..
Using the Bitmap class [[Bitmap#Lua|here]], with an ASCII pixel representation, then extending with <code>line()</code> as [[Bitmap/Bresenham%27s_line_algorithm#Lua|here]], then extending further..
<lang lua>local cos, sin, floor, pi = math.cos, math.sin, math.floor, math.pi
<syntaxhighlight lang="lua">local cos, sin, floor, pi = math.cos, math.sin, math.floor, math.pi


function Bitmap:render()
function Bitmap:render()
Line 1,439: Line 1,439:
bitmap:render()
bitmap:render()
print()
print()
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre style="font-size:50%">...........
<pre style="font-size:50%">...........
Line 1,596: Line 1,596:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang mathematica>Graphics[{GeometricTransformation[KochCurve[5], RotationTransform[Pi, {0.5, 0}]],
<syntaxhighlight lang="mathematica">Graphics[{GeometricTransformation[KochCurve[5], RotationTransform[Pi, {0.5, 0}]],
GeometricTransformation[KochCurve[5], RotationTransform[-Pi/3, {1, 0}]],
GeometricTransformation[KochCurve[5], RotationTransform[-Pi/3, {1, 0}]],
GeometricTransformation[KochCurve[5], RotationTransform[Pi/3, {0, 0}]]}]</lang>
GeometricTransformation[KochCurve[5], RotationTransform[Pi/3, {0, 0}]]}]</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
{{works with|nim|1.4.2}}
{{works with|nim|1.4.2}}
{{libheader|nim-libgd}}
{{libheader|nim-libgd}}
<lang nim>
<syntaxhighlight lang="nim">
from math import sin, cos, PI
from math import sin, cos, PI
import libgd
import libgd
Line 1,645: Line 1,645:


main()
main()
</syntaxhighlight>
</lang>


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>use SVG;
<syntaxhighlight lang="perl">use SVG;
use List::Util qw(max min);
use List::Util qw(max min);


Line 1,684: Line 1,684:
open $fh, '>', 'koch_curve.svg';
open $fh, '>', 'koch_curve.svg';
print $fh $svg->xmlify(-namespace=>'svg');
print $fh $svg->xmlify(-namespace=>'svg');
close $fh;</lang>
close $fh;</syntaxhighlight>
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/koch_curve.svg Koch curve] (offsite image)
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/koch_curve.svg Koch curve] (offsite image)


Line 1,691: Line 1,691:
{{libheader|Phix/online}}
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/koch.htm here].
You can run this online [http://phix.x10.mx/p2js/koch.htm here].
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Koch_curve.exw
-- demo\rosetta\Koch_curve.exw
Line 1,769: Line 1,769:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|Processing}}==
=={{header|Processing}}==
<lang java>int l = 300;
<syntaxhighlight lang="java">int l = 300;


void setup() {
void setup() {
Line 1,816: Line 1,816:
kcurve(0, s);
kcurve(0, s);
popMatrix();
popMatrix();
}</lang>'''The sketch can be run online''' :<BR> [https://www.openprocessing.org/sketch/848209 here.]
}</syntaxhighlight>'''The sketch can be run online''' :<BR> [https://www.openprocessing.org/sketch/848209 here.]


==={{header|Processing Python mode}}===
==={{header|Processing Python mode}}===
<lang python>l = 300
<syntaxhighlight lang="python">l = 300


def setup():
def setup():
Line 1,861: Line 1,861:
rotate(radians(-120))
rotate(radians(-120))
kcurve(0, s)
kcurve(0, s)
popMatrix()</lang>
popMatrix()</syntaxhighlight>


=={{header|Prolog}}==
=={{header|Prolog}}==
{{works with|SWI Prolog}}
{{works with|SWI Prolog}}
Produces an SVG file showing a Koch snowflake.
Produces an SVG file showing a Koch snowflake.
<lang prolog>main:-
<syntaxhighlight lang="prolog">main:-
write_koch_snowflake('koch_snowflake.svg').
write_koch_snowflake('koch_snowflake.svg').


Line 1,910: Line 1,910:
koch_curve(Stream, X2, Y2, X3, Y3, N1),
koch_curve(Stream, X2, Y2, X3, Y3, N1),
koch_curve(Stream, X3, Y3, X4, Y4, N1),
koch_curve(Stream, X3, Y3, X4, Y4, N1),
koch_curve(Stream, X4, Y4, X1, Y1, N1).</lang>
koch_curve(Stream, X4, Y4, X1, Y1, N1).</syntaxhighlight>


{{out}}
{{out}}
Line 1,920: Line 1,920:


{{Trans|Haskell}}
{{Trans|Haskell}}
<lang python>'''Koch curve'''
<syntaxhighlight lang="python">'''Koch curve'''


from math import cos, pi, sin
from math import cos, pi, sin
Line 2,056: Line 2,056:
# MAIN ---
# MAIN ---
if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>


===String rewriting===
===String rewriting===
<lang python>import numpy as np
<syntaxhighlight lang="python">import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
from matplotlib.colors import hsv_to_rgb as hsv
from matplotlib.colors import hsv_to_rgb as hsv
Line 2,090: Line 2,090:
#curve('F', {'F': 'G-F-G', 'G': 'F+G+F'}, 60, 7)
#curve('F', {'F': 'G-F-G', 'G': 'F+G+F'}, 60, 7)
#curve('A', {'A': '+BF-AFA-FB+', 'B': '-AF+BFB+FA-'}, 90, 6)
#curve('A', {'A': '+BF-AFA-FB+', 'B': '-AF+BFB+FA-'}, 90, 6)
#curve('FX+FX+', {'X': 'X+YF', 'Y': 'FX-Y'}, 90, 12)</lang>
#curve('FX+FX+', {'X': 'X+YF', 'Y': 'FX-Y'}, 90, 12)</syntaxhighlight>


=={{header|QBasic}}==
=={{header|QBasic}}==
<lang qbasic> ' Chaos: start at any point, this program uses the middle of the screen (or universe. One of six
<syntaxhighlight lang="qbasic"> ' Chaos: start at any point, this program uses the middle of the screen (or universe. One of six
' degrees of freedom (a direction) is chosen at random (by throwing a six-sided die), and a line
' degrees of freedom (a direction) is chosen at random (by throwing a six-sided die), and a line
' is drawn from the old point to the new point in the direction indicated by the pip on the die.
' is drawn from the old point to the new point in the direction indicated by the pip on the die.
Line 2,311: Line 2,311:
Y= Y + YP(N, R)
Y= Y + YP(N, R)
LINE -(X, Y) ' depending on the "die", draw the next part of the chaos curve.
LINE -(X, Y) ' depending on the "die", draw the next part of the chaos curve.
GOTO 900 ' now, go and do another point.</lang><br><br>
GOTO 900 ' now, go and do another point.</syntaxhighlight><br><br>


=={{header|Quackery}}==
=={{header|Quackery}}==
Line 2,317: Line 2,317:
Using an L-system.
Using an L-system.


<lang Quackery> [ $ "turtleduck.qky" loadfile ] now!
<syntaxhighlight lang="quackery"> [ $ "turtleduck.qky" loadfile ] now!
[ $ "" swap witheach
[ $ "" swap witheach
Line 2,338: Line 2,338:
char L = iff
char L = iff
[ -1 6 turn ] done
[ -1 6 turn ] done
1 6 turn ]</lang>
1 6 turn ]</syntaxhighlight>


{{output}}
{{output}}
Line 2,345: Line 2,345:


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket


(require metapict)
(require metapict)
Line 2,371: Line 2,371:
(koch a c n)))
(koch a c n)))


(scale 4 (snow 2))</lang>
(scale 4 (snow 2))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Line 2,377: Line 2,377:
{{works with|Rakudo|2018.03}}
{{works with|Rakudo|2018.03}}
Koch curve, actually a full Koch snowflake.
Koch curve, actually a full Koch snowflake.
<lang perl6>use SVG;
<syntaxhighlight lang="raku" line>use SVG;


role Lindenmayer {
role Lindenmayer {
Line 2,407: Line 2,407:
:polyline[ points => @points.join(','), :fill<white> ],
:polyline[ points => @points.join(','), :fill<white> ],
],
],
);</lang>
);</syntaxhighlight>


See: [https://github.com/thundergnat/rc/blob/master/img/koch1.svg Koch snowflake]
See: [https://github.com/thundergnat/rc/blob/master/img/koch1.svg Koch snowflake]


Variation using 90° angles:
Variation using 90° angles:
<lang perl6>use SVG;
<syntaxhighlight lang="raku" line>use SVG;


role Lindenmayer {
role Lindenmayer {
Line 2,441: Line 2,441:
:polyline[ points => @points.join(','), :fill<white> ],
:polyline[ points => @points.join(','), :fill<white> ],
],
],
);</lang>
);</syntaxhighlight>
See: [https://github.com/thundergnat/rc/blob/master/img/koch2.svg Koch curve variant with 90° angles]
See: [https://github.com/thundergnat/rc/blob/master/img/koch2.svg Koch curve variant with 90° angles]


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
# Project : Koch curve
# Project : Koch curve


Line 2,513: Line 2,513:
paint.drawline(x4, y4, x2, y2)
paint.drawline(x4, y4, x2, y2)
ok
ok
</syntaxhighlight>
</lang>
Output image:
Output image:


Line 2,522: Line 2,522:
{{libheader|JRubyArt}}
{{libheader|JRubyArt}}
Using a Lindenmayer System to produce a KochSnowflake or simple Koch Fractal
Using a Lindenmayer System to produce a KochSnowflake or simple Koch Fractal
<lang ruby>
<syntaxhighlight lang="ruby">
attr_reader :koch
attr_reader :koch
def settings
def settings
Line 2,618: Line 2,618:
end
end


</syntaxhighlight>
</lang>


=={{header|Rust}}==
=={{header|Rust}}==
Output is a file in SVG format depicting a Koch snowflake.
Output is a file in SVG format depicting a Koch snowflake.
<lang rust>// [dependencies]
<syntaxhighlight lang="rust">// [dependencies]
// svg = "0.8.0"
// svg = "0.8.0"


Line 2,686: Line 2,686:
fn main() {
fn main() {
write_koch_snowflake("koch_snowflake.svg", 600, 5).unwrap();
write_koch_snowflake("koch_snowflake.svg", 600, 5).unwrap();
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,693: Line 2,693:
=={{header|Sidef}}==
=={{header|Sidef}}==
Using the LSystem class defined at [https://rosettacode.org/wiki/Hilbert_curve#Sidef Hilbert curve].
Using the LSystem class defined at [https://rosettacode.org/wiki/Hilbert_curve#Sidef Hilbert curve].
<lang ruby>var rules = Hash(
<syntaxhighlight lang="ruby">var rules = Hash(
F => 'F+F--F+F',
F => 'F+F--F+F',
)
)
Line 2,709: Line 2,709:
)
)


lsys.execute('F--F--F', 4, "koch_snowflake.png", rules)</lang>
lsys.execute('F--F--F', 4, "koch_snowflake.png", rules)</syntaxhighlight>


Output image: [https://github.com/trizen/rc/blob/master/img/koch-snowflake-sidef.png Koch snowflake]
Output image: [https://github.com/trizen/rc/blob/master/img/koch-snowflake-sidef.png Koch snowflake]
Line 2,717: Line 2,717:
A Turtle graphics library makes defining the curve easy.
A Turtle graphics library makes defining the curve easy.


<syntaxhighlight lang="vb">
<lang vb>


option explicit
option explicit
Line 2,824: Line 2,824:
set x=nothing 'show image in browser
set x=nothing 'show image in browser


</syntaxhighlight>
</lang>


=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Go}}
{{trans|Go}}
{{libheader|DOME}}
{{libheader|DOME}}
<lang ecmascript>import "graphics" for Canvas, Color, Point
<syntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color, Point
import "dome" for Window
import "dome" for Window
import "math" for M
import "math" for M
Line 2,868: Line 2,868:


static draw(dt) {}
static draw(dt) {}
}</lang>
}</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>real PosX, PosY, Angle;
<syntaxhighlight lang="xpl0">real PosX, PosY, Angle;


proc DrawSide(Depth, Dist); \Draw side as 4 segments
proc DrawSide(Depth, Dist); \Draw side as 4 segments
Line 2,897: Line 2,897:
Angle:= Angle + 120.;
Angle:= Angle + 120.;
];
];
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 2,908: Line 2,908:
Uses Image Magick and
Uses Image Magick and
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<lang zkl>var width=512, height=512, img=PPM(width,height,0xFfffFF); // white canvas
<syntaxhighlight lang="zkl">var width=512, height=512, img=PPM(width,height,0xFfffFF); // white canvas
var angle=(60.0).toRad();
var angle=(60.0).toRad();
const green=0x00FF00;
const green=0x00FF00;
Line 2,935: Line 2,935:


koch(100.0,100.0, 400.0,400.0, 4);
koch(100.0,100.0, 400.0,400.0, 4);
img.writeJPGFile("koch.zkl.jpg");</lang>
img.writeJPGFile("koch.zkl.jpg");</syntaxhighlight>
Image at [http://www.zenkinetic.com/Images/RosettaCode/koch.zkl.jpg koch curve]
Image at [http://www.zenkinetic.com/Images/RosettaCode/koch.zkl.jpg koch curve]


Line 2,941: Line 2,941:
Using a Lindenmayer system and turtle graphics to draw a Koch snowflake:
Using a Lindenmayer system and turtle graphics to draw a Koch snowflake:


<lang zkl>lsystem("F--F--F", Dictionary("F","F+F--F+F"), "+-", 4) // snowflake
<syntaxhighlight lang="zkl">lsystem("F--F--F", Dictionary("F","F+F--F+F"), "+-", 4) // snowflake
//lsystem("F", Dictionary("F","F+F--F+F"), "+-", 3) // curve
//lsystem("F", Dictionary("F","F+F--F+F"), "+-", 3) // curve
: turtle(_);
: turtle(_);
Line 2,971: Line 2,971:
}
}
img.writeJPGFile("kochSnowFlake.zkl.jpg");
img.writeJPGFile("kochSnowFlake.zkl.jpg");
}</lang>
}</syntaxhighlight>
Image at [http://www.zenkinetic.com/Images/RosettaCode/kochSnowFlake.zkl.jpg Koch snow flake]
Image at [http://www.zenkinetic.com/Images/RosettaCode/kochSnowFlake.zkl.jpg Koch snow flake]