Question:
trying to draw a tree in flash using the drawing api?
Hussain A
2009-12-10 03:23:25 UTC
heres what i have so far:
var trees:MovieClip = new MovieClip();
trees.graphics.beginFill(0xA03001);
trees.graphics.drawRect(200,250,5,35);
trees.graphics.beginFill(0x0A980A);
trees.graphics.curveTo(200,0,190,210);

i have the trunk of the tree but I just do not understand the graphics.curveTo parameters
Three answers:
?
2009-12-10 03:32:50 UTC
package {

import flash.display.*;

import flash.events.*;

import flash.utils.*;

import flash.errors.*;



public class DrawTrees extends MovieClip {



//drawing board variables

private static const DrawBoardWidth:uint=500;

private static const DrawBoardHeight:uint=500;

private static const DrawBoardPegHorizontalSpacing:uint=50;

private static const DrawBoardPegVerticalSpacing:uint=50;

private static const DrawBoardOffsetx:int=25;

private static const DrawBoardOffsety:int=25;

private static const GroundHeight:int=400;



//tree variables, including different player colors

private static const pointSize:uint=5;

private static const playerOneColor:uint=0x000000;

private static const playerTwoColor:uint=0xFFFFFF;



//this is the number of players. each should have his own tree.

public var NumberOfPlayers:uint=1;



//this is the current player's number. eventually, should switch between turns.

public var CurrentPlayer:uint=1;

public var CurrentPlayerColor:uint=playerOneColor;//current player's color switches between turns, too.

public var SelectedPoint:Sprite=null;//the currently-selected point. NOTE: Does this work?

public var PointIsSelected:Boolean=false;//is a point selected?



//this array will hold all of the trees

public var allTrees:Array=null;



//this is where the points will be drawn- a limiting box.

public var DrawBoard:Sprite=new Sprite;



//constructor function

public function DrawTrees() {

MakeDrawBoard();

FillallTrees(NumberOfPlayers);

DrawBoard.addEventListener(MouseEvent.CLICK,DrawTreePoint);//draw a point when they click



}

//this makes and places the drawing board (limit of where points can be drawn)

//NOTE: this will eventually have to be invisible. how to do this?

public function MakeDrawBoard() {

DrawBoard.graphics.lineStyle(2,0x000000);

DrawBoard.graphics.beginFill(0xFF0000);

DrawBoard.graphics.drawRect(0,0,DrawBoardWidth,DrawBoardHeight);

DrawBoard.graphics.endFill();

DrawBoard.x=DrawBoardOffsetx;

DrawBoard.y=DrawBoardOffsety;

stage.addChild(DrawBoard);

}

//this fills the allTrees array with new tree arrays, up to the number of players (each player has a tree)

public function FillallTrees(NumberOfPlayers:uint) {

allTrees=new Array;

for (var x:uint=0; x < NumberOfPlayers; x++) {

var tree:Array=new Array ;

allTrees.push(tree);

}

}

//this creates, adds to trees, and draws points, given X and Y coordinates (pointX and pointY, respectively)

public function DrawTreePoint(event:MouseEvent) {

var newbranch:Object=new Object;



if (allTrees[CurrentPlayer - 1].length == 0) {//if the current player's tree length is zero (no points have been added):

newbranch.point=new Sprite;

newbranch.point.addEventListener(MouseEvent.CLICK,SelectPoint);

newbranch.point.graphics.lineStyle(0,CurrentPlayerColor);//the color of the point changes depending on whose turn it is.

newbranch.point.graphics.beginFill(CurrentPlayerColor);//this too

newbranch.point.graphics.drawCircle(event.localX,GroundHeight,pointSize);//add point at their cursor's x, but at GroundHeight y.

newbranch.point.graphics.endFill();

allTrees[CurrentPlayer - 1].push(newbranch);//this should add the new point to the end of the tree-array of the current player

DrawBoard.addChild(allTrees[CurrentPlayer - 1][allTrees[CurrentPlayer - 1].length - 1].point);/*this should add to DrawBoard the point that was just added

(in current player's tree array, the point that is at the current length of the array, minus one (to compensate for 0 index)*/



} else if (PointIsSelected) {//if a point is selected:

//add a new point,

newbranch.point=new Sprite;

newbranch.point.addEventListener(MouseEvent.CLICK,SelectPoint);

newbranch.point.graphics.lineStyle(0,CurrentPlayerColor);//the color of the point changes depending on whose turn it is.

newbranch.point.graphics.beginFill(CurrentPlayerColor);//this too

newbranch.point.graphics.drawCircle(event.localX,event.localY,pointSize);//add point at their cursor

newbranch.point.graphics.endFill();

//and a new line.

newbranch.branch=new Shape;

newbranch.branch.graphics.lineStyle(3,CurrentPlayerColor);

newbranch.branch.graphics.moveTo(newbranch.point.x,newbranch.point.y);

newbranch.branch.graphics.lineTo(SelectedPoint.x,SelectedPoint.y);

//add newbranch to tree array

allTrees[CurrentPlayer - 1].push(newbranch);//this should add the new point to the end of the tree-array of the current player

//draw new point and branch

DrawBoard.addChild(allTrees[CurrentPlayer - 1][allTrees[CurrentPlayer - 1].length - 1].point);/*this should add to DrawBoard the point that was just added

(in current player's tree array, the point that is at the current length of the array, minus one (to compensate for 0 index)*/

D
?
2016-10-15 03:15:06 UTC
i want some explanation right here, Tim: Are you drawing a penis that doesn't in any different case exist onto your physique? Or artistically adorning a pre-contemporary appendage? the two way i've got faith a sombre, frowny face to be the extra desirable expression. adult men's front bottoms are no longer any giggling count number! i glance forward on your replace.
ralphus
2009-12-10 04:38:52 UTC
Hi, its easier to understand the curve to() when you see it in action, its difficult to understand when its explained so:



you normally have a graphics.moveto() to set a line start position ( lets say (100,100)



in your example curve to(200,0,190,210)



the last 2 numbers are where the line will finish (their x,y) and the first 2 are the point at which the line will curve to eg.



(200,0)

/ \

/ \

/ \

/ \

/ \

(100,100) (190,210)



yahoo is shrinking my excellent ascii graphics but you should get the idea. if not go here



http://www.flashessential.com/archives/94


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...