| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 | <html><!--Example of using the turtle module in skulpt.Author:  Brad MillerNote:  One important convention, since I plan to usemultiple turtle canvases on a page I am passing the runitfunction a prefix to use in creating the id for the following:  - textarea containing the code  - pre tag for any printed output  - canvas tag for the turtleI've enclosed the whole group of them in a div because I was thinkingat one point about creating the pre tag and the canvas tag on the flythe more I think about it the more I wonder...--><head><title>Processing Integration with Skulpt</title><link rel="stylesheet" type="text/css" media="all" href="main.css"><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script><script src="env/codemirror/js/codemirror.js" type="text/javascript"></script><script src="env/editor.js" type="text/javascript"></script><script src="skulpt.js" type="text/javascript"></script><script src="builtin.js" type="text/javascript"></script><script src="processing-1.4.1.min.js" type="text/javascript"></script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript" ></script></head><div class="page">    <div class="body">        <div class="main"><body><script type="text/javascript">function outf(text) {   var mypre = document.getElementById(Sk.pre);   text = text.replace(/</g, "<").replace(/>/g, ">").replace(/\n/g, "<br/>")   mypre.innerHTML = mypre.innerHTML + text;}function builtinRead(x){    if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)        throw "File not found: '" + x + "'";    return Sk.builtinFiles["files"][x];}function runit(myDiv) {   var prog = document.getElementById(myDiv+"_code").value;   var mypre = document.getElementById(myDiv+"_pre");   mypre.innerHTML = '';   Sk.divid = myDiv;   Sk.canvas = myDiv+"_canvas";    var can = document.getElementById(Sk.canvas);    can.style.display = 'block';    if (can) {        can.width = can.width;        if (Sk.tg) {            Sk.tg.canvasInit = false;            Sk.tg.turtleList = [];        }    }   Sk.pre = myDiv+"_pre";   Sk.configure({output:outf,  	        read: builtinRead              });   try {      Sk.importMainWithBody("<stdin>",false,prog);   } catch (e) {      alert(e);   }}</script><h1>Integrating Skulpt and the DOM</h1><div id="example2"><textarea edit_id="eta_5a" id="example2_code" cols="60" rows="21">from urllib.request import urlopenpage = urlopen('http://knuth.luther.edu/~bmiller/hello.html')text = page.read()print textprint "-------------------------------"page = urlopen('http://knuth.luther.edu/~bmiller/hello.html')for line in page:   print lineprint "-------------------------------"page = urlopen('http://knuth.luther.edu/~bmiller/hello.html')line = page.readline()while line:   print line   line = page.readline()</textarea><button onclick="runit('example2')" type="button">Run</button><canvas id="example2_canvas"></canvas><pre id="example2_pre"></pre></div></body></div> </div></div></html>
 |