The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> Flash Help
|
Flash cordinates and pixels
Discuss Flash cordinates and pixels in the Flash Help forum on Dev Shed. Flash cordinates and pixels Flash Help forum discussing all products originally created by Macromedia including DreamWeaver, Contribute, Flash, Fireworks, Freehand, Director, Authorware and HomeSite. Adobe bought Macromedia in 2005.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 17th, 2003, 06:28 AM
|
 |
PHP Member
|
|
Join Date: Jun 2002
Location: England
Posts: 163
Time spent in forums: 12 h 55 m 11 sec
Reputation Power: 11
|
|
|
Flash cordinates and pixels
I am trying to create a dynamic line graph, i'm wanting to put a pixel on a scene,
I wanting to do, something like this:
pseudeo code:
for(i=0;lengthof(array);i++)
{
putpixel(array(i)(x), array(i)(y))
}
i'm having trouble finding something to draw a pixel at x and y, from my 2 dimensional array;
any sugestions would be cool.
thanks
|

February 17th, 2003, 12:34 PM
|
|
flash junkie
|
|
Join Date: Jan 2003
Location: CO, USA
Posts: 172
Time spent in forums: 5 m 38 sec
Reputation Power: 11
|
|
sure, you'll need to use the Drawing API (and of course, use Actionscript syntax, not PHP  Everything is done with movieclips, so we'll need to create a new one:
this.createEmptyMovieClip("line_mc",1);
then(or first) we want to create our position arrays
x_pos = [1,50,120,150,400];
y_pos = [3,60,150,170,450];
we want to use the line_mc to draw lines (using the lineTo method):
with(line_mc){
lineStyle(1,0x000000,100);
for(i=0;i<x_pos.length;i++){
lineTo(x_pos[i],y_pos[i]);
}
}
and that's it! here's a look at all of the code:
PHP Code:
//actionscript:
this.createEmptyMovieClip ("line_mc", 1);
x_pos = [1, 50, 120, 150, 400];
y_pos = [3, 60, 150, 170, 450];
with (line_mc) {
lineStyle (1, 0x000000, 100);
for (i=0; i<x_pos.length; i++) {
lineTo (x_pos[i], y_pos[i]);
}
}
the lineStyle code takes three parameters -- line width, colour and alpha. the lineTo takes two parameters -- x and y.
mess around with it. if you know PHP it shouldn't seem too foreign.
cheers,
bret
|

February 17th, 2003, 03:23 PM
|
 |
PHP Member
|
|
Join Date: Jun 2002
Location: England
Posts: 163
Time spent in forums: 12 h 55 m 11 sec
Reputation Power: 11
|
|
Thanks dude!!
Will look at it tomoz at work.

|

February 20th, 2003, 10:41 AM
|
 |
PHP Member
|
|
Join Date: Jun 2002
Location: England
Posts: 163
Time spent in forums: 12 h 55 m 11 sec
Reputation Power: 11
|
|
Cool thats what i was looking for, this nect question is a little harder, with the data been displayed not been mission critical or anything, is there anyway of curving the line.
Say i have data like you provided, whihc is a line going diaganolly down to the left, with a hump, is there anyway of slightly making it more curvy, without chnaging the values ?
Thanks

|

February 20th, 2003, 11:24 AM
|
|
flash junkie
|
|
Join Date: Jan 2003
Location: CO, USA
Posts: 172
Time spent in forums: 5 m 38 sec
Reputation Power: 11
|
|
sure, you can use the curveTo method. it takes 4 arguments: controlx, controly, anchorx and anchory. The curveTo function emulates a 1 point bezier curve. This means that your control points will determine the amount of curve. here's an example of a simple curve from 0 to 100 pixels:
PHP Code:
//actionscript
this.createEmptyMovieClip("curve_mc",1);
curve_mc.lineStyle(1,0x000000,100);
curve_mc.curveTo(100,0,100,100);
you'll have to create another two arrays to hold the controlx and the controly values, but the implementation would still be the same... write back if you're still having problems.
cheers,
bret
|

February 21st, 2003, 06:23 AM
|
 |
PHP Member
|
|
Join Date: Jun 2002
Location: England
Posts: 163
Time spent in forums: 12 h 55 m 11 sec
Reputation Power: 11
|
|
550x400 Canvas:
The straight version looks ok, the curvy version looks emmmm, well weird lol, is there any way of just making the straight version bit more curvier or is there something i've missed on the curving.
Straight version:
PHP Code:
this.createEmptyMovieClip ("curve_mc", 1);
skewY = 400;
x_pos = [50, 100, 150, 200, 250, 300];
y_pos = [350, 60, 150, 170, 450,0];
with (curve_mc)
{
lineStyle (1, 0x000000, 100);
for (i=0; i<x_pos.length; i++)
{
curve_mc.lineTo(x_pos[i],skewY-y_pos[i]);
}
}
curvy version  :
PHP Code:
this.createEmptyMovieClip ("curve_mc", 1);
skewY = 400;
x_pos = [50, 100, 150, 200, 250, 300];
y_pos = [350, 60, 150, 170, 450,0];
with (curve_mc)
{
lineStyle (1, 0x000000, 100);
for (i=0; i<x_pos.length; i++)
{
curve_mc.curveTo(100,0,x_pos[i],skewY-y_pos[i]);
}
}
Thanks
|

February 21st, 2003, 11:13 AM
|
|
flash junkie
|
|
Join Date: Jan 2003
Location: CO, USA
Posts: 172
Time spent in forums: 5 m 38 sec
Reputation Power: 11
|
|
hey,
here's what i mean.. create two more arrays that house the x and y control:
PHP Code:
this.createEmptyMovieClip ("curve_mc", 1);
x_control = [25, 100, 125, 175, 225, 300];
y_control = [375,200,90,180,425,425];
x_pos = [50, 100, 150, 200, 250, 300];
y_pos = [350, 60, 150, 170, 450,0];
with (curve_mc)
{
lineStyle (1, 0x000000, 100);
for (i=0; i<x_pos.length; i++)
{
curveTo(x_control[i],y_control[i],x_pos[i],y_pos[i]);
}
}
mess with that and see if you can't get what you are looking for..
cheers,
bret
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|