KTurtle/Examples/da: Difference between revisions
(Importing a new version from external source) |
No edit summary |
||
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<languages /> | <languages /> | ||
{{EduBreadCrumbs | {{EduBreadCrumbs/da|1=KTurtle}} | ||
{{Tip/da|1=Scriptformattering er resultatet af en "HTML-eksport" af '''KTurtle'''.}} | |||
Line 11: | Line 10: | ||
Logo-script: | Logo-script: | ||
{{Input|1=<span style="color: #a0a0a4;"># Koch curve</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span> <span style="color: #800000;">850</span>, <span style="color: #800000;">550</span><br /><span style="color: #000080;">go</span> <span style="color: #800000;">125</span>, <span style="color: #800000;">350</span><br /><span style="color: #000080;">turnright</span> <span style="color: #800000;">90</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #800080; font-weight: bold;">$t</span><span style="color: #5a64ff; font-weight: bold;">></span><span style="color: #800000;">0</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #800080; font-weight: bold;">$t</span><span style="color: #000000; font-weight: bold;">=</span><span style="color: #800080; font-weight: bold;">$t</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #800080; font-weight: bold;">$x</span><span style="color: #000000; font-weight: bold;">=</span><span style="color: #800080; font-weight: bold;">$x</span><span style="color: #808080; font-weight: bold;">/</span><span style="color: #800000;">3</span><br /> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span><br /> <span style="color: #000080;">turnleft</span> <span style="color: #800000;">60</span><br /> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span><br /> <span style="color: #000080;">turnright</span> <span style="color: #800000;">120</span><br /> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span><br /> <span style="color: #000080;">turnleft</span> <span style="color: #800000;">60</span><br /> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span><br /> <span style="color: #008000; font-weight: bold;">}</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000080;">forward</span> <span style="color: #800000;">3</span><span style="color: #808080; font-weight: bold;">*</span><span style="color: #800080; font-weight: bold;">$x</span> <br /> <span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br />koch <span style="color: #800000;">200</span>, <span style="color: #800000;">6</span>}} | {{Input|1=<span style="color: #a0a0a4;"># Koch curve</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span> <span style="color: #800000;">850</span>, <span style="color: #800000;">550</span><br /><span style="color: #000080;">go</span> <span style="color: #800000;">125</span>, <span style="color: #800000;">350</span><br /><span style="color: #000080;">turnright</span> <span style="color: #800000;">90</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #800080; font-weight: bold;">$t</span><span style="color: #5a64ff; font-weight: bold;">></span><span style="color: #800000;">0</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #800080; font-weight: bold;">$t</span><span style="color: #000000; font-weight: bold;">=</span><span style="color: #800080; font-weight: bold;">$t</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #800080; font-weight: bold;">$x</span><span style="color: #000000; font-weight: bold;">=</span><span style="color: #800080; font-weight: bold;">$x</span><span style="color: #808080; font-weight: bold;">/</span><span style="color: #800000;">3</span><br /> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span><br /> <span style="color: #000080;">turnleft</span> <span style="color: #800000;">60</span><br /> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span><br /> <span style="color: #000080;">turnright</span> <span style="color: #800000;">120</span><br /> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span><br /> <span style="color: #000080;">turnleft</span> <span style="color: #800000;">60</span><br /> koch <span style="color: #800080; font-weight: bold;">$x</span>, <span style="color: #800080; font-weight: bold;">$t</span><br /> <span style="color: #008000; font-weight: bold;">}</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000080;">forward</span> <span style="color: #800000;">3</span><span style="color: #808080; font-weight: bold;">*</span><span style="color: #800080; font-weight: bold;">$x</span> <br /> <span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br />koch <span style="color: #800000;">200</span>, <span style="color: #800000;">6</span>}} | ||
Resultat: | Resultat: | ||
Line 20: | Line 21: | ||
En anden berømt fraktal er [http://en.wikipedia.org/wiki/Sierpinski_triangle Sierpinski-trekanten]. | En anden berømt fraktal er [http://en.wikipedia.org/wiki/Sierpinski_triangle Sierpinski-trekanten]. | ||
Logo script: | Logo-script: | ||
{{Input|1=<span style="color: #a0a0a4;"># Sierpinski triangle</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span> sierp <span style="color: #800080; font-weight: bold;">$l</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #800080; font-weight: bold;">$l</span> <span style="color: #5a64ff; font-weight: bold;">></span> <span style="color: #800000;">2</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">repeat</span> <span style="color: #800000;">3</span> <span style="color: #008000; font-weight: bold;">{</span><br /> sierp <span style="color: #800080; font-weight: bold;">$l</span><span style="color: #808080; font-weight: bold;">/</span><span style="color: #800000;">2</span><br /> <span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$l</span><br /> <span style="color: #000080;">turnleft</span> <span style="color: #800000;">120</span><br /> <span style="color: #008000; font-weight: bold;">}</span><br /> <span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span> <span style="color: #800000;">600</span>, <span style="color: #800000;">533</span><br /><span style="color: #000080;">go</span> <span style="color: #800000;">50</span>, <span style="color: #800000;">483</span><br /><span style="color: #000080;">turnright</span> <span style="color: #800000;">90</span><br />sierp <span style="color: #800000;">500</span>}} | {{Input|1=<span style="color: #a0a0a4;"># Sierpinski triangle</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span> sierp <span style="color: #800080; font-weight: bold;">$l</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #800080; font-weight: bold;">$l</span> <span style="color: #5a64ff; font-weight: bold;">></span> <span style="color: #800000;">2</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">repeat</span> <span style="color: #800000;">3</span> <span style="color: #008000; font-weight: bold;">{</span><br /> sierp <span style="color: #800080; font-weight: bold;">$l</span><span style="color: #808080; font-weight: bold;">/</span><span style="color: #800000;">2</span><br /> <span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$l</span><br /> <span style="color: #000080;">turnleft</span> <span style="color: #800000;">120</span><br /> <span style="color: #008000; font-weight: bold;">}</span><br /> <span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span> <span style="color: #800000;">600</span>, <span style="color: #800000;">533</span><br /><span style="color: #000080;">go</span> <span style="color: #800000;">50</span>, <span style="color: #800000;">483</span><br /><span style="color: #000080;">turnright</span> <span style="color: #800000;">90</span><br />sierp <span style="color: #800000;">500</span>}} | ||
Resultat: | |||
[[Image:KTurtle-sierpinski-triangle.png|600px|center]] | [[Image:KTurtle-sierpinski-triangle.png|600px|center]] | ||
== | ==Heighways drage== | ||
Endnu en berømt fraktal er [http://en.wikipedia.org/wiki/Dragon_curve Heighways drage]. | |||
Logo-script: | |||
{{Input|1=<span style="color: #a0a0a4;"># Heighway dragon</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span> <span style="color: #800000;">500</span>, <span style="color: #800000;">500</span><br /><span style="color: #000080;">go</span> <span style="color: #800000;">320</span>, <span style="color: #800000;">400</span><br /><span style="color: #000080;">turnright</span> <span style="color: #800000;">90</span><br /><span style="color: #800080; font-weight: bold;">$size</span> <span style="color: #000000; font-weight: bold;">=</span> <span style="color: #800000;">7</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span> X <span style="color: #800080; font-weight: bold;">$depth</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #5a64ff; font-weight: bold;">></span><span style="color: #800000;">0</span> <span style="color: #008000; font-weight: bold;">{</span><br /> X <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #000080;">turnleft</span> <span style="color: #800000;">90</span><br /> Y <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$size</span><br /> <span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span> Y <span style="color: #800080; font-weight: bold;">$depth</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #5a64ff; font-weight: bold;">></span><span style="color: #800000;">0</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$size</span><br /> X <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #000080;">turnright</span> <span style="color: #800000;">90</span><br /> Y <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br /><br /><span style="color: #000080;">pencolor</span> <span style="color: #800000;">0</span>,<span style="color: #800000;">255</span>,<span style="color: #800000;">0</span><br /><span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$size</span><br />X <span style="color: #800000;">10</span><br /><span style="color: #000080;">turnleft</span> <span style="color: #800000;">90</span><br /><span style="color: #000080;">pencolor</span> <span style="color: #800000;">255</span>,<span style="color: #800000;">0</span>,<span style="color: #800000;">0</span><br />Y <span style="color: #800000;">10</span><br /><span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$size</span><br /><br /><span style="color: #000080;">go</span> <span style="color: #800000;">50</span>,<span style="color: #800000;">450</span>}} | {{Input|1=<span style="color: #a0a0a4;"># Heighway dragon</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span> <span style="color: #800000;">500</span>, <span style="color: #800000;">500</span><br /><span style="color: #000080;">go</span> <span style="color: #800000;">320</span>, <span style="color: #800000;">400</span><br /><span style="color: #000080;">turnright</span> <span style="color: #800000;">90</span><br /><span style="color: #800080; font-weight: bold;">$size</span> <span style="color: #000000; font-weight: bold;">=</span> <span style="color: #800000;">7</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span> X <span style="color: #800080; font-weight: bold;">$depth</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #5a64ff; font-weight: bold;">></span><span style="color: #800000;">0</span> <span style="color: #008000; font-weight: bold;">{</span><br /> X <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #000080;">turnleft</span> <span style="color: #800000;">90</span><br /> Y <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$size</span><br /> <span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span> Y <span style="color: #800080; font-weight: bold;">$depth</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #5a64ff; font-weight: bold;">></span><span style="color: #800000;">0</span> <span style="color: #008000; font-weight: bold;">{</span><br /> <span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$size</span><br /> X <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #000080;">turnright</span> <span style="color: #800000;">90</span><br /> Y <span style="color: #800080; font-weight: bold;">$depth</span><span style="color: #808080; font-weight: bold;">-</span><span style="color: #800000;">1</span><br /> <span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br /><br /><span style="color: #000080;">pencolor</span> <span style="color: #800000;">0</span>,<span style="color: #800000;">255</span>,<span style="color: #800000;">0</span><br /><span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$size</span><br />X <span style="color: #800000;">10</span><br /><span style="color: #000080;">turnleft</span> <span style="color: #800000;">90</span><br /><span style="color: #000080;">pencolor</span> <span style="color: #800000;">255</span>,<span style="color: #800000;">0</span>,<span style="color: #800000;">0</span><br />Y <span style="color: #800000;">10</span><br /><span style="color: #000080;">forward</span> <span style="color: #800080; font-weight: bold;">$size</span><br /><br /><span style="color: #000080;">go</span> <span style="color: #800000;">50</span>,<span style="color: #800000;">450</span>}} | ||
Resultat: | |||
[[Image:KTurtle-heighway-dragon.png|center]] | [[Image:KTurtle-heighway-dragon.png|center]] | ||
[[Category: | [[Category:Uddannelse/da]] |
Latest revision as of 16:12, 5 September 2012
Hjem » Programmer » Uddannelse » KTurtle
Koch kurve
Dette er en fraktal kurve. Du kan finde mere information om den på Wikipedia.
Logo-script:
# Koch curve
reset
canvassize 850, 550
go 125, 350
turnright 90
learn koch $x, $t {
if $t>0 {
$t=$t-1
$x=$x/3
koch $x, $t
turnleft 60
koch $x, $t
turnright 120
koch $x, $t
turnleft 60
koch $x, $t
} else {
forward 3*$x
}
}
koch 200, 6
Resultat:
Sierpinski-trekant
En anden berømt fraktal er Sierpinski-trekanten.
Logo-script:
# Sierpinski triangle
learn sierp $l {
if $l > 2 {
repeat 3 {
sierp $l/2
forward $l
turnleft 120
}
}
}
reset
canvassize 600, 533
go 50, 483
turnright 90
sierp 500
Resultat:
Heighways drage
Endnu en berømt fraktal er Heighways drage.
Logo-script:
# Heighway dragon
reset
canvassize 500, 500
go 320, 400
turnright 90
$size = 7
learn X $depth {
if $depth>0 {
X $depth-1
turnleft 90
Y $depth-1
forward $size
}
}
learn Y $depth {
if $depth>0 {
forward $size
X $depth-1
turnright 90
Y $depth-1
}
}
pencolor 0,255,0
forward $size
X 10
turnleft 90
pencolor 255,0,0
Y 10
forward $size
go 50,450
Resultat: