Difference between revisions of "Animation"

From Progzoo
Jump to: navigation, search
(Moving block)
Line 36: Line 36:
 
  classpath="classes.jar">
 
  classpath="classes.jar">
 
<prog>
 
<prog>
static void drawFrame(Graphics g, int frame){
+
static void drawFrame(Graphics2D g, int frame){
 +
  g.setColor(Color.red);
 +
  g.fillRect(0,0,300,200);
 
   g.setColor(Color.yellow);
 
   g.setColor(Color.yellow);
   g.fillOval(22+2*frame,22,4+frame*2,4+frame*2);
+
   g.fillRect(50,10*frame,100,20);
 
}
 
}
 +
 +
</prog>
 +
</question>
 +
==Shooting Star==
 +
<question copyFile="classes.jar" imgOut='anim.gif'
 +
frames='10' width='150' height='100' className="Anim"
 +
classpath="classes.jar">
 +
<prog>
 +
static void drawFrame(Graphics2D g, int frame){
 +
  int r = 20;
 +
  Polygon star = new Polygon(
 +
  new int[]{0,22,95,36,59,0,-59,-36,-95,-22},
 +
  new int[]{-100,-31,-31,12,81,38,81,12,-31,-31},10);
 +
  g.setColor(Color.red);
 +
  g.fillRect(0,0,300,200);
 +
  g.setColor(Color.yellow);
 +
  g.translate(10*frame,10*frame);
 +
  g.scale(r/100.0,r/100.0);
 +
  g.fillPolygon(star);
 +
  g.scale(100.0/r,100.0/r);
 +
  g.translate(-frame*10,-frame*10);
 +
}
 +
 
</prog>
 
</prog>
 
</question>
 
</question>

Revision as of 00:30, 21 November 2008

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

Moving block


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

Shooting Star


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