(load "bunnu.k") [Shell grammar: 'bunnu] println "Hello world\n"; // Show a canvas var canvas = ImageBox.newImage:(SDLImage.newExtent:([400, 400].asPoint())); var frame = FrameBox.with:title:(canvas, "turtle"); frame.position:([440, 10].asPoint()); Window.default().addFront:(frame); // Prepare the context and draw a circle just for testing. var ctx = SDLContext.new:(canvas.image()); ctx.color:(Color.withR:withG:withB:(200, 180, 60)); ctx.fillCircle:radius:([100,50].asPoint(), 80); canvas.damaged(); // Setting up the turtle. var x = 200; var y = 200; var angle = 0; // Define a couple of turtle functions. var forward = function(n) { var newX = x + n * angle.cos(); var newY = y + n * angle.sin(); ctx.color:(Color.withR:withG:withB:(0, 150, 20)); ctx.drawLine:to:(Point.withX:withY:(x, y).asPoint(), Point.withX:withY:(newX,newY).asPoint()); canvas.damaged(); x = newX; y = newY; }; var turn = function(n) { angle = angle + n * Float.pi() / 180; }; var clean = function() { ctx.color:(Color.withR:withG:withB:(255, 255, 255)); ctx.fillRectangle:extent:([0,0].asPoint(), [400,400].asPoint()); x = 200; y = 200; angle = 0; canvas.damaged(); }; forward(100); turn(144); clean(); for (i = 1; i <= 40; i = i + 1) { forward(4 * i); turn(89); } var inspi = function(side, angle, inc) { for (i = 0; i < 2000; i = i + 1) { forward(side); turn(angle + inc * i); } }; inspi(20, 40, 30); canvas.onMotion: = function (event) { clean(); inspi(8, event.position().x(), event.position().y()); };