Programs to test Script Tracing
clear()
repeat (4) {
    forward(100)
    right()
}
def square(n: Int) {
    repeat(4) {
        forward(100)
        right()
    }
}

clear()
square(100)
clear()
setAnimationDelay(10) // speed up the turtle
setPenColor(gray)
var clr = Color(255, 0, 0, 127) // start with a semi transparent red color
repeat(18) {
    setFillColor(clr)
    repeat(5) {
        forward(100)
        right(72)
    }
    clr = hueMod(clr, 0.15) // change color hue
    right(360/18)
}
val l = List(1,2,3)
val x = l map (_ + 1)
def fn(l: List[Int]) = l map (_ + 1)
fn(x)
def double(n: Int) =
    n * 2

val bigger = math.max(2, 4)
double(bigger)
def factorial(n: Int): Int =
    if (n == 0) 1 else n * factorial(n - 1)

factorial(4)
var sum = 0
var i = 0
while(i < 10) {
  sum = sum + i
  i = i + 1
}
println(sum)
clear
forward(100)
var t = newTurtle(50,50)
t.right
t.forward(50)
left
forward(50)
def tick(n: Int) {
            // save current style, position and heading
            saveStyle()
            savePosHe()
            setPenColor(gray)
            right()
            forward(n)
            back(n * 2)
            restorePosHe()
            restoreStyle()
            // restore caller's style, position and heading
        }

clear()
setPenColor(green)
right()
//green line
forward(100)
// grey tick
tick(10)
// green line
forward(100)
clear()
setPenFont(Font("Cambria", 20))
// write with Cambria font
write("Hi There")
forward(50)
setPenFont(Font("Calibri", 40))
write("Hi There")
clear
beamsOn
setHeading(40)
forward(100)
beamsOff
clear
var t = newTurtle(0,100)
var t1 = newTurtle(0,10)
println(t1.distanceTo(t))
t1.remove()
val l = new java.util.ArrayList[String]
l.add("abc")
l.add("def")
inspect(l)
def p = Picture {
    right(30)
    forward(100)
}

val pic = picStack(p, trans(50, 30) * rot(-30) -> p)
cleari()
draw(pic)
def p = Picture {
    right(30)
    forward(100)
}

val pic = picRow(p, trans(50, 30) * rot(-30) -> p, p)
cleari()
draw(pic)
def p = Picture {
    right(30)
    forward(100)
}

def drawing(n: Int): Picture = {
    if (n == 1)
        p
    else
        picStack(p, scale(1.1) * rot(10) -> drawing(n - 1))
}

val pic = drawing(5)
cleari()
draw(pic)
def p = Picture {
    right(30)
    forward(100)
}

val pic1 = p
val pic2 = trans(50, 20) * rot(-60) -> p
val pic3 = trans(50, 20) * rot(30) -> p

cleari()
draw(pic1, pic2, pic3)
def p = Picture {
    repeat(4) {
        forward(50)
        right()
    }
}

val pic = picRow(
      p,
      picCol(
            p,
            picRow(
                  p,
                  p
            )
      ),
      p
)

cleari()
draw(pic)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License