Can flash draw a quartic??
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Can flash draw a quartic??

  1. #1
    Senior Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    135

    Can flash draw a quartic??

    Hello,

    I want to be able to draw quartic equations (aX^4 + bX^3 + cX^2 + X + u)with flash.

    I work for a climate change think tank and we want rebuild a planning model we have which charts future CO2 emissions scenarios.

    The key graphic we are generating, is a stack of 180 bell shaped curves modeled with a quartic equation for each country (an image is attached).

    Our current model is a 10MB excell file and I am hoping that with Flash MX it can be much smaller by using vectors.

    My initial trawling of the net tells me that the vectors in flash are all binomials.
    Do you have any ideas or know of code that could help in this quartic qest??.

    Many Thanks,

    Tim.
    Attached Images Attached Images
    For solutions to climate change visit www.gci.org.uk

  2. #2
    Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    63
    What your on about is way over my head but this link might help?
    :: Have Fun ::

    Nimmit

  3. #3
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469
    curveTo() creates a quadratic curve - but this doesn't stop you from building higher order curves or shapes from straight line segments? (It is possible to use quadratic segments - but probably not worth it).

    Have I missed the issue? It looks easy?

    10MB? For 180 sets of 4 parameters? Wow!
    AIR, ActionScript 3, Flex and Flash expert and freelance developer

  4. #4
    Senior Member
    Join Date
    Mar 2001
    Posts
    127
    Hello,
    I would say that flash would be too slow for this application. With any large number of vectors or indeed points the flash player/exe/projector would not cope and jam up i fear.
    cheers
    Hexagone

  5. #5
    Senior Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    135
    Thank you nimmit, brutfood and hexagone for responding to my post. I have been working to get up to speed understanding FLASH and your comments have been very helpful.

    Thanks nimmit for the link to Robert Penner http://gizma.socalleddesign.com/easing/

    I am interested in his code for a quartic quartic. I am asuming that this is being drawn with straight lines, as it ignores the curveTo function.
    ___________________________________________
    Math.easeInOutQuart = function (t, b, c, d) {
    t /= d/2;
    if (t < 1) return c/2*t*t*t*t + b;
    t -= 2;
    return -c/2 * (t*t*t*t - 2) + b;
    };
    ____________________________________________

    The other way of creating a quartic seems to be to aproximate it with a string of curveTo quadratic curves. http://www.timotheegroleau.com/Flash...r_in_flash.htm

    Hexagone, you pointed out that flash might sieze up if it has to crunch too many vectors. how many do you think is too many? I am wondering if I can side step the problem by performing them sequentialy and build up the image as a little animation.

    Do you think I would optimise processing by using flashes internal curveTo function to aproximate the curve or to ignore it and draw them from a fresh quartic equation a bit like Robert Penner?

    Cheers,
    Tim
    For solutions to climate change visit www.gci.org.uk

  6. #6
    Senior Member
    Join Date
    Mar 2000
    Posts
    472
    hey Tim H-L!

    I've been exploring this since you first posted, and I've come up with an example to show a possible set of results(although not close to your requested bell curve), with input to try different segment iterations, using 100 'lineTo' instructions per segment. I found very little difference in speed issues between creating a new line mc for every segment and redrawing segments into one line mc (which is just a little faster, so I've used it in the example).

    quarticEquation1.2 .swf .fla

    I'm on a rather slow machine (Athlon 550), but I suspect even faster machines will start to slow down after 80-100 iterations. The 180 segments you're requesting takes 11-12 seconds according to the onstage field, but actually takes about 37 seconds before rendering (at least on my machine), and functionality stalls after rendering that many segments. That doesn't even factor in the weight of your fills needed beneath each segment.

    Bottom line: you could probably attempt this with a maximum of 80-100 segments, but 180 won't fly.

    I would be interested to see a list of input expression:value pairs that you are using, and to know which expressions in the quartic that you wish to map? I can't seem to be able to render a bell curve, no matter which two expressions I solve for.

    Richard
    Last edited by Dickee; 01-17-2003 at 09:12 PM.

  7. #7
    Fearing Dawn
    Join Date
    Jul 2002
    Location
    yup.
    Posts
    50
    Dickee.. I ran your movie on my machine, i stopped upping the segments after i got to 260 rendered in 3.617 seconds on my (P4 2.4) and 180 segments rendered in 7.511 seconds on my (P3 750). I just thought you would like to hear how it was acting with a few different setups. Anyhow, good work.
    "And it is in his own image, let us remember, that Man creates God." ~~ H. Havelock Ellis

  8. #8
    ActionScript Insomniac
    Join Date
    Jan 2003
    Location
    43d03.21'N, 89d23.65'W
    Posts
    1,173

    Here's what you need

    Tim,

    I believe that the way to draw your bell curves is this: draw ONE bell curve (I export graphs from graphing software as EPS, import into Flash). Then produce each of your 180 bell curves by scaling and shifting this ONE bell curve, using _x, _xscale, _yscale.

    In general, you can produce any cubic from the graph of y = x^3 by using manipulations Flash provides. You can't get a general quartic (though you can get close with a combination of rotation and skew), but yours will be symmetric if they are approximating bell curves.

    (And if you're approximating a bell curve by a quartic, then you're working in a realm where that kind of precision doesn't matter.)

    If you want more details, I'll be happy to provide them. Just ask.

  9. #9
    Senior Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    135
    Hi Dickee,

    Thanks for quarticEquation1.2, I have been having a play with it.
    I am still very much at the novice stage in all this FLASH. I can start to see how the action script is put together and am now getting to grips with doing it myself.
    My current plan is to use a series of curveTo quadratics to aproximate each quartic path. Timothy Groleau has done some good work on this for cubics. I hope I can extend the code to work on quartics.
    Somewhere between 4 and 10 quadratics gives a "visibly exact" aproximation of a cubic. I asume similar figures for a quartic. On the other hand I expect that the processing of curveTo is more intensive than lineTo so I don't know if it would be slower overall or not.
    See the library file available from:
    http://www.timotheegroleau.com/Flash...r_in_flash.htm

    I am not quite sure what you mean by a "value pair". However here is an example of the kind of quartic I will need to produce.
    x values from 0 to 1. y=-23x^4+65x^3-57x^2+11x+7

    This is a projected curve of future carbon emissions. It would sit next to (follow on from) a grahph that plotted rising historic emissions.

    To Mkantor,
    Thank you for your suggetion. Unfortunately the quartic I want to draw is not a simple or symetrical bell shaped curve. I need the flexability that each of the quartics components provide, to design all sorts of possible curves, that are not just scaled versions of each other.

    I think my next step is to get to grips with Timothee Groleau's code and then try to expand it to make quartics.

    Cheers,
    Tim.
    For solutions to climate change visit www.gci.org.uk

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

Poll by Flashkit.com