123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <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);
- 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 document import *
- p = getElementById('myp')
- p.innerHTML = 'foo'
- div = getElementById('example2')
- h1 = createElement("h1")
- h1.innerHTML = 'HELLO'
- h1.setCSS('color','#f00')
- div.appendChild(h1)
- l = getElementsByTagName('h1')
- for e in l:
- print e.innerText
- ct = getElementsByName('loopcount')[0].value
- print ct
- for i in range(int(ct)):
- print i
- </textarea>
- How many times to loop <input type="text" name="loopcount" value="10" />
- <button onclick="runit('example2')" type="button">Run</button>
- <canvas id="example2_canvas"></canvas>
- <pre id="example2_pre"></pre>
- </div>
- <h3>Output should appear here</h3>
- <p id="myp"></p>
- </body>
- </div> </div></div>
- </html>
|