sku-pg
Version:
Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!
109 lines (93 loc) • 3.17 kB
HTML
<html>
<!--
Example of using the turtle module in skulpt.
Author: Brad Miller
Note: One important convention, since I plan to use
multiple turtle canvases on a page I am passing the runit
function 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 turtle
I've enclosed the whole group of them in a div because I was thinking
at one point about creating the pre tag and the canvas tag on the fly
the 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 urlopen
page = urlopen('http://knuth.luther.edu/~bmiller/hello.html')
text = page.read()
print text
print "-------------------------------"
page = urlopen('http://knuth.luther.edu/~bmiller/hello.html')
for line in page:
print line
print "-------------------------------"
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>