import math._ def f(x: Double): Double = { // 3*x*x+x // or 3*math.pow(3,2)+x sin(x) } clear def drawGraph(f:Double=>Double) { val (s, e, step) = (-10.0, 10.0, 0.1) val (sx, sy) = (10, 100) val (tx, ty, t) = (newTurtle, newTurtle, newTurtle) runInBackground { tx.jumpTo(s * sx, 0); tx.moveTo(e * sx, 0) } runInBackground { ty.jumpTo(0, -1 * sy) ty.moveTo(0, sy * (s to e by step).map(f).max) } runInBackground { t.jumpTo(s * sx, f(s) * sy) for (x <- s to e by step) t.moveTo(x * sx, f(x) * sy) } } drawGraph(f)