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

My class is using the sketch programming Processing and we are learning about in

ID: 670805 • Letter: M

Question

My class is using the sketch programming Processing and we are learning about inserting images. Our assignment is as follows:

In processing load at least 5 images and compose a nice scene.

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)

Now I have been able to load the background image at 1200x800, but when it comes to getting the three smaller images to load it doesn't show. Here is what I have so far:

// Declaring a variable of type PImage
PImage img;
PImage birds;
PImage plane;
PImage frisbee;

void setup()
{
size(1200,800);
// Make a new instance of a PImage by loading an image file
img = loadImage("beach.jpg");

}
  
void draw() {
background(0);
// Draw the image to the screen at coordinate (0,0)
image(img,0,0);
}

I'm not sure how to get the other smaller images to show up. The screen goes black or doesn't load at all. I have the images already, I just need to know the lines to put in.

Explanation / Answer

You can use the other format of the image function that is image(img, a, b, c, d)

Here,

a and b represent the x and y co-ordinates of the upper left corner of the image

c- width to display the image

d-height to display the image

You can animate the images by incrementing the x and y co-ordinates as shown below

PImage img;

PImage birds;

PImage plane;

PImage frisbee;

float x

void setup()

{

   size(1200,800);

   // Make a new instance of a PImage by loading an image file

   img = loadImage("beach.jpg");

   birds= loadImage("birds.jpg");

   plane= loadImage("plane.jpg");

   frisbee= loadImage("frisbee.jpg");

}

  

void draw() {

   background(0);

   // Draw the image to the screen at coordinate (0,0)

   //image(img,0,0);

   image(img,x,0,500,500);

   x+=0.01;

   image(birds,x,50,0);

   x+=0.05;

   image(plane,x,100,0);

   x+=0.1;

   image(frisbee,x,150,0);

   x+=0.01;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote