Difference between revisions of "Animation"

From Progzoo
Jump to: navigation, search
Line 4: Line 4:
 
import java.io.File;
 
import java.io.File;
 
import javax.imageio.ImageIO;
 
import javax.imageio.ImageIO;
public class Raster{
+
import net.jmge.gif.Gif89Encoder;
 +
 
 +
public class Anim{
  
 
QcQ
 
QcQ
  
 
   public static void main(String argv []){
 
   public static void main(String argv []){
     for (int i=0;i<10;i++){
+
     BufferedImage image = new BufferedImage(150,100, BufferedImage.TYPE_INT_ARGB);
      BufferedImage image = new BufferedImage(150,100, BufferedImage.TYPE_INT_ARGB);
+
    Graphics2D g = image.createGraphics();
      Graphics2D g = image.createGraphics();
+
    try {
      drawFrame(g,i);
+
        Gif89Encoder genc = new Gif89Encoder();
      g.dispose();
+
        for (int i=0;i<4;i++){
      try {
+
          drawFlag(g,i);
         File out = new File("flag"+i+".png");
+
          genc.addFrame(image);
         ImageIO.write(image, "png", out);
+
        }
      }catch(Exception e){
+
          
      System.err.println(e);
+
        genc.setUniformDelay(10);
      }
+
        genc.setLoopCount(0);
 +
        FileOutputStream out = new FileOutputStream("flaganim.gif");
 +
         genc.encode(out);
 +
    }catch(Exception e){
 +
    System.err.println(e);
 
     }
 
     }
 +
    g.dispose();
 
   }
 
   }
 
}
 
}
 
</shell>
 
</shell>
 
==Moving block==
 
==Moving block==
<question imgOut='flag.png' width='150' height='100' className="Raster">
+
<question copyFile="classes.jar" imgOut='flag.png' width='150' height='100' className="Anim">
 
<prog>
 
<prog>
static void drawFrame(Graphics g,int i){
+
static void drawFlag(Graphics g, int frame){
   g.setColor(Color.black);
+
   g.setColor(new Color(0,32*frame,0));
   g.fillRect(20*i,20*i,50,50);
+
   g.fillRect(0,0,150,100);
 +
  g.setColor(Color.yellow);
 +
  g.fillOval(22+2*frame,22,4+frame*2,4+frame*2);
 
}
 
}
 
</prog>
 
</prog>
 
</question>
 
</question>

Revision as of 15:47, 14 November 2008

Moving block


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