123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <script src="skulpt.min.js" type="text/javascript"></script>
- <script src="skulpt-stdlib.js" type="text/javascript"></script>
- </head>
- <body>
- <p>To use this as a test file, you need to run it in a local server. python -m http.server --port 8889 should work.</p>
- <img id="meme" src="logo.png">
- <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.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
- });
- var myPromise = Sk.misceval.asyncToPromise(function() {
- return Sk.importMainWithBody("<stdin>",false,prog,true);
- });
- myPromise.then(function(mod) {}, function(err) {
- console.log(err.toString());
- });
- }
- </script>
- <h3>Try This</h3>
- <div id="example1">
- <form>
- <textarea edit_id="eta_5" id="example1_code" cols="60" rows="10">
- import image
- img = image.Image("meme")
- win = image.ImageWin()
- img.draw(win)
- img.setDelay(1,15)
- for col in range(img.getWidth()):
- for row in range(img.getHeight()):
- p = img.getPixel(col,row)
- p.setRed(255-p.getRed())
- p.setGreen(255-p.getGreen())
- p.setBlue(255-p.getBlue())
- img.setPixel(col,row,p)
- </textarea>
- <button onclick="runit('example1')" type="button">Run</button>
- </form>
- <div id="example1_canvas" height="500" width="800"
- style="border-style: solid; display: none"></div>
- <pre id="example1_pre"></pre>
- </div>
- </body>
- </html>
|