How to synchronize animation with time?

I want to synchronize animation with time, but I can't determine the current time, because the return value of the System.currentTimeMillis() method is updated only every 10 milliseconds.
The following example demonstrates it:
import java.applet.Applet;
import java.awt.Graphics;
class TimeStep extends Applet
  long minimalStep=1000L;
  long lastTime=System.currentTimeMillis();
  public void paint(Graphics g)
    g.drawString("Minimal timestep: "+minimalStep,5,30);
    for (int i=25;i-->0;)
      while (true)
         long newTime=System.currentTimeMillis();
         long step=newTime-lastTime;
         if (step>0L)
             if (step<minimalStep)
                minimalStep=step;
             lastTime=newTime;
             break;
    repaint();
}It causes flickers by most framerates:
import java.applet.Applet;
import java.awt.Graphics;
class SynchronizedAnimation extends Applet
  static final int FRAME_RATE=90;     // 100 works, 90 flickers
  static final int STEP=5;
  static final int WIDTH=640;
  static final int HEIGHT=20;
  static final long FRAME_TIME=1000L/FRAME_RATE;
  int lastPosition,newPosition;
  long lastTime=System.currentTimeMillis();
  public void paint(Graphics g)
    long waitedTime=lastTime+FRAME_TIME;
    while (waitedTime-System.currentTimeMillis()>0L);
    lastTime=waitedTime;
    newPosition=(lastPosition+STEP)%WIDTH;
    g.drawLine(newPosition,0,newPosition,HEIGHT);
    if (lastPosition!=newPosition)
        g.setColor(getBackground());
        g.drawLine(lastPosition,0,lastPosition,HEIGHT);
        lastPosition=newPosition;
    repaint(0L);
  public void update(Graphics g)
    paint(g);

On windows 9x its even worse. The timer is only updated every 50/60 milliseconds.
Instead you could do something like keep the time when the animation starts, and then everytime you want to paint, check how much time has gone since then and calculate where the animation has gone to at this point.
Even if you can only update every 50 ms, it gives you 20 frames. I don't think its that bad.

Similar Messages

  • How to synchronize the FieldPoint time with my computer time?

    When I using MAX to read the values from my FieldPoint cFP-1804 module, there is and timestamp generated for every measurement, but it does not match my PC's system time. How to synchronize the FieldPoint time with my windows PC?
    I found a thread on the forum regarding this problem (http://digital.ni.com/public.nsf/allkb/C4E56AD6450FC5FD86256DFF0007FF01), it ask me to select the Time Zone on the System Setting tab, but I didn't find any System Setting tab and Time Zone setting in my MAX screen. (MAX version4.4)
    I'm using the cFP-1804 without embedded CPU module, I'm using asp.net, measurement studio to link with the cFP-1804, not by using Labview. Does cFP-1804 have a Time Server function? Please tell me how to match the FieldPoint time with my PC. 
    Thanks

    Hi Presario2100,
    In order to obtain an updated timestamp with each FieldPoint Read, you should
    use a Flat Sequence structure.  In the same frame as the
    FieldPoint Read, use a Get Date/Time In
    Seconds node.
    The program obtains a fresh Timestamp each time the FieldPoint Read VI is
    called.
    I hope this helps.
    Message Edited by Pie56694 on 08-15-2008 05:58 PM
    Attachments:
    TSUpdates.jpg ‏38 KB
    FlatSequence.jpg ‏54 KB

  • TS3423 Mac book pro stops responding after Maverick OS restart. Currently have a circle with a line through it after 20+ hours. Tried to shut it down and use the Time Machine to restore but no response. How can I restore with Time Machine if it will not s

    Mac book pro stops responding after Maverick OS restart. Currently have a circle with a line through it after 20+ hours. Tried to shut it down and use the Time Machine to restore but no response. How can I restore with Time Machine if it will not start?

    sonjadg,
    you can purchase a replacement pair of grey installation DVDs for your MacBook Pro from either Apple or iFixit. If Startup Manager is only showing an OS X Installer volume, then it sounds like the Mavericks installer had a problem midway through its installation process. To fix this, you’re going to need to erase your internal disk and reïnstall your original version of OS X from the grey Mac OS X Install DVD, use Software Update  to get it back to 10.6.8 (presuming that your MacBook Pro originally came with Snow Leopard), and then restore from Time Machine.

  • How to control animation with touch

    Hello! I need some help with controlling animations with touch. I am building a fake app and need to 'unlock' an iphone (slide an arrow along a track and then have it fade into another page). I have been using http://forums.adobe.com/message/4865693 that thread. The prototype link listed there is similar to waht I need to recreate, but I think I need an 'on touch' actino instead of a mousemove one.
    http://assets.ordienetworks.com.s3.amazonaws.com/the_occasional/checkerPro/checkerPro.html
    That is a link to the Edge file I have been working on, using the info in the thread above. It is broken at the moment, and I am terrible with javascript and have no idea how to move forward. I have figured that I'll need an 'on touch' action instead of the mouseover one, but I'm not sure how to build it.
    If there is a working example of this on a different thread that I've missed I'd love a link as well!!
    Thank you!!

    Hi, akall-
    There are a number of touch events that you can use to accomplish what you want.  You can try using the touchmove event instead of the mousemove event, and stick your code in there.
    Hope that helps,
    -Elaine

  • My Ical events disappeared how do I restore with time machine/mountain lion?

    I recently installed mountain lion.    Today my ICal events disappeared and I can't restore them with time machine.   What happened?   How do I fix it?

    Did you try rebuilding the library's database file as follows:  make a temporary, backup copy of your library if you don't already have one (Control-click on the library and select Duplicate from the contextual menu) and  apply the two fixes below in order as needed:
    Fix #1
    Launch iPhoto with the Command+Option keys held down and rebuild the library.
    Since only one option can be run at a time start with Option #3, followed by #4 and then #1 as needed.
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    1 - download iPhoto Library Manager and launch.
    2 - click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    3 - Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option.
    4 - In the next  window name the new library and select the location you want it to be placed.
    5 - Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments.  However, books, calendars, cards and slideshows will be lost. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.

  • How to filter date with time

    Hi, with ADF 11.2.0 , i'm having a date column in the table which displays the date and time in the format of "yyyy-MM-dd hh:mm:ss.FF ". But the filter allows me to give only the date and i'm expecting to filter the records at least based the on the given date. But it's not working so. The reason i got in this forum is ,
    "The typical af:table setup has it such that the filter for a date column allows you to specify dates, but not times. When the filter queries against the database, *it defaults the date's time component to midnight*. As such only records that match the date at midnight will be returned."
    Based on the above statement , i guess no way for my scenario to filter the records based on date. Is there any way to filter data with time stamp. Thanks .

    What if you define a transient attribute in your VO that basically uses Trunc(dateField) as its value?
    Then show this attribute in the table for filtering.

  • How to synchronize the system time/date of a PXI controller with a GPS or time server?

    Using a PXI system with a NI-PXI 8196 controller and LabVIEW RTOS, I am  searching for a solution to set or reset the on board timeclock of the controller trough a external signal like a GPS or a time server (ntp).
    Do an easy way exist to do this?
    Any response will be greatly appreciated.
    Philippe D.

    Hello Philippe,
    combining those examples should resolve your request:
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=DB0882E37369122DE034080020E74861&p_...
    and
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=EE349DC00D8D5E08E0340003BA7CCD71&p_...
    or
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3E23356A4E034080020E74861&p_...
    Hope this helps,
    Regards Thomas Bl.

  • How to synchronize iPad with Apple TV

    Just got the Apple TV, can you synchronize the iPad with the Apple TV in order to stream the music and movies from the iPad to the TV?  Thanks for your help.

    Hi Audiotinker,
    Welcome to the Support Communities!
    The links below will show you how to setup your Apple TV using your iPad (with the iOS 7 software),
    Apple TV (3rd generation): Using an iOS device to set up your Apple TV
    http://support.apple.com/kb/HT5900
    And how to use Airplay to share the information on your iPad with the Apple TV:
    Apple TV - AirPlay - Play content from iOS devices on Apple TV.
    iOS: Using AirPlay
    http://support.apple.com/kb/HT4437
    iOS: How to use AirPlay Mirroring
    http://support.apple.com/kb/ht5209
    Cheers,
    - Judy

  • How to synchronize itunes with the hard-drive's directories ?

    Hi everyone,
    I'm new at iTunes and iPod.
    I'm used to put all my mp3 files in the same folder. I add every weeks some new mp3 files.
    How to tell to iTunes to synchronize and get the new files in the music folder ?
    In the same way, i try to refresh the ide3 tags from my mp3 files.
    I use Tag&Rename software. But it seems that itunes doesn't xant to see the ide3 tags modifications ?
    How to tell him to refresh in its own library the newly updated tags ?
    thx for your answers

    I got the same problem. The only thing which worked for me was moving with my files too, onto the harddisk.
    Start/MyDocuments/rightklick on it/ change the location to your external HD and hit enter.

  • Adobe Acrobat 9 Pro- How to password protect with time expiration

    Does anyone know how to set a password for a .pdf file that will expire after a certain length of time. Thanks for your help.
    Roy

    Not possible with Acrobat alone, but with a DRM system on your PDF (License Server etc.) you can expire documents as and when you like.

  • How to synchroniz​e with RTSI?

    Hi all 
    I am working with  2 PCIe card (#6351 and #6536) connected via RTSI. The bus RTSI permit to solve 2 critical problems in my application: simultaneous triggering and synchronization
    For the synchronization, I would like to generate a rectangular signal with a fixed low level (5 microseconds) and a high level that I can tune with the card 6351 on the RTSI line 0
    For the simultaneous triggering, RTSI line 1 is at 0 (low level) by default. The acquisition and the emission of the synchronization signal is triggered on a rising edge.
    Here is the chronogram of the signals RTSI lines 0 and 1:
    a) acquisition starts
    b) 5 microseconds
    c) measuring something
    d) refreshing all the digital outputs
    e) end 
    Could you help me with the vi because I really do not know how to proceed 
    Thanks by advance
    Attachments:
    Coupled_RTSI.pdf ‏145 KB

    I've programmed a bit of FPGA, but not to the point where I'd call myself an expert with it.  I understand everything going on in the attached FPGA vi and our primary FPGA vi (not attached).
    I was hoping to implement it into the host because the desired frequency of the pulse from the daqmx counter has already been implemented in a much larger application, and it is actually a control on the front panel.  Changing the location of the source would require rewriting a lot of code.  65536 Hz will be the fastest possible frequency so I went ahead and wired the worst case scenario into the attached vi.  Also the desired frequency is approximately 65 kHz, not MHz.
    I'd simply like to find a way to use the 65536 Hz pulse from /Dev1/Ctr0InternalOutput to run the FPGA subvi at every rising edge of the pulse if possible.
    Thanks for your help!

  • How to play Animation with site loading in background to reveal website?

    So I know there are pre loaders and you can make that with edge... But they are so small and just a little circle moving around or something... I more mean a full page pre-loader then I guess...
    I have created an animation of a M with marquee lights going around and slowly zooming in... Then I have the M fade out and I have a black solid layer move up and another black solid layer move down to reveal the blank stage below...
    What I want to happen is maybe with some java script but to have the solids move out of the way to reveal my site bellow... Anyone know how to accomplish this?
    Thanks so much! I think being able to do things like this in native html and css and java will be huge for giving websites a "Font Door" or Opening Title like we have in movies... Thanks so much!

    first I recommend that you use mouseenter and mouseleave instead.
    second: if you have a symbol that has let's say one animation you can do
    on mouse enter
    sym.getSymbol('symbolname').play();
    on mouseleave:
    sym.getSymbol('symbolname').playReverse();
    you may have to add
    sym.getComposition().getStage().getSymbol('symbolname').play();
    sym.getComposition().getStage().getSymbol('symbolname').playReverse();
    or you can put the event in stage/compositionreday
    sym.getSymbol('symbolname').mouseenter(function(){
    sym.getSymbol('symbolname').play();
    sym.getSymbol('symbolname').mouseleave(function(){
    sym.getSymbol('symbolname').play();

  • How to do^ working with time dim and contracts dim/fact

    how to set physical and Bmm layers
    thera are Contracts entity with two dates: begin_date and end_date
    and Time entity with hierarchy YEAR to DAY and also two atributes FIRSTDAY_OF_YEAR and LASTDAY_OF_YEAR at detail level
    how to set physical and Bmm layers to get report like:
    Get all contracts for which the begin_date and end_date intersect with the interval of FIRSTDAY_OF_YEAR to LASTDAY_OF_YEAR.
    YEAR are set by prompt

    I want to show 10 rows of data in a one page and
    remain in other pages. How to do ithttp://onesearch.sun.com/search/onesearch/index.jsp?qt=jsp+pagination&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums
    Make sure you calculate the pagination before you invoke the JSP.

  • How to load date with time zone using sql loader???

    Hi All,
    How to load following value in the table using SQL loader.
    [11/Jan/2006:15:20:14 -0800]
    What should be the datatype of the column in the table. I have tried with "timestamp with local time zone", but unable to load the record using sql loader. What should be the format string in the loader control file to load this type of record.
    Any help in this regard is highly appreciated.
    Sameer

    Try something like this in your control file:
    mycol char "TO_TIMESTAMP_TZ(mycol, 'DD/MON/YYYY:HH24:MI:SS TZH:TZM')"
    [pre]
    Message was edited by:
            Jens Petersen                                                                                                                                                                                                                                                                                                                                                                       

  • How to restore ical with time machine

    I have (some how) lost all of my appointments in my "Work Calendar" within iCal except for one entry (which is strangs).
    I have been trying to restore from Time Machine, but, the user interface for iCal through Time Machine is "not easy" to figure out or to use.
    I am unable to open the iCal folder as I can do with other ones to restore the data.
    How can I do this - I have never been able to do this restore in iCal & Contacts.
    Please can any one help me?

    Frank Lowney1 wrote:
    Another factor that may be relevant is that I seen iCal appear and disappear from the MobileMe list of things to synch.  It's out of view 99% of the time.
    If you are talking about something you see in System Preferences>MobileMe then it's not relevant - iCal does not in fact sync, it reads the calendars directly from the server (though there is by default a cached local copy) and as I said the settings in that prefs pane are nothing to do with iCal any more.
    iCal is controlled in System Preferences>Mail, Contacts& Calendars and you should check that your MobileMe login details are correctly entered there - please see http://support.apple.com/kb/HT4758
    As to the process I detailed, in the first set of numbered instructions, please make sure that when you have exported your MobileMe calendars you import them back into a calendar listed under 'On My Mac' - these cannot be deleted by MobileMe and from your description it sounds as if you may not have done this. Given your problems, I would suggest choosing new name sfor the calendars, at least temporarily.
    Then when you reconnect to the internet it should not be possible for MobileMe to delete the calendars and you can proceed with the next steps.

Maybe you are looking for

  • Problem with flash contents in Firefox

    I never have this problem with earlier version of Flash 9 for Firefox until the recent version upgrade. The videos always stopped at about 3 seconds and no sound can be heard. IE works fine though... Is there a fix or work aorund for this issue?...

  • IBooks Author table of contents does recognize paragraph styles

    The video https://www.youtube.com/watch?v=n2p08-NmqfQ shows that using iBooks Author  I should be able to have text that is formatted with specific Paragraph Styles show automatically in the Table of Contents. But for me that does not work.  My versi

  • ClasscastException while displaying image from content selector

    Hi, My requirement is show an image gif file in jsp, through portal. This problem is specific to 8.1 version. Created an image type content in BEA repository which i could retrieve from workshop content preview correctly, with a rule (named filerule)

  • Array in pl/sql block

    hi all, I would like to know whether there is any array function in pl/sql when it comes to 8.0.5.1.0 workgroup/enterprise edition. Also can we split a string (rcvd as in param) into array of values (any in-built function) best regards, --meghanad   

  • MixRadio not working in Sonos

    I signed up for premium MixRadio service a couple of months ago.  Using Sonos's beta MixRadio service was working fine. Then it it just stopped working.  Recently some of the playlist work, some don't, some start working then stop.  The "Play Me" fun