We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This is a homework assignment that I have. I have to create 4 different scenes, in all, they must have 2 animal objects and 4 other objects. I have to have the animals move in every scene and one object move in one scene. I am trying to get the seagull to fly straight across. Is there any way to group all the parts of the seagull to only have to code once or do i have to code every single part i've made?
PImage img; // Declare variable "img" of type PImage
float xPosition = 100;
float xSpeed = 2.9;
float object = 30;
float top, bottom, left, right;
void setup() {
fullScreen(); // use fullScreen() instead of size()
background( 0 );
img = loadImage("http:" + "//eskipaper.com/images/beach-background-4.jpg"); // Load the image into the program
imageMode( CENTER ); // position the center, not upper right, of the image
colorMode(HSB, 100); // hue, sat, brightness color system
}
void draw() {
background( 0 );
tint(0, 0, 360, 255); // Display full opacity no color tint
image(img, width/2, height/2); // Display at full opacity
xPosition = xPosition + xSpeed;
if ( xPosition < left ) {
xSpeed = xSpeed * -1;
} else if ( xPosition > right ) {
xSpeed = xSpeed * -1;
}
//Turtle
noFill();
stroke(33, 86, 32);
strokeWeight(8);
strokeCap(ROUND);
strokeJoin(ROUND);
line(300, 800, 350, 770 ); //Create right top fin
noFill();
stroke(33, 86, 32);
strokeWeight(8);
strokeCap(ROUND);
strokeJoin(ROUND);
line(300, 800, 350, 830 ); //Create right bottom fin
noFill();
stroke(33, 86, 32);
strokeWeight(8);
strokeCap(ROUND);
strokeJoin(ROUND);
line(300, 800, 250, 770 ); //Create left top fin
noFill();
stroke(33, 86, 32);
strokeWeight(8);
strokeCap(ROUND);
strokeJoin(ROUND);
line(300, 800, 250, 830 ); //Create left bottom fin
fill(10, 86, 32);
noStroke();
ellipse(300, 800, 80, 60); //Create brown shell
fill(33, 86, 32);
noStroke();
ellipse(350, 800, 40, 30); //Create head
ellipseMode(RADIUS);
noStroke();
fill(100);
ellipse(350, 807, 3, 3);
ellipseMode(CENTER);
stroke(0);
strokeWeight(2);
fill(100);
ellipse(350, 807, 2, 2); //Create bottom eye
ellipseMode(RADIUS);
noStroke();
fill(100);
ellipse(350, 793, 3, 3);
ellipseMode(CENTER);
stroke(0);
strokeWeight(2);
fill(100);
ellipse(350, 793, 2, 2); //Create top eye
//Boat 1
noStroke();
fill(70, 50, 80);
bezier(300, 630, 380, 675, 410, 675, 490, 630); //Hull
stroke(0);
strokeWeight(2);
fill(100);
ellipse(370, 645, 8, 8); //Create left window
stroke(0);
strokeWeight(2);
fill(100);
ellipse(395, 645, 8, 8); //Create center window
stroke(0);
strokeWeight(2);
fill(100);
ellipse(420, 645, 8, 8); //Create right window
stroke(0);
strokeWeight(6);
line(395, 630, 395, 500); //Pole
noStroke();
fill(100);
triangle(400, 540, 400, 500, 455, 520); //Flag
//Crab
stroke(0);
strokeWeight(3);
strokeCap(ROUND);
strokeJoin(ROUND);
line(460, 800, 450, 830 ); //Create outter left leg
stroke(0);
strokeWeight(3);
strokeCap(ROUND);
strokeJoin(ROUND);
line(470, 800, 460, 830 ); //Create middle left leg
stroke(0);
strokeWeight(3);
strokeCap(ROUND);
strokeJoin(ROUND);
line(480, 800, 470, 830 ); //Create inner left leg
stroke(0);
strokeWeight(3);
strokeCap(ROUND);
strokeJoin(ROUND);
line(540, 800, 550, 830 ); //Create outter right leg
stroke(0);
strokeWeight(3);
strokeCap(ROUND);
strokeJoin(ROUND);
line(530, 800, 540, 830 ); //Create middle right leg
stroke(0);
strokeWeight(3);
strokeCap(ROUND);
strokeJoin(ROUND);
line(520, 800, 530, 830 ); //Create inner right leg
fill(0, 100 , 100);
noStroke();
ellipse(500, 800, 100, 60); //Create red body
noFill();
stroke(359, 100, 0);
strokeWeight(6);
strokeCap(SQUARE);
strokeJoin(ROUND);
bezier(470, 800, 440, 785, 440, 770, 470, 755); //Create left arm
fill(0, 100 , 100);
noStroke();
ellipse(470, 755, 20, 20); //Create left claw
noFill();
stroke(359, 100, 0);
strokeWeight(6);
strokeCap(SQUARE);
strokeJoin(ROUND);
bezier(530, 800, 560, 785, 560, 770, 530, 755); //Create right arm
fill(0, 100 , 100);
noStroke();
ellipse(530, 755, 20, 20); //Create left claw
ellipseMode(RADIUS);
noStroke();
fill(100);
ellipse(480, 800, 3, 3);
ellipseMode(CENTER);
stroke(0);
strokeWeight(2);
fill(100);
ellipse(480, 800, 1, 1); //Create left eye
ellipseMode(RADIUS);
noStroke();
fill(100);
ellipse(520, 800, 3, 3);
ellipseMode(CENTER);
stroke(0);
fill(100);
ellipse(520, 800, 1, 1); //Create right eye
//Boat 2
noStroke();
fill(90, 30, 30);
bezier(800, 630, 880, 675, 910, 675, 990, 630); //Hull
stroke(0);
strokeWeight(2);
fill(100);
ellipse(870, 645, 8, 8); //Create left window
stroke(0);
strokeWeight(2);
fill(100);
ellipse(895, 645, 8, 8); //Create center window
stroke(0);
strokeWeight(2);
fill(100);
ellipse(920, 645, 8, 8); //Create right window
stroke(0);
strokeWeight(6);
line(895, 630, 895, 500); //Pole
noStroke();
fill(100);
triangle(900, 540, 900, 500, 955, 520); //Flag
//Seagull
noFill();
strokeCap(ROUND);
stroke(0);
strokeWeight(8);
line(300, 90, 280, 80); //Create top wing
noStroke();
fill(100);
ellipse(300, 100, 50, 30); //Create body
noStroke();
fill(100);
ellipse(330, 100, 25, 25); //Create head
noFill();
strokeCap(ROUND);
stroke(10, 80, 100);
line(338, 103, 355, 103); //Create beak
noFill();
strokeCap(ROUND);
stroke(0);
strokeWeight(8);
line(300, 110, 280, 120); //Create bottom wing
stroke(0);
strokeWeight(2);
fill(100);
ellipse(330, 100, 1, 1); //Create eye
//Dog
fill(10, 86, 50);
noStroke();
ellipse(1000, 800, 175, 225); //Create brown head
fill(0);
stroke(0);
strokeWeight(8);
strokeJoin(ROUND);
triangle(1000, 875, 970, 835, 1030, 835); //Create nose
ellipseMode(RADIUS);
noStroke();
fill(100);
ellipse(975, 775, 15, 20);
ellipseMode(CENTER);
stroke(0);
strokeWeight(2);
fill(0);
ellipse(975, 775, 10, 20); //Create left eye
ellipseMode(RADIUS);
noStroke();
fill(100);
ellipse(1025, 775, 15, 20);
ellipseMode(CENTER);
stroke(0);
strokeWeight(2);
fill(0);
ellipse(1025, 775, 10, 20); //Create right eye
fill(10, 86, 70);
stroke(10, 86, 70);
strokeWeight(8);
strokeJoin(ROUND);
triangle(1040, 695, 1092, 830, 1100, 768); //Create right ear
fill(10, 86, 70);
stroke(10, 86, 70);
strokeWeight(8);
strokeJoin(ROUND);
triangle(960, 695, 908, 830, 900, 768); //Create left ear
}
Answers
Look up translate(), pushMatrix(), and popMatrix(). Those are the functions you need.