Concept: A user inputs distances and angles so mcPencil can draw a shape/polygon on screen. The user inputs a distance; mcPencil draws a straight line. The user then inputs an angle; mcPencil turns that angle (using mcPencil.rotation += turnDegree); the user inputs another distance for mcPencil to draw another straight line at that angle to the first line.
My goal is to end up with a piece of ‘educational software’ to replicate (if you’re of a similar generation to me, you may remember) the old, screen-based Turtle graphics (v. simple kids’ programming eg FORWARD 50, TURN 90, FORWARD 50 etc etc to draw a square) on the old BBC “computers”/BBC BASIC etc.
Problem: Using AS3, the user can input distances, draw straight lines and input angles, but not draw the second or subsequent lines at an angle to the first, though mcPencil has rotated by ‘turnDegree’. The second line simply continues the first.
inputLabel.text = "Forward"; // label for userInput
stage.focus = userInput; // input distance to draw
… submit userInput value on pressing Enter using an Event Listener
graphics.lineStyle(2, 0x000000);
// set the starting point for the line; current location of mcPencil
graphics.moveTo(mcPencil.x, mcPencil.y);
mcPencil.x + = (Number(userInput.text));
// draw the line to new mcPencil.x; mcPencil.y must also be involved!?
graphics.lineTo(mcPencil.x, mcPencil.y);
…
inputLabel.text = "Turn";
stage.focus = userInput; // input angle to turn
var turnDegree:Number = Number(userInput.text);
… submit userInput value on pressing Enter using an Event Listener
mcPencil.rotation += turnDegree;
So, how to draw second line at an angle to the first?
I’ve also tried to use copies of a movie clip (mcDrawingLine) using
for (var i:Number =0; i<100; i++){
root["myLine" + i] =new mcDrawingLine();
}
& then positioning & rotating the lines depending on the user input (values for ‘Forward’ & ‘Turn’).
movieclipNumber ++;
(root["myLine" + movieclipNumber]).x = pencil.x ;
(root["myLine" + movieclipNumber]).y = pencil.y ;
(root["myLine" + movieclipNumber]).width += Number(fromInput.text);
(root["myLine" + movieclipNumber]).rotation += turnDegree;
addChild(root["myLine" + movieclipNumber]);
pencil.x = (root["myLine" + movieclipNumber]).x;
pencil.y = (root["myLine" + movieclipNumber]).y;
This has made progress in that the lines are drawn & angles turned… but, because I have been unsuccessful in moving myLine’s registration point, the 2[SUP]nd[/SUP] & subsequent lines are drawn over the first (ie always originating at pencil.x/pencil.y).
I also tried putting myLines in containers so I could draw myLine2 from container1’s registration point, myline3 from conatiner2’s reg point etc).
(root["myLine" + movieclipNumber]).y = pencil.y ;
(root["myLine" + movieclipNumber]).width = Number(fromInput.text);
(root["myLineContainer" + movieclipNumber]).rotation += turnDegree;
root["myLineContainer" + movieclipNumber].addChild (root["myLine" + movieclipNumber]);
pencil.x = (root["myLineContainer" + movieclipNumber]).x;
pencil.y=(root["myLineContainer" + movieclipNumber]).y;
The problems I had with this were
a) I didn’t know/couldn’t find container’s reg points
b) I wasn’t convinced myLine was actually in its container as I couldn’t see it (or myLine!) &
c) The pencil relocated to (0,0)
Any help would be gratefully appreciated! Even suggestions for a different solution –my attempts to solve this apparently simple problem are becoming more & more (unnecessarily?) elaborate!