#include "drawArc.as" fscommand("fullscreen", "true"); fscommand("allowscale", "false"); //Legitimate commands validCommands = new Array("fd", "bk", "rt", "lt", "repeat", "pu", "pd", "cs", "ht", "st", "rc", "lc","arc", "return"); //Initial pen settings pen = "penDown"; _global.canvas = this; //Pen style and location canvas.lineStyle(1,0xFFFFFF); canvas.moveTo(logo._x, logo._y); inix = logo._x; iniy = logo._y; function init() { var msg; input_txt.background = true; input_txt.backgroundColor = 0xFFFFFF; story.history_txt.background = true; story.history_txt.backgroundColor = 0xFFFFFF; story.history_txt.text = "Welcome to logodoodle\rType in a command in the input box and press ENTER\r--------------------------------------------------------------------------------------\r"; msg="EXAMPLE: fd 100 rt 90 fd 100 lt 90"; message(msg); msg="EXAMPLE: repeat 4 fd 100 rt 90"; message(msg); msg="EXAMPLE: repeat 4 fd 50 lc 50 90"; message(msg); msg= "Origin [x: "+(logo._x-400)+", y: "+(-(logo._y-300))+", angle: "+logo._rotation+"]"; message(msg); story.turtleAngle.text="0"; story.xStatus.text="0"; story.yStatus.text="0"; rawCommands = undefined; comando = ""; commandElement = new Array(); commandParameters = new Array(); } // Save the command history function message(theMessage) { story.history_txt.text += "\r"+theMessage; story.history_txt.scroll = story.history_txt.maxscroll; } function handleRepeat() { delete commandElement; delete commandParameters;delete commandParameters2; delete commandParts; commandElement = new Array(); commandParameters = new Array(); commandParameters2 = new Array(); commandParts = rawCommands.split(" "); if (commandParts[0] != "repeat") { commandParts.reverse(); commandParts.push("1", "repeat"); commandParts.reverse(); processCommand(); } else { processCommand(); } } function processCommand() { j = 0; for (i=2; i<=(commandParts.length-1); ) { commandItem = commandParts[i]; parsedNOK=1; for (e=0; e<(validCommands.length); e++) { if (commandItem == validCommands[e]) { parsedNOK=0; if (commandItem == "pu" | commandItem == "pd" | commandItem == "st" | commandItem == "ht") { commandElement[j] = commandItem; commandParameters[j] = ""; j++;i += 1; } else if (commandItem =="arc" | commandItem=="lc" | commandItem=="rc") { commandElement[j] = commandItem; commandParameters[j] = commandParts[i+1]; commandParameters2[j] = commandParts[i+2]; j++;i += 3; } else { commandElement[j] = commandItem; commandParameters[j] = commandParts[i+1]; j++;i += 2; } } } if (parsedNOK) {message("ERROR - I do not understand the following command:\t");return;} } executeCommand(); } function curvePath(x,y,r,th) { var orientation; temp = new Array(); orientation=-logo._rotation; temp = drawArc(x, y,r,th,orientation); var msg="rot:"+logo._rotation+" th:"+th;message(msg); logo._rotation -= th; logo._x=temp["x"]; logo._y = temp["y"]; updateAfterEventAJH(); } function parseCommands() { rawCommands = input_txt.text.toLowerCase(); handleRepeat(); var msg=input_txt.text; msg += " [x: "+(logo._x-400)+", y: "+(-(logo._y-300))+", angle: "+logo._rotation+"]"; message(msg); //message(input_txt.text); input_txt.text = ""; } function updateAfterEventAJH() { story.xStatus.text=logo._x - 400; story.yStatus.text=-(logo._y - 300); story.turtleAngle.text=logo._rotation; updateAfterEvent(); } function executeCommand() { if (isNaN(commandParts[1]) == false) { repetitions = Number(commandParts[1])+1; for (o=1; o