Background colour change

Hello,

I am a beginner trying to create a real-time art for an assignment in processing with true or false conditions and a mouse press.

So far I have been able to play around and gain understanding with some code I found on the processing website to look and function the way I would like, but every time I add new code from tutorials and the processing website for colour changes or mouse pressed, I am getting errors of active and static and other code errors that I don’t understand.

What else I would like in the code:

  • Background random colour change with mouse press
  • Star collision changes when the stars hit each other.

Here is my code; any help with some explanation would be appreciated and some points in the right direction would be appreciated.

I look forward to a reply.

Sheree

///canvas setup varibles
void setup() {
  size(1280, 720);
  stroke (4);

}

/// spinning stars

void draw() {
  background(218,251,255);
  
  /// left star moves clockwise
  pushMatrix();
  translate(width*0.3, height*0.5);
  rotate(frameCount / 200.0);
  star(0, 0, 60, 140, 10); 
  fill(240,21,240);
  popMatrix();
  
 
  /// middle star spin anticlockwise
  
  pushMatrix();
  translate(width*0.5, height*0.5);
  rotate(frameCount / -100.0);
  star(0, 0, 60, 140, 10); 
  popMatrix();
  

  /// right star moves anticlockwise 
  pushMatrix();
  translate(width*0.7, height*0.5);
  rotate(frameCount / 200.0);
  star(0, 0, 60, 140, 10); 
  popMatrix();


}

void star(float x, float y, float radius1, float radius2, int npoints) {
  float angle = TWO_PI / npoints;
  float halfAngle = angle/2.0;
  beginShape();
  for (float a = 0; a < TWO_PI; a += angle) {
    float sx = x + cos(a) * radius2;
    float sy = y + sin(a) * radius2;
    vertex(sx, sy);
    sx = x + cos(a+halfAngle) * radius1;
    sy = y + sin(a+halfAngle) * radius1;
    vertex(sx, sy);
  }
  endShape(CLOSE);
}
1 Like

This sounds like you may not understand the difference between active and static modes.

Read the overview tutorial:

A program written as a list of statements (like the previous examples) is called a static sketch. In a static sketch, a series of functions are used to perform tasks or create a single image without any animation or interaction. Interactive programs are drawn as a series of frames, which you can create by adding functions titled setup() and draw() as shown in the code below.

So, you can do certain things with no setup and no draw. But you want animation, so you need exactly one draw and (optionally) one setup, and the commands should go inside them. You can’t have more than one setup or draw.

Hi @jeremydouglass
Thank you for your reply.
Ohhh now I understand.
Thanks again :slight_smile:

1 Like