Rollover with animation

Hey, can someone please tell me what I am doing wrong here:

int radius=0;
int length= 720;

float colorscheme1;
float colorscheme2;

float mouseX;
float mouseY;

boolean rectIsShrinking = true;
boolean circleIsShrinking = false;

void setup() {
size(1080, 720);
background(0,0,0);
rectMode(CENTER);

}

void draw() {
noStroke();

fill(red, green, blue);
rect(width/2, height/2, length, length);
if (rectIsShrinking) length–;
else length++;
if (length == 0 || length == 720) rectIsShrinking = !rectIsShrinking;

fill(red, green, blue);
ellipse(width/2, height/2, radius, radius);
if (circleIsShrinking) radius–;
else radius++;
if (radius == 0 || radius == 720) circleIsShrinking = !circleIsShrinking;
}

if(mouseX > 0 && mouseX < 1080 && mouseY > 0 && mouseY < 720) {
** colorscheme1 = (random(0), random(0), random(255)) &&**
** colorscheme2 = (random(255), random(0), random(0));**
** }**
** else{**
** colorscheme1 = (random(255), random(0), random(0)) &&**
** colorscheme2 = (random(0), random(0), random(255));**

}
}


basically processing can’t read this last part
the message on the console reads: expecting EOF, found ‘if’

thanks in advance!

1 Like

Replace “&&” by “;” please

Chrisir

1 Like

also use color:

colorscheme1 = color(random (…

1 Like
int radius=0;
int length= 720;

float colorscheme1;
float colorscheme2;

float mouseX;
float mouseY;

boolean rectIsShrinking = true;
boolean circleIsShrinking = false;

void setup() {
  size(1080, 720);
  background(0, 0, 0);
  rectMode(CENTER);
}

void draw() {
  noStroke();

  fill(red, green, blue);
  rect(width/2, height/2, length, length);
  if (rectIsShrinking) length–;
  else length++;
  if (length == 0 || length == 720) rectIsShrinking = !rectIsShrinking;

  fill(red, green, blue);
  ellipse(width/2, height/2, radius, radius);
  if (circleIsShrinking) radius–;
  else radius++;
  if (radius == 0 || radius == 720) circleIsShrinking = !circleIsShrinking;
} // <-- This is the end of draw()

// VVV What function is this code in? VVV

if (mouseX > 0 && mouseX < 1080 && mouseY > 0 && mouseY < 720) {
  colorscheme1 = (random(0), random(0), random(255)); // This is a single statement! && -> ;
  colorscheme2 = (random(255), random(0), random(0));
} else {
  colorscheme1 = (random(255), random(0), random(0)); // This is a single statement! && -> ;
  colorscheme2 = (random(0), random(0), random(255));
}
}

When you format this code properly, you easily see that your draw() function is being ended early by a stray closing bracket, which puts some of your code not in a function.

You probably want to remove this stray closing bracket.

Your lost code also has &&'s where it should have ;'s, and it’s assigning four strange things to some float numbers…

2 Likes

Thanks!
I’ve corrected those mistakes but it still doesn’t work the way I want it too.

int radius=0;
int length= 720;

float x;
float y;

float mouseX;

boolean rectIsShrinking = true;
boolean circleIsShrinking = false;

void setup() {
size(1080, 720);
background(0,0,0);
rectMode(CENTER);

}

void draw() {
noStroke();

if(mouseX > 180 && mouseX < 900) {
y = 255;
x = 0;
}
else {
y = 0;
x = 255;
}
fill(random(x), 0, random(y));
rect(width/2, height/2, length, length);
if (rectIsShrinking) length–;
else length++;
if (length == 0 || length == 720) rectIsShrinking = !rectIsShrinking;

fill(random(y), 0, random(x));
ellipse(width/2, height/2, radius, radius);
if (circleIsShrinking) radius–;
else radius++;
if (radius == 0 || radius == 720) circleIsShrinking = !circleIsShrinking;
}

Basically what I want is when the mouse is over the area of the square, I want the colors of both the squares and the ellipses to shift.

At first, the squares are being drawn in a scale of reds (random(255), 0, 0) and the ellipses in a scale of blues (0, 0, random(255)). When the mouse hovers the area where they’ll being drawn, I want the squares to change and start being drawn in a scale of blues and the ellipses to be drawn in a scale of reds…

Thank you!
I’ve now corrected those errors but it still doesn’t work the way I want it too.

int radius=0;
int length= 720;

float x;
float y;

float mouseX;

boolean rectIsShrinking = true;
boolean circleIsShrinking = false;

void setup() {
size(1080, 720);
background(0,0,0);
rectMode(CENTER);

}

void draw() {
noStroke();

if(mouseX > 180 && mouseX < 900) {
y = 255;
x = 0;
}
else {
y = 0;
x = 255;
}
fill(random(x), 0, random(y));
rect(width/2, height/2, length, length);
if (rectIsShrinking) length–;
else length++;
if (length == 0 || length == 720) rectIsShrinking = !rectIsShrinking;

fill(random(y), 0, random(x));
ellipse(width/2, height/2, radius, radius);
if (circleIsShrinking) radius–;
else radius++;
if (radius == 0 || radius == 720) circleIsShrinking = !circleIsShrinking;
}

Basically what I want is when the mouse is over the area of the square, I want the colors of both the squares and the ellipses to shift.

At first, the squares are being drawn in a scale of reds (random(255), 0, 0) and the ellipses in a scale of blues (0, 0, random(255)). When the mouse hovers the area where they’ll being drawn, I want the squares to change and start being drawn in a scale of blues and the ellipses to be drawn in a scale of reds…

This was one problem as I said in your other thread


int radius=0;
int length= 720;

float x;
float y;

boolean rectIsShrinking = true;
boolean circleIsShrinking = false;

boolean overRect=false; 

void setup() {
  size(1080, 720);
  background(0, 0, 0);
  rectMode(CENTER);
}

void draw() {
  noStroke();

  if (mouseX > 180 && 
    mouseX < 900) {
    overRect=true;
  } else {
    overRect=false;
  }

  if (overRect)
    fill(0, 0, random(255));   
  else
    fill (random(255), 0, 0); 
  //  fill(random(x), 0, random(y));
  rect(width/2, height/2, length, length);

  if (rectIsShrinking) 
    length--;
  else length++;
  if (length == 0 || length == 720) 
    rectIsShrinking = !rectIsShrinking;

  if (overRect)
    fill (random(255), 0, 0);
  else
    fill(0, 0, random(255)); 
  //fill(random(y), 0, random(x));
  ellipse(width/2, height/2, radius, radius);

  if (circleIsShrinking) 
    radius--;
  else radius++;

  if (radius == 0 || radius == 720)
    circleIsShrinking = !circleIsShrinking;
}

continued in your other thread

Chrisir