A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: drawing lines in script

Hybrid View

  1. #1
    Junior Member
    Join Date
    Sep 2003
    Posts
    12

    drawing lines in script

    Hi I want to draw a line which represents the size of the x-velocity value in a movie of a projectile. I think it has something to do with the Drawing commands eg lineTo (x,Y).
    Basically how do I use the draw commands?

    Thanks
    dannym

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    if you are drawing on the root movie you first set the linestyle then moveTO for the starting point then lineTo to draw

    But I would use a pre drawn line paint object and scale it

    Draw a line as a paint obect the lentgh you want to see it when velocity is at it's greatest

    move the center point to the end you want it to grow from.

    Scale it to 1 in that direction (should be 0 but this causes problems on export)

    not as your velocity increases scale the element to match with scale of 100 equal to your highest velocity you will use.
    Last edited by blanius; 12-14-2003 at 09:55 AM.

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    example

    Heres an example



    Source

    Example here

  4. #4
    Junior Member
    Join Date
    Sep 2003
    Posts
    12

    drawing with script

    Thanks Blanius.... to the rescue again. This is a cool method.
    But could I possibly ask for a demo on how to draw a line in script.
    eg what do I put infront of .moveTo(x,y) etc

    Thanks for your time and help.

    Danny Mallon

  5. #5
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    There is the paint example that I did and the guys at 3dfa modified. look in the sample folder


    put this code in a starting script of a movie and see what it does
    PHP Code:
    //set up some colors to use
    blue=rgb(0,0,255);
    red=rgb(255,0,0);
    yellow=rgb(255,255,0);

    //lets start with blue line 8 pixels wide
    root.lineStyle (8,blue,100)

    //to draw on the movie's canvas starting at 10,10
    root.moveTo(10,10)

    //then draw
    root.lineTo(10,100);

    //lets draw a curved line
    root.curveTo(50,50,100,100);

    root.lineStyle (8,red,100);
    //after changing style you have to reset position
    root.moveTo(100,100);

    root.lineTo(100,10);

    root.lineStyle (8,yellow,100);
    root.moveTo(100,10);

    root.lineTo(10,10);

    //now look at filling an area

    root.lineStyle(4,blue,80);//for fun
    root.beginFill (red,100);
    root.moveTo (200,200);//box
    root.lineTo (200,300);
    root.lineTo (300,300);
    root.lineTo (300,200);
    root.lineTo (200,200);
    root.endFill() 

    you can use these commands on a layer as well but the x,y coords will be based on the center of the layer for some reason so you first should move the center of the layer to the upper left corner

  6. #6
    Junior Member
    Join Date
    Sep 2003
    Posts
    12
    What a guy!
    Super cool!
    You`ve made this physics teacher so much happy.
    Dannym

  7. #7
    Member
    Join Date
    Aug 2003
    Posts
    30
    Is there a way to change the line style dynamically? I'd like to be able to create a dashed line on the fly... is that even possible? I've searched and can't seem to find anything.

    Thanks!

  8. #8
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    No not that I know of, but you could do it with some math by calculating the line and then drawing little lines to the end of each side of the box, Yeah make a function that takes the top left and bottom right coordinates and just draw it with lots of little lines, or even use cloned dots or something.

    Should be very doable that way.

  9. #9
    Member
    Join Date
    Aug 2003
    Posts
    30
    Thanks, I guess I've gotta do what I've gotta do...

    I found this code from another post, I'm going to try it now.

    code:

    this.lineStyle(2);
    for (var i = 0; i <= 8; i++) {
    if (i % 2 == 0) {
    var x = 10 * i;
    this.moveTo(x, 100);
    this.lineTo(x + 10, 100);
    }
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center