# Could someone tell me why this isn't working please?

**URL:** <https://discourse.processing.org/t/could-someone-tell-me-why-this-isnt-working-please/37468>\
**Category:** Coding Questions\
**Created:** [June 11, 2022, 2:56am UTC](https://discourse.processing.org/t/could-someone-tell-me-why-this-isnt-working-please/37468 "2022-06-11T02:56:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![locky.mcdonald](https://avatars.discourse-cdn.com/v4/letter/l/9de0a6/32.png) [@locky.mcdonald](https://discourse.processing.org/u/locky.mcdonald)\
**Post date:** [June 11, 2022, 2:56am UTC](https://discourse.processing.org/t/could-someone-tell-me-why-this-isnt-working-please/37468/1 "2022-06-11T02:56:37Z")

</div>

// I know its a bit all over the place, but any little help would be much appreciated. The background is supposed to fade from cream to black and back while a circle moves up and down the screen, behind the waves at the bottom of the code. I don’t understand why it is not working. I can get the screen to fade and sun to move up and down by itself but when I add the wave code, it doesn’t work. /

```auto
< `let ellipseY = 0;
let ySpeed = 0.3;
let amt, startColor, newColor;
let p = ['#DEEEFC','#CBE5FC','#BDDDFA','#ACD7FC','#A0D3FD','#8FCAFA','#68A8DB','#356C97'];

function setup() {
  createCanvas(windowWidth, windowHeight);
  startColor = color('#FFF5E6');
  newColor = color('#00050A');
  amt = -14;
  background(startColor);
}

function draw() {

//fading background, changes when sun dissapears.
{
  background(lerpColor(startColor, newColor,amt));
  amt += 0.01;
  if(amt >= 20.5){
    amt = 0.0;
    startColor = newColor;
    newColor = color('#00050A');
  }
}   
if (mouseIsPressed) {
    noStroke();
    fill(0, 24, 95, 50);
    ellipseMode(CENTER);
    ellipse(mouseX, mouseY, 400, 400);
  }
 {
  ellipse(400, ellipseY, 200);
  noStroke();
  fill ('#FFDA0C');
  ellipseY = ellipseY + ySpeed;

  // bounce off bottom
  if(ellipseY > height) {
    ySpeed = ySpeed * -1;
  }
 }
  
   //Calling Wave function 
    wave();   
  }
  
   function wave() { 
     
   var w = windowWidth*2;
   var h = .35*windowHeight;
  
	var m = {
		x:-windowWidth/2,
		y:random(h/p.length-1, h/p.length)
  };
     
   for (var i = 1; i<p.length; i++){
   	var r = random(i*.75, i*1.5);
    strokeWeight(2);
    stroke(p[i]);
    fill(p[i]);
    push(); // left-right down angle
    translate(0,0);
    rotate(random(.1,.15));
     
    beginShape();
    
     for (var j=0; j<w/3; j++ ){
      vertex(j*3, h+m.y*r+random(-1,1));
  }
    vertex(w, windowHeight*2); // bottom right
    vertex(m.x, windowHeight*2); // bottom left
  } 
    endShape(CLOSE);
	pop();  
     
     
    var r = random(i*.5, i*1.5);
    strokeWeight(2);
    stroke(p[i]);
    fill(p[i]);
    push(); // left-right down angle
    translate(windowWidth,0);
    scale(-1,1);
    rotate(random(.1,.15));
    beginShape();
    for (var j=0; j<w/3; j++ ){
      vertex(j*3, h+m.y*r+random(-1,1));
  }
    vertex(w, windowHeight*2); // bottom right
    vertex(m.x, windowHeight*2); // bottom left
   }
    endShape(CLOSE);
	pop();
  }`>

```

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 11, 2022, 7:13am UTC](https://discourse.processing.org/t/could-someone-tell-me-why-this-isnt-working-please/37468/2 "2022-06-11T07:13:11Z")

</div>

Hi @locky.mcdonald ,

The code you posted isn’t actually runnable as too many syntax issues and not that I understand all your intention for your code … but I tried to get close and fix it … 🙂

[Try this](https://editor.p5js.org/mnse/sketches/jtaQQsUCw)

Cheers  
—mnse

PS: next time maybe it would be much easier for us to help, if you share your code with [P5js Webeditor](https://editor.p5js.org).

PPS: waves should be also aligned wrt. of animation speed not always be random each frame …

---

<div class="post-metadata">

**Author:** ![locky.mcdonald](https://avatars.discourse-cdn.com/v4/letter/l/9de0a6/32.png) [@locky.mcdonald](https://discourse.processing.org/u/locky.mcdonald)\
**Post date:** [June 12, 2022, 5:37am UTC](https://discourse.processing.org/t/could-someone-tell-me-why-this-isnt-working-please/37468/4 "2022-06-12T05:37:07Z")

</div>

ahhh okay, that makes more sense. thank you!!
