#1
  1. PHP Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    England
    Posts
    163
    Rep Power
    12

    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
  2. #2
  3. No Profile Picture
    flash junkie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    CO, USA
    Posts
    172
    Rep Power
    12
    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 = [150120150400];
    y_pos = [360150170450];
    with (line_mc) {
        
    lineStyle (10x000000100);
        for (
    i=0i<x_pos.lengthi++) {
            
    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
  4. #3
  5. PHP Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    England
    Posts
    163
    Rep Power
    12
    Thanks dude!!

    Will look at it tomoz at work.

  6. #4
  7. PHP Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    England
    Posts
    163
    Rep Power
    12
    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

  8. #5
  9. No Profile Picture
    flash junkie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    CO, USA
    Posts
    172
    Rep Power
    12
    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
  10. #6
  11. PHP Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    England
    Posts
    163
    Rep Power
    12
    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 = [50100150200250300];
    y_pos = [35060150170450,0];

    with (curve_mc
    {
        
    lineStyle (10x000000100);
        for (
    i=0i<x_pos.lengthi++) 
        {
            
    curve_mc.lineTo(x_pos[i],skewY-y_pos[i]);
        }


    curvy version :

    PHP Code:
    this.createEmptyMovieClip ("curve_mc"1);
    skewY 400;
    x_pos = [50100150200250300];
    y_pos = [35060150170450,0];

    with (curve_mc
    {
        
    lineStyle (10x000000100);
        for (
    i=0i<x_pos.lengthi++) 
        {
            
    curve_mc.curveTo(100,0,x_pos[i],skewY-y_pos[i]);
        }

    Thanks
  12. #7
  13. No Profile Picture
    flash junkie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    CO, USA
    Posts
    172
    Rep Power
    12
    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 = [25100125175225300];
    y_control = [375,200,90,180,425,425];
    x_pos = [50100150200250300];
    y_pos = [35060150170450,0];

    with (curve_mc
    {
        
    lineStyle (10x000000100);
        for (
    i=0i<x_pos.lengthi++) 
        {
            
    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

IMN logo majestic logo threadwatch logo seochat tools logo