Login   Register  
Icontem

File: star.html

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Arturs Sosins  >  Canvas Turtle  >  star.html  >  Download  
File: star.html
Role: Example script
Content type: text/plain
Description: Interpreter example
Class: Canvas Turtle
Interpret and render graphic commands in a Canvas
Author: By
Last change:
Date: 2011-09-11 12:09
Size: 1,687 bytes
 

Contents

Class file image Download
<!--
/*************************************************************
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com
 * Feel free to distribute and modify code, but keep reference to its creator
 *
 * Canvas Turtle provides LOGO Turtle Grpahics Javascript API 
 * and LOGO Turtle Grpahic language interpreter for drawing
 * objects in Canvas
 *
 * For more information, examples and online documentation visit: 
 * http://webcodingeasy.com/JS-classes/Canvas-Turtle-graphics-using-javascript
**************************************************************/
-->
<html>
<head>
</head>
<body>
<div>
<p>Emulate formal grammar using string replace:</p>
<!--<pre>
axiom : draw 100
	right 120 
	draw 100 
	right 120 
	draw 100
rule1 : draw 100 -> 	draw 100 
			left 60 
			draw 100 
			right 120 
			draw 100 
			left 60 
			draw 100
rule2 : right 120 -> right 120
rule3 : left 60 -> left 60
</pre>-->
</div>
<div id='logo_div'></div>
<p><input type='button' value='Next Step' onclick='next();'/></p>
<script src="./canvas_turtle.packed.js" type="text/javascript"></script>
<script>
var l = new canvas_turtle("logo_div", {
	//width of canvas
	width: 800,
	//height of canvas
	height: 600,
	//start value for x axis
});
l.exec("left 90\r\nmove 5\r\nright 180");
var cmd = "draw 10\r\nright 120\r\ndraw 10\r\nright 120\r\ndraw 10";
l.exec(cmd);
function next(){
	var rep = "draw 10\r\nleft 60\r\ndraw 10\r\nright 120\r\ndraw 10\r\nleft 60\r\ndraw 10";
	l.clear();
	l.exec("left 90\r\nmove 5\r\nright 180");
	cmd = cmd.replace(new RegExp("draw 10", "g"), rep);
	l.exec(cmd);
}
</script>
</body>
</html>