Results 1 to 4 of 4
  1. #1
    smr
    smr is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Unhappy Java QuadCurve2D: How to make it draw slowly with delays..

    So basically im making a simulator, which preforms a projectile motion. And i want to make the quadcurve appear in slowmotion.
    Please here. Here is the code for QuadCurve2d

    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.draw(new QuadCurve2D.Float(curvefinalx, curvefinaly, curvemiddlex, curvemiddley, curveintialx, curveintialy));
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Java QuadCurve2D: How to make it draw slowly with delays..

    From the sound of it you want to draw parts of the curve.

    According to the API QuadCurve2D has some subdivide() methods. You could use this a number of times to obtain lots of smaller curves and then use a timer to render them progressively.

    Another approach - I don't know whether it is more or less contrived - would be to set the clip of the graphics g so that only part of the curve is rendered. Again use a timer, but this time make the clipped region progressively larger. On second thoughts I would try this second approach.

  3. #3
    smr
    smr is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Java QuadCurve2D: How to make it draw slowly with delays..

    I tried researching on subdividing, but sadly had no luck understanding the concept.
    Would it be possible for you to provide me with a piece of code, as an example?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Java QuadCurve2D: How to make it draw slowly with delays..

    Sorry, no code.

    The "concept", such as it is, is trivial: subdivision cuts the curve into 2 pieces. Do this seven times cutting every piece you have and you will end up with 128 pieces. Use a timer to draw progressively more pieces. If the timer's rate is 20ms then the curve will be fully drawn (ie all 128 pieces) after about 2s.

    As I said it might be more straightforward to animate the clipping region of the graphics. And more realistic: typically projectile motion does *not* reveal itself in time at a constant rate because the projectile slows down as it gains potential energy. If the animation calculated the projectile's position it could clip the region so that curve revealed itself as it might to an observer watching it in real time.

    Either way the concept to reckon with is animation. There are various examples here: Java 2D API Sample Programs
    and a simpler example that bring out the logic of animation here: create Animation in java

Similar Threads

  1. Java Bean calendar Applet closing slowly
    By l.najm@acteos.com in forum Java Applets
    Replies: 0
    Last Post: 10-24-2011, 04:31 PM
  2. [SOLVED] Form is loading slowly! :(
    By pranav13 in forum AWT / Swing
    Replies: 14
    Last Post: 10-20-2008, 12:51 PM
  3. How to draw Curve using QuadCurve2D
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:20 PM
  4. Delays by Play announcements
    By koni123 in forum Java Software
    Replies: 0
    Last Post: 01-08-2008, 09:51 AM
  5. Pauses (or delays rather....)
    By Windoze in forum New To Java
    Replies: 2
    Last Post: 11-17-2007, 09:44 AM

Tags for this Thread

Posting Permissions

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