Java Animation

Java Animation

In a for loop draw an object with moving x or y coordinates.
use the delay(time) function to animate.
use clearDrawing as well.
Here is an example. Imagine it is an alien coming toward you .

	void main()
	{
	setColor(red);
	for(int count = 0 ; count < 50; count++)
	{
		fillCircle(150, count*5, 50);
		delay(0.1);
		clearDrawing();
	}
	}

Try it without clearDrawing() by commenting out that line. e.g.

	//clearDrawing();

Notes on Above Java Code

  1. Set the color of the drawing object
  2. Do a loop for 50 times
  3. Draw a filled circle. The X coordinate (150 ) will stay constant, as it needs to only move down, not across. The Y co-ordinate will increase by 5 (count*5) each time the loop goes round(iterates).
    If count = 0 , then y = count * 5 = 0 * 5 = 0 , Add 1 to count
    if count = 1 , then y = count * 5 = 1 * 5 = 5 , add 1 to count
    if count = 2 , then y = count * 5 = 2 * 5 = 10 , add 1 to count
    So you can see that y increases by 5 every time the loop goes round, until count = 49. Then y will equal 49 * 5 = 245 .
  4. delay(0.1) – stops the program executing for a tenth of a second.
  5. clearDrawing() – clears the screen so you only see that frame being painted

Leave a Reply

Your email address will not be published. Required fields are marked *