🔍

Hello Processing

This basic script shows how to get stated with Processing IDE and coding in general. The script offers some key elements like shape drawing, colors, mouse movement, for loops and if cases.


color my_current_color = #000000; // this variable we use variable to save current drawing color
color[] my_colors = { #A5E317, #1774E3, #F4F7A0, color(150, 0, 0) }; // my color palette

int brush_mode = 0; // our current brush mode

// this is run only once at startup
void setup() {

  size(600, 300); // create a new sage window
  background(255, 204, 0); // fill with organge
}

// this runs in a loop
void draw() {

  // check if mouse is pressed
  if (mousePressed) {

    // if left mousebutton is down
    if (mouseButton == LEFT) {

      fill( my_current_color ); // change the fill color
      noStroke();
      for ( int i = 0; i < 10; i++) {

       
        float offx = random(-20, 20 ); 
        float offy = random(-20, 20 ); 
        
       // check  
       // ---------------------------------
        if(brush_mode == 0){ 
       
                  circle(mouseX + offx, mouseY + offy, 5); // here we draw the circle
        }
        
        // ---------------------------------
        if(brush_mode == 1){  
          
                pushMatrix();
                   translate(mouseX+offx, mouseY+offy);
                   rotate( random(TWO_PI) );
                   rect( 0,0, 2,44 ); 
                popMatrix();
        }
        // ---------------------------------
        if(brush_mode == 2){  
          
          strokeWeight(8); // set the stroke thickness
          stroke(my_current_color ); // set the color of the line
          line( mouseX+offx,mouseY+offy, width/2, height/2 ); // draw line from point A to point B
        
        }
        
      }
    }
    // if right mousebutton is down
    if (mouseButton == RIGHT) {

      // draw a circle with the same color as the background = our cool eraser tool ;) 
      fill(255, 204, 0);
      circle( mouseX, mouseY, 20);
    }
  }
  
  filter(POSTERIZE, 4);
  filter(BLUR, 1);
}

// this is some keyboard events that are executes on key input
void keyPressed() {

  
  println(keyCode);
  
  if ( keyCode == 83 ) { // 83 is the equivalten of the skey for SAVE
  
    saveFrame( "shot_###.png" );
  }
  
  if ( keyCode == 49 ) { // 49 is the equivalent of 1 key
    my_current_color = my_colors[0]; // change color to palette color 1
  }

  if ( keyCode == 50 ) { // 50 is the equivalent of 2 key
    my_current_color = my_colors[1]; // change color to palette color 2
  }

  if ( keyCode == 51 ) { // 50 is the equivalent of 3 key
    my_current_color = my_colors[2]; // change color to palette color 2
  }

  if ( keyCode == 52 ) { // 50 is the equivalent of 4 key
    my_current_color = my_colors[3]; // change color to palette color 2
  }
  // change the brushmode with my setup keys // 7 8 9 
  if ( keyCode == 55 ) { brush_mode = 0;}
  if ( keyCode == 56 ) { brush_mode = 1;}
  if ( keyCode == 57 ) { brush_mode = 2;}
}