Results 1 to 4 of 4
- 01-17-2012, 07:13 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
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));
}
- 01-17-2012, 08:39 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
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.
- 01-17-2012, 09:30 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
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?
- 01-17-2012, 11:32 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
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
-
Java Bean calendar Applet closing slowly
By l.najm@acteos.com in forum Java AppletsReplies: 0Last Post: 10-24-2011, 05:31 PM -
[SOLVED] Form is loading slowly! :(
By pranav13 in forum AWT / SwingReplies: 14Last Post: 10-20-2008, 01:51 PM -
How to draw Curve using QuadCurve2D
By Java Tip in forum java.awtReplies: 0Last Post: 06-24-2008, 12:20 AM -
Delays by Play announcements
By koni123 in forum Java SoftwareReplies: 0Last Post: 01-08-2008, 10:51 AM -
Pauses (or delays rather....)
By Windoze in forum New To JavaReplies: 2Last Post: 11-17-2007, 10:44 AM
Bookmarks