Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In processing load at least 5 images and compose a nice scene. It is Java based.

ID: 3759657 • Letter: I

Question

In processing load at least 5 images and compose a nice scene. It is Java based. We were using processing.org in class.

Example: you could use a beach background image, a cloud image, a boat image, a surfer image etc. and show in every frame the background and animate the cloud to move to the right, and the boat to move to the left, and the surfer to move to the right maybe faster than the boat.

Example 2: you could use a country scene background and have a bird fly to the left, an airplane fly to the right, a car move in the road to the left etc.

REQUIREMENTS:

Use at least 5 images.

The size of each image should be no higher than 800x800.

The size of the window should be no more than 1200x800 (in the class I use 800x600).

At least 3 images should move in different directions/speed (for example: -1, +1, +3)

Looking for the code for the pde file.

Explanation / Answer

    import java.awt.Graphics;
       import java.awt.Image;
       import java.awt.Color;
    
       public class Pics extends java.applet.Applet
           implements Runnable
           {
   
        Image nekopics[] = new Image[9];
           Image currentimg;
           Thread runner;
           int xpos;
           int ypos = 50;
   
           public void init() {
                   String nekosrc[] = { "text1.gif", "text2.gif",
                  "text3.gif", "text4.gif", "text4.gif",
                   "text5.gif" };
   
              for (int i=0; i < nekopics.length; i++) {
                   nekopics[i] = getImage(getCodeBase(),
                   "images/" + nekosrc[i]);
               }
          }
           public void start() {
              if (runner == null) {
                   runner = new Thread(this);
                   runner.start();
               }
           }
   
           public void stop() {
               if (runner != null) {
                   runner.stop();
                   runner = null;
               }
          }
   
           public void run() {
               setBackground(Color.white);
   
              // run from one side of the screen to the middle
               nekorun(0, size().width / 2);
  
               // stop and pause
               currentimg = nekopics[2];
              repaint();
              pause(1000);
   
              // yawn
               currentimg = nekopics[3];
               repaint();
              pause(1000);
   
              // scratch four times
               nekoscratch(4);
   
               // sleep for 5 "turns"
               nekosleep(5);
  
               // wake up and run off
               currentimg = nekopics[8];
               repaint();
               pause(500);
               nekorun(xpos, size().width + 10);
           }
   
           void nekorun(int start, int end) {
               for (int i = start; i < end; i += 10) {
                  xpos = i;
               
                   if (currentimg == nekopics[0])
                      currentimg = nekopics[1];
                   else currentimg = nekopics[0];
                   repaint();
                   pause(150);
               }
           }
    
           void nekoscratch(int numtimes) {
              for (int i = numtimes; i > 0; i--) {
                   currentimg = nekopics[4];
                   repaint();
                   pause(150);
                   currentimg = nekopics[5];
                  repaint();
                  pause(150);
               }
           }
    
           void nekosleep(int numtimes) {
              for (int i = numtimes; i > 0; i--) {
                   currentimg = nekopics[6];
                   repaint();
                   pause(250);
                   currentimg = nekopics[7];
                   repaint();
                   pause(250);
              }
  
         void pause(int time) {
               try { Thread.sleep(time); }
              catch (InterruptedException e) { }
          }
   
          public void paint(Graphics g) {
             if (currentimg != null)
               g.drawImage(currentimg, xpos, ypos, this);
          }
     }