KTurtle/Examples: Difference between revisions

From KDE Wiki Sandbox
No edit summary
(3 examples: fractals with recursion)
Line 1: Line 1:
{{EduBreadCrumbs|parent=KTurtle}}
{{EduBreadCrumbs|parent=KTurtle}}
{{Construction}}


{| cellpadding="10"
{| cellpadding="10"
Line 35: Line 34:
Result:
Result:
[[Image:KTurtle-heighway-dragon.png|center]]
[[Image:KTurtle-heighway-dragon.png|center]]
[[Category:Education]]

Revision as of 13:46, 8 July 2010

Home » Applications » Education » KTurtle » Examples


Tip
Script formatting results from the HTML export of KTurtle.


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:

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:

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
  }
}

forward $size
11

go 50,450

Result: