# Moving a picture

**URL:** <https://discourse.processing.org/t/moving-a-picture/25018>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 29, 2020, 4:00pm UTC](https://discourse.processing.org/t/moving-a-picture/25018 "2020-10-29T16:00:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntiQliMax](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@AntiQliMax](https://discourse.processing.org/u/AntiQliMax)\
**Post date:** [October 29, 2020, 4:00pm UTC](https://discourse.processing.org/t/moving-a-picture/25018/1 "2020-10-29T16:00:14Z")

</div>

Well at this point i worked a bit further, The goal is that a fish should jump from a random start position to another (hard coded route) to another end point.

I know you guys don’t have the pictures and I am sorry for that if needed i can try to remake this model with squares.

the part that i am stuck on is the part were the movement of the fish is involved, I can create the random number from a mouseclick, but when i start to move the fish, first of all it is instant, second I get a whole trail of fish behind it, I guess that the background is not redrawn, but I don’t really know where is should place the background if i have to redraw it correctly.

If you have questions please ask, I am online.

//initilizing all images  
PImage penguin;  
PImage Fish1;  
PImage Fish2;  
PImage Fish3;  
PImage Fish4;  
PImage Wak1;  
PImage Wak2;  
PImage Wak3;  
PImage Wak4;  
PImage Hiddenfish;

//initilizing classes  
Penguin P;  
Fish F;

//initilizing X and Y  
int x = 450;  
int y = 450;

//setup  
void setup() {  
P = new Penguin();  
F = new Fish();  
size(1000, 1000);

//loading images  
penguin = loadImage(“penguin.png”);  
Fish1 = loadImage(“Fish.png”);  
Fish2 = loadImage(“Fish.png”);  
Fish3 = loadImage(“Fish.png”);  
Fish4 = loadImage(“Fish.png”);  
Wak1 = loadImage(“Wak.png”);  
Wak2 = loadImage(“Wak.png”);  
Wak3 = loadImage(“Wak.png”);  
Wak4 = loadImage(“Wak.png”);  
Hiddenfish = loadImage(“Hiddenfish.png”);  
}

void draw() {  
//placing images/background  
background(203, 231, 243);  
image(Hiddenfish, 0, 100);  
image(Wak1, 650, 650);  
image(Wak2, 100, 150);  
image(Wak3, 650, 150);  
image(Wak4, 100, 650);  
image(penguin, x, y);

//Penguin movement  
if (keyPressed) {  
P.moveLeft();  
P.moveUp();  
P.moveDown();  
P.moveRight();  
}

}

void mousePressed() {  
if (mousePressed) {  
F.fishJump();  
}  
}

class Fish {  
int Xfish = 0;  
int Yfish = 0;  
int jumpPosition;  
int test;  
void fishJump() {

```
if (mousePressed == true)
  mousePressed();

if (jumpPosition == 0) {
  
  for (int Xfish = 0; Xfish < 770; Xfish = Xfish+1) {
    image(Fish1, Xfish+220, Yfish+250);
  }
 
}

if (jumpPosition == 1)
{   
  for (int Xfish = 0; Xfish < 770; Xfish = Xfish+1) {
    image(Fish1, Xfish+220, Yfish+250);
  }
 
  
} 
if (jumpPosition == 2)
{  
  image(Fish3, Xfish+770, Yfish+750);
} 

if (jumpPosition == 3)
{   
  image(Fish4, Xfish+ 220, Yfish+750);
}

```

}

void mousePressed() {  
jumpPosition = int(random(4));  
println(jumpPosition);  
}  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 29, 2020, 4:02pm UTC](https://discourse.processing.org/t/moving-a-picture/25018/2 "2020-10-29T16:02:26Z")

</div>

draw() should start with background

for movement use `lerp()` (see reference please) but without the for-loop just use `amt` as a global variable and say `amt += 0.011;`
