Je suis en train de convertir une esquisse de traitement en un fichier flash as3, et je suis coincé sur deux de traitement commandes - pushMatrix() et popMatrix() - quelqu'un peut-il me dire comment les convertir en flash? Essentiellement, j'ai juste besoin de stocker la matrice de lignes que j'ai dessinées jusqu'ici et dessiner une nouvelle ligne, et cela se fait récursivement. Voici mon code:flash as3 équivalent de popmatrix() de traitement et pushmatrix() - ou ... stocker une matrice de transformation
var theta;
var xpos:Number = 0;
addEventListener(Event.ENTER_FRAME,draw)
function draw(e:Event) {
graphics.lineStyle(1, 0xf1eee5, 1, false, LineScaleMode.NONE, CapsStyle.SQUARE);
var a = (mouseX/stage.stageWidth) * 90;
trace("a: " + a);
var theta = degreesToRadians(a);
graphics.moveTo(stage.stageWidth/2,stage.stageHeight);
graphics.lineTo(stage.stageWidth/2,stage.stageHeight-150);
branch(150);
if (a <= 30){
xpos+=3;
} else {
}
}
function degreesToRadians(degrees:Number):Number {
return degrees * Math.PI/180;
}
function branch(h) {
// Each branch will be 2/3rds the size of the previous one
h *= 0.66;
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 2) {
/* HASN'T BEEN CONVERTED TO FLASH AS3 YET
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0, 0, 0, -h); // Draw the branch
translate(0, -h); // Move to the end of the branch
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0, 0, 0, -h);
translate(0, -h);
println(h);
branch(h);
popMatrix();
*/
}
}