A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Particles as vector textures?

  1. #1
    Senior Member evolbeagle's Avatar
    Join Date
    Oct 2000
    Location
    Nashville, TN
    Posts
    355

    Particles as vector textures?

    Has anybody experimented with using particles to add texture to vector drawings in KM? I was thinking about that as a possble approach and thought I'd ask before trying to reinvent the wheel.

    Say, for instance, you had a vector shape that represented a dirt road. It occurred to me that if you could write a script that would scatter a bunch of particles across that shape, you might be able to give it a suitable grainy texture without having to draw a bunch of extra shapes. The particles would be static once created, but would vary somewhat in terms of things like alpha, scale, rotation - the standard stuff. Has anybody already tried anything like this? If so, does it work? I did some searching on this idea but came up basically empty - maybe I'm not using the right search terms.

    Anyway, any input would be appreciated.

    Thanks,

    Matt

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    It's an interesting idea. Let us know what you find out.

  3. #3
    Senior Member evolbeagle's Avatar
    Join Date
    Oct 2000
    Location
    Nashville, TN
    Posts
    355
    Well, I experimented with the idea a bit tonight. You can see one example here. The linked example uses two vector particles (no bitmaps) and diminishes the _yscale as you go up the rectangle in an attempt to give it a sort of perspective look.

    Assuming it's not too CPU-intensive, this general idea seems promising if you could figure out how to clip the resulting texture to an irregular shape.

    Matt

  4. #4
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    It's better to create a bitmap object and draw onto that object.
    If you duplicate a lot of movieclips cpu load gets high. Drawing onto a bitmap can be done as often as you want since there's not a lot of movieclips that have to be kept in memory.

    Here's an example
    Code:
    createEmptyMovieClip('src_obj', 0);
    src_obj._visible = false;
    src_obj.beginFill(0xffff00);
    src_obj.lineStyle(5, 0xff00ff);
    src_obj.moveTo(20, 20);
    src_obj.lineTo(40, 40);
    src_obj.lineTo(20, 40);
    src_obj.lineTo(20, 20);
    dst_obj.endFill();
    
    bmp_fill = new flash.display.BitmapData(200,100,true,0);
    onEnterFrame = function(){
     for (i=0; i<20; i++){
      mat = new flash.geom.Matrix(Math.random(),0,0,Math.random(),Math.random()*200,Math.random()*100);
      col = new flash.geom.ColorTransform(1, 1, 1, Math.random(), 0, 0, 0, 0);
      bmp_fill.draw(src_obj, mat, col);
     }
    }
    onEnterFrame();
    
    createEmptyMovieClip('dst_obj', 1);
    dst_obj.beginBitmapFill(bmp_fill);
    dst_obj.lineStyle(1, 0x0000ff);
    dst_obj.moveTo(10, 10);
    dst_obj.curveTo(140, 0, 190, 10);
    dst_obj.curveTo(20, 40, 190, 90);
    dst_obj.lineTo(10, 10);
    dst_obj.endFill();
    Make sure to export as flash 8.

  5. #5
    Senior Member evolbeagle's Avatar
    Join Date
    Oct 2000
    Location
    Nashville, TN
    Posts
    355
    Thanks for the tip! I'll play around with that approach and see what I can do with it.

    Matt

  6. #6
    Junior Member
    Join Date
    Apr 2007
    Posts
    9
    Your link states your having problems clipping the texture. I'm assuming your code is in the main frame. Try putting your code in the 1st frame of an MC. Then masking over the top of the MC. You could also try noise or perlin noise, used with alpha or blend modes, for creating textures.

  7. #7
    Junior Member
    Join Date
    Apr 2007
    Posts
    9

    Perlin Shape Painter

    This is about as a simple as I could make it.
    Play around with the parameters for endless texture effects.
    Attached Files Attached Files

  8. #8
    Junior Member
    Join Date
    Apr 2007
    Posts
    9

    Noise Shape Painter

    Same as above, but for random noise.
    Attached Files Attached Files

  9. #9
    Senior Member evolbeagle's Avatar
    Join Date
    Oct 2000
    Location
    Nashville, TN
    Posts
    355
    Thanks, Mysteron! I'll play around with those and see what I can learn.

    Matt

  10. #10
    Junior Member
    Join Date
    Apr 2007
    Posts
    9
    If you think they worthy. I will post them in the exchange, Along with a more artistic example. If your work involves alot of vector shapes it's sometimes worth saving as bitmap, then importing back in.

  11. #11
    Senior Member evolbeagle's Avatar
    Join Date
    Oct 2000
    Location
    Nashville, TN
    Posts
    355
    Quote Originally Posted by Mysteron
    If your work involves alot of vector shapes it's sometimes worth saving as bitmap, then importing back in.
    True, of course, but then you give up scalability without pixelation. The problem here the the old "can't maximize for all the variables" rub: if you're avoiding the Flash cartoony look (as I'm trying to do), it's difficult to make a flash movie that's great for both the web and dvd output. For now, I'll probably just optimize the movies I'm making for the web and forget about the possibility of putting them on dvd unless and until that becomes a real and viable thing to do. Then I'll solve whatever issues I have in converting at that time.

    While I'm on this, though, I did stumble across a cartoon on Cartoon Network that seems to use this noise-based approach for its texturing. The cartoon was called Ben 10 and I thought the approach was only somewhat effective - partly because it was overused in this particular instance.

    Matt

  12. #12
    Junior Member
    Join Date
    Apr 2007
    Posts
    9
    If scalability is the issue. You could adapt the perlin_mc's script to work at run time. But it's not a good idea due to CPU overhead. But you may be able to adapt this for your purposes. It uses the start big scale down approach. But doesn't suffer from pixelation and bandwidth problems associated with bitmaps. It's the best I could come up with. I've removed the mask for clartity. Code is in the main frame and the 1st frame of the perlin_mc. The perlin_mc is not visible because its empty(aside script). But you will find it in the top left corner(0,0).
    Attached Files Attached Files

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