How to add code to your documentation

Click the <> button to add code to your post:

You’ll then see this screen where you can paste your code in:

For Processing code change the language to Java:

Once you’re done click Add and you’re all set. Easy!

int x;
int y;
int backgroundColor = 255;
float r = 255;
float g = 0;
float b = 0;
int rectWidth = 100;
int rectHeight = 100;

void setup() {
  size(640, 480);
  x = width/2;
  y = height/2;
}

void draw() {
  background(backgroundColor);
  noStroke();
  fill(r, g, b);
  rect(x, y, rectWidth, rectHeight);
}

void mousePressed() {
  if (mouseX > x && mouseX < x+rectWidth && mouseY > y && mouseY < y+rectHeight) {
    r = random(255);
    g = random(255);
    b = random(255);
  }
}

void keyPressed() {
  if (key=='b') {
    backgroundColor = 255 - backgroundColor;
  }
}

 

Leave a Reply