KTurtle/Examples/uk: Difference between revisions

From KDE Wiki Sandbox
(Updating to match new version of source page)
(Created page with "{{Input|1=<span style="color: #a0a0a4;"># Крива Коха</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span>...")
Line 12: Line 12:
Скрипт Logo:
Скрипт Logo:


{{Input|1=<span style="color: #a0a0a4;"># Koch curve</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span>&nbsp;<span style="color: #800000;">850</span>,&nbsp;<span style="color: #800000;">550</span><br /><span style="color: #000080;">go</span>&nbsp;<span style="color: #800000;">125</span>,&nbsp;<span style="color: #800000;">350</span><br /><span style="color: #000080;">turnright</span>&nbsp;<span style="color: #800000;">90</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span>&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span>&nbsp;<span style="color: #008000; font-weight: bold;">{</span><br />&nbsp;&nbsp;<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;">&gt;</span><span style="color: #800000;">0</span> &nbsp;<span style="color: #008000; font-weight: bold;">{</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<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 />&nbsp;&nbsp;&nbsp;&nbsp;<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 />&nbsp;&nbsp;&nbsp;&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000080;">turnleft</span>&nbsp;<span style="color: #800000;">60</span><br />&nbsp;&nbsp;&nbsp;&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000080;">turnright</span>&nbsp;<span style="color: #800000;">120</span><br />&nbsp;&nbsp;&nbsp;&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000080;">turnleft</span>&nbsp;<span style="color: #800000;">60</span><br />&nbsp;&nbsp;&nbsp;&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span><br />&nbsp;&nbsp;<span style="color: #008000; font-weight: bold;">}</span>&nbsp;<span style="color: #000000; font-weight: bold;">else</span>&nbsp;<span style="color: #008000; font-weight: bold;">{</span><br />&nbsp;&nbsp;<span style="color: #000080;">forward</span>&nbsp;<span style="color: #800000;">3</span><span style="color: #808080; font-weight: bold;">*</span><span style="color: #800080; font-weight: bold;">$x</span>&nbsp;<br />&nbsp;&nbsp;<span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br />koch&nbsp;<span style="color: #800000;">200</span>,&nbsp;<span style="color: #800000;">6</span>}}
{{Input|1=<span style="color: #a0a0a4;"># Крива Коха</span><br /><br /><span style="color: #000080;">reset</span><br /><span style="color: #000080;">canvassize</span>&nbsp;<span style="color: #800000;">850</span>,&nbsp;<span style="color: #800000;">550</span><br /><span style="color: #000080;">go</span>&nbsp;<span style="color: #800000;">125</span>,&nbsp;<span style="color: #800000;">350</span><br /><span style="color: #000080;">turnright</span>&nbsp;<span style="color: #800000;">90</span><br /><br /><span style="color: #00ff00; font-weight: bold;">learn</span>&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span>&nbsp;<span style="color: #008000; font-weight: bold;">{</span><br />&nbsp;&nbsp;<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;">&gt;</span><span style="color: #800000;">0</span> &nbsp;<span style="color: #008000; font-weight: bold;">{</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<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 />&nbsp;&nbsp;&nbsp;&nbsp;<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 />&nbsp;&nbsp;&nbsp;&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000080;">turnleft</span>&nbsp;<span style="color: #800000;">60</span><br />&nbsp;&nbsp;&nbsp;&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000080;">turnright</span>&nbsp;<span style="color: #800000;">120</span><br />&nbsp;&nbsp;&nbsp;&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000080;">turnleft</span>&nbsp;<span style="color: #800000;">60</span><br />&nbsp;&nbsp;&nbsp;&nbsp;koch&nbsp;<span style="color: #800080; font-weight: bold;">$x</span>,&nbsp;<span style="color: #800080; font-weight: bold;">$t</span><br />&nbsp;&nbsp;<span style="color: #008000; font-weight: bold;">}</span>&nbsp;<span style="color: #000000; font-weight: bold;">else</span>&nbsp;<span style="color: #008000; font-weight: bold;">{</span><br />&nbsp;&nbsp;<span style="color: #000080;">forward</span>&nbsp;<span style="color: #800000;">3</span><span style="color: #808080; font-weight: bold;">*</span><span style="color: #800080; font-weight: bold;">$x</span>&nbsp;<br />&nbsp;&nbsp;<span style="color: #008000; font-weight: bold;">}</span><br /><span style="color: #008000; font-weight: bold;">}</span><br />koch&nbsp;<span style="color: #800000;">200</span>,&nbsp;<span style="color: #800000;">6</span>}}


Результат:
Результат:

Revision as of 18:38, 4 September 2012

Other languages:

Домівка » Програми » Освіта » KTurtle » KTurtle/Examples/uk


Підказка
Форматування скриптів отримано за допомогою можливості Експортування до HTML KTurtle.



Крива Коха

Це фрактальна крива. Докладніші відомості щодо неї можна отримати зі сторінки Вікіпедії.

Скрипт Logo:

# Крива Коха

reset
canvassize 850550
go 125350
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 2006

Результат:

Трикутник Серпінського

Ще один відомий фрактал — трикутник Серпінського.

Скрипт Logo:

# Sierpinski triangle

learn sierp $l {
  if $l > 2 {
    repeat 3 {
      sierp $l/2
      forward $l
      turnleft 120
    }
  }
}

reset
canvassize 600533
go 50483
turnright 90
sierp 500

Результат:

Дракон Гейвея

Відомий фрактал — Дракон Гейвея.

Скрипт Logo:

# Heighway dragon

reset
canvassize 500500
go 320400
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
10
turnleft 90
pencolor 255,0,0
10
forward $size

go 50,450

Результат: