Please feel free to include this in future versions of kturtle.
I'll want to write a proper modulus function for kturtle Real Soon Now
# adapted from http://pturing.livejournal.com/108896.html
learn sign $x {
if $x == 0 {
return 0
}
if $x < 0 {
return -1
}
return 1
}
learn integer_part $x {
if $x == 0 {
return 0
}
$r = sign $x
$y = 0
while ( ($r * $y) <= ($r * $x) ) {
$y = $y + $r
}
return $y - $r
}
learn fractional_part $x {
$y = integer_part $x
return ($x - $y)
}
# works at least for integers x and y, x > y > 0
learn modulus $x, $y {
$quotient = ($x / $y)
return ($x - (integer_part $quotient) * $y)
}
# / adapted from http://pturing.livejournal.com/108896.html
# c 2014 , GPL, Robin David Hammond rhammo...@databit7.com
learn min $x, $y {
if ( $x < $y ) {
return $x
} else {
return $y
}
}
learn gcf $x, $y {
$min = min $x, $y
$f = $min
repeat ( $min ) {
if ( ( (modulus $x , $f ) == 0 ) and ( (modulus $y, $f) == 0 ) ) {
return $f
}
$f = $f - 1
}
return $f
}
# d is the number of vertices # s is the number of points over which to skip, # l is the length of a stroke.
$d = 47
$s = 13
$l = 60
reset
penup
backward $l/2
pendown
$a = 360/$d # Interior angle between outerpoints
$e = ($s+1)*$a
$b = (180-$e)
$R = $l / ( 2 * cos ($b /2 )) # Radius to outerpoints
$outer = gcf $d , ($s + 1) # the regular hexagram for example has to be drawn as two triangles.
repeat ($outer ) {
repeat (1 + $d/$outer) {
forward $l
turnright 180+$b
}
penup
turnleft $b/2
forward $R
turnright 360/$d
backward $R
turnright $b/2
pendown
}
--
You received this message because you are subscribed to the Google Groups "KTurtle; an educational programming environment" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kdeedu-kturtl...@googlegroups.com.
To post to this group, send email to kdeedu-...@googlegroups.com.
Visit this group at http://groups.google.com/group/kdeedu-kturtle.
For more options, visit https://groups.google.com/groups/opt_out.