Difference between revisions of "Animation"

From Progzoo
Jump to: navigation, search
(Rotating Star)
(Rotating Star)
Line 97: Line 97:
 
     RenderingHints.VALUE_ANTIALIAS_ON);
 
     RenderingHints.VALUE_ANTIALIAS_ON);
 
   g.fillPolygon(star);
 
   g.fillPolygon(star);
 +
}
 +
</prog>
 +
</question>
 +
 +
==Arrange Shapes in a Circle==
 +
<question copyFile="classes.jar" imgOut='anim.gif'
 +
width='150' height='100' className="Anim"
 +
classpath="classes.jar">
 +
We will print 20 stars.
 +
 +
Each of them will be yellow - except one.
 +
 +
<prog>
 +
static void drawFrame(Graphics2D g, int frame){
 +
  int r = 20;
 +
  g.setColor(Color.white);
 +
  g.fillRect(0,0,300,200);
 +
  for(int i=0;i<20;i++){
 +
    if (i==frame)
 +
      g.setColor(Color.red);
 +
    else
 +
      g.setColor(Color.yellow);
 +
    g.fillRect(150*i/20,0,150/20,100);
 +
    g.setColor(color.black);
 +
    g.drawRect(150*i/20,0,150/20,100);
 +
    g.translate(150/20,0);
 +
  }
 
}
 
}
 
</prog>
 
</prog>
 
</question>
 
</question>

Revision as of 13:04, 1 December 2015

The animations here rely on Gif89Encoder available from http://jmge.net/java/gifenc/ developed by JMG Elliot.

Moving block

You can click on "Show" to see the full program.

The method drawFrame is called 20 times; frame is a different value each time, the graphics object is new each time. Draws a yellow rectangle at coordinates (50,8*frame-20) which is (50,-20), (50,-12), (50,-2), (50,6) ... (50,172) So the yellow box appears at the top of the image and moves down a little with each frame.


[Font] [Default] [Show] [Resize] [History] [Profile]

Shooting Star

In this example both the x and the y coordinates change at each frame and so the star moves diagonally.


[Font] [Default] [Show] [Resize] [History] [Profile]

Rotating Star


[Font] [Default] [Show] [Resize] [History] [Profile]

Arrange Shapes in a Circle

Line: 123 DOMDocument::loadXML(): StartTag: invalid element name in Entity, line: 11