urltest.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <html>
  2. <!--
  3. Example of using the turtle module in skulpt.
  4. Author: Brad Miller
  5. Note: One important convention, since I plan to use
  6. multiple turtle canvases on a page I am passing the runit
  7. function a prefix to use in creating the id for the following:
  8. - textarea containing the code
  9. - pre tag for any printed output
  10. - canvas tag for the turtle
  11. I've enclosed the whole group of them in a div because I was thinking
  12. at one point about creating the pre tag and the canvas tag on the fly
  13. the more I think about it the more I wonder...
  14. -->
  15. <head>
  16. <title>Processing Integration with Skulpt</title>
  17. <link rel="stylesheet" type="text/css" media="all" href="main.css">
  18. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
  19. <script src="env/codemirror/js/codemirror.js" type="text/javascript"></script>
  20. <script src="env/editor.js" type="text/javascript"></script>
  21. <script src="skulpt.js" type="text/javascript"></script>
  22. <script src="builtin.js" type="text/javascript"></script>
  23. <script src="processing-1.4.1.min.js" type="text/javascript"></script>
  24. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript" >
  25. </script>
  26. </head>
  27. <div class="page">
  28. <div class="body">
  29. <div class="main">
  30. <body>
  31. <script type="text/javascript">
  32. function outf(text) {
  33. var mypre = document.getElementById(Sk.pre);
  34. text = text.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br/>")
  35. mypre.innerHTML = mypre.innerHTML + text;
  36. }
  37. function builtinRead(x)
  38. {
  39. if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
  40. throw "File not found: '" + x + "'";
  41. return Sk.builtinFiles["files"][x];
  42. }
  43. function runit(myDiv) {
  44. var prog = document.getElementById(myDiv+"_code").value;
  45. var mypre = document.getElementById(myDiv+"_pre");
  46. mypre.innerHTML = '';
  47. Sk.divid = myDiv;
  48. Sk.canvas = myDiv+"_canvas";
  49. var can = document.getElementById(Sk.canvas);
  50. can.style.display = 'block';
  51. if (can) {
  52. can.width = can.width;
  53. if (Sk.tg) {
  54. Sk.tg.canvasInit = false;
  55. Sk.tg.turtleList = [];
  56. }
  57. }
  58. Sk.pre = myDiv+"_pre";
  59. Sk.configure({output:outf,
  60. read: builtinRead
  61. });
  62. try {
  63. Sk.importMainWithBody("<stdin>",false,prog);
  64. } catch (e) {
  65. alert(e);
  66. }
  67. }
  68. </script>
  69. <h1>Integrating Skulpt and the DOM</h1>
  70. <div id="example2">
  71. <textarea edit_id="eta_5a" id="example2_code" cols="60" rows="21">
  72. from urllib.request import urlopen
  73. page = urlopen('http://knuth.luther.edu/~bmiller/hello.html')
  74. text = page.read()
  75. print text
  76. print "-------------------------------"
  77. page = urlopen('http://knuth.luther.edu/~bmiller/hello.html')
  78. for line in page:
  79. print line
  80. print "-------------------------------"
  81. page = urlopen('http://knuth.luther.edu/~bmiller/hello.html')
  82. line = page.readline()
  83. while line:
  84. print line
  85. line = page.readline()
  86. </textarea>
  87. <button onclick="runit('example2')" type="button">Run</button>
  88. <canvas id="example2_canvas"></canvas>
  89. <pre id="example2_pre"></pre>
  90. </div>
  91. </body>
  92. </div> </div></div>
  93. </html>