turtle.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <html>
  2. <head>
  3. <script src="../dist/skulpt.min.js" type="text/javascript"></script>
  4. <script src="../dist/skulpt-stdlib.js" type="text/javascript"></script>
  5. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
  6. </head>
  7. <body>
  8. <div id="mycanvas" height="500" width="800"
  9. style="border-style: solid;"></div>
  10. <textarea id="code" rows="24" cols="80">
  11. import turtle
  12. wn = turtle.Screen()
  13. babbage = turtle.Turtle()
  14. babbage.shape("triangle")
  15. n = 8
  16. angle = 360/n
  17. for i in range(n):
  18. babbage.right(angle)
  19. babbage.forward(90)
  20. babbage.stamp()
  21. wn.exitonclick()
  22. </textarea>
  23. <script>
  24. var prog = document.getElementById("code").value;
  25. function builtinRead(x) {
  26. if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
  27. throw "File not found: '" + x + "'";
  28. return Sk.builtinFiles["files"][x];
  29. }
  30. (Sk.TurtleGraphics || (Sk.TurtleGraphics = {})).target = 'mycanvas';
  31. Sk.configure({ read: builtinRead });
  32. Sk.misceval.asyncToPromise(function() {
  33. return Sk.importMainWithBody("<stdin>",false,prog,true);
  34. });
  35. </script>
  36. </body>
  37. </html>