KTurtle/Examples

Jump to: navigation, search
Other languages:
dansk • ‎English • ‎українська

Home » Applications » Education » KTurtle » Examples

Ktip.png
 
Tip
Script formatting results from the HTML export of KTurtle.


Note-box-icon.png
 
Note for translators
If you want to translate the scripts the best way is probably to create the script in KTurtle, export it as HTML, and insert the exported HTML in the respective Input templates. Alternatively, simply leave the scripts untranslated. A simpler solution using the syntaxhighlight tag is currently being investigated



Koch curve

This is a fractal curve. You can find more information about this at Wikipedia.

Logo script:

# Koch curve

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

Result:

KTurtle-koch-curve.png

Sierpinski Triangle

Another famous fractal is the Sierpinski triangle.

Logo script:

# 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

Result:

KTurtle-sierpinski-triangle.png

Heighway Dragon

Another famous fractal is the Heighway Dragon.

Logo script:

# 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

Result:

KTurtle-heighway-dragon.png

This page was last modified on 5 September 2012, at 05:59. Content is available under Creative Commons License SA 4.0 unless otherwise noted.