My class is using the sketch programming Processing and we are learning about in
ID: 670894 • 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:
PImage frisbee;
PImage beach;
PImage plane;
PImage birds;
int speed=10;// PIXELS/SECOND
int frisbee_position_x=400;
int frisbee_direction_x=-1; // IS ALWAYS -1 (LEFT) OR +1 (RIGHT)
int frisbee_position_y=400;
int frisbee_direction_y=-1; // IS ALWAYS -1 (TOP) OR +1 (BOTTOM)
void setup()
{
size(1200,800);
frisbee=loadImage("frisbee.png");
beach=loadImage("beach.jpeg");
plane=loadImage("plane.png");
birds=loadImage("birds.png");
}
void draw()
{
image(beach,0,0,1200,800);
image(frisbee, frisbee_position_x, frisbee_position_y, 100,100);
//ALWAYS MOVE THE BALL
frisbee_position_x=frisbee_position_x+frisbee_direction_x*speed;
frisbee_position_y=frisbee_position_y+frisbee_direction_y*speed;
//IF THE BALL HITS THE LEFT OR THE RIGHT BORDER DO:
if(frisbee_position_x<=0 || frisbee_position_x>=1200-100)
{
frisbee_direction_x= -frisbee_direction_x;
}
//IF THE BALL HITS THE TOP OR THE BOTTOM BORDER DO:
if(frisbee_position_y<=0 || frisbee_position_y>=600-100)
{
frisbee_direction_y= -frisbee_direction_y;
}
}
I'm not sure how to get the other smaller images to show up or move. 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. What is wrong?
Explanation / Answer
You can try out ths method once and see the result....
Images can be added to the data folder automatically via:
Sketch --> Add File. . .
or manually:
Sketch --> Show Sketch Folder
This will open up the sketch folder. If there is no data directory create one. Otherwise, place your image files inside.
Processing accepts the following file formats for images: GIF, JPG, TGA, PNG.
Also , you can try out to define different size() parameter for the 3 images....I think, otherwise the code is right..
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.