Gioco da definire

Did you consider to make a 3D Mondrian?

Using boxes and spheres


// https://discourse.processing.org/t/gioco-da-definire/18681/7

import peasy.*;

final color WHITE  = color(255);
final color BLACK  = color(0);

final color RED     = color(255, 0, 0);
final color GREEN   = color(0, 255, 0);
final color BLUE    = #0326FF; 

final color YELLOW  = #FFF703; 
float x = 300;
float y = 300;
float y2 = 300;

// drag 
boolean hold=false;  // left mouse button
boolean hold2=false;  // right mouse button

// state 
final int INFO=0; 
final int GAME=1; 
int state=INFO; 

PeasyCam cam;

//--------------------------------------------------------------------

void setup() {
  size(600, 600, P3D);
  background(0);
  surface.setTitle("Mondrian");
  avoidClipping(); 
  cam = new PeasyCam(this, 5000);
}

void draw() {
  // evaluate state 
  if (state==INFO) {
    cam.beginHUD(); 
    background(0);
    fill(255); 
    text("INFO-SCREEN\n\nMove sculpture with mouse.\nWhen you hold a key: Click left mouse and drag both directions; \nClick right mouse and drag y direction. \n\nClick mouse.", 
      100, 100);
    cam.endHUD();
  } 
  //---------------------
  else if (state==GAME) {
    //
    background(0); 
    lights(); 

    stroke(#FCFDFF);
    strokeWeight(1); // 9 

    // line(0, x, x, height);

    float depth=430; 

    fill(BLUE);
    box3D(0, 0, -30, x, height, depth );

    fill(#FFF703);
    box3D(0, y, -30, x, y, depth);

    fill(WHITE);
    // box3D(0, height+10, -30, x, height, depth );

    //  line(x, 0, x, height);

    fill(RED);
    box3D(x, 0, -30, x, height, depth);

    // line(0, y, x, y);



    //  line(x, y2, width, y2);

    fill(#0326FF);
    box3D(x, y2, -30, width, y2, depth);

    println(x, y);

    //-----------------------------------------
    if (hold) {
      x+=mouseX-pmouseX;
      y+=mouseY-pmouseY;
    }//if

    if (hold2) {
      //x+=mouseX-pmouseX;
      y2+=mouseY-pmouseY;
    }//if


    if (keyPressed) 
      cam.setActive(false); 
    else cam.setActive(true);
  }//else state 
  //
}//draw 

//----------------------------------------------------------------

void box3D(float x, float y, float z, 
  float w, float h, float d) {
  // 
  pushMatrix();
  translate (x, y, z);
  box(w, h, d); 
  popMatrix();
}

//----------------------------------------------------------------

void mousePressed() {
  // evaluate state 
  if (state==INFO) {
    state = GAME;
  }
  //-----------------------------------------
  else if (state==GAME) {
    if (mouseButton==LEFT) { 
      hold=true;
    } else {
      hold2=true;
    }
  }//else
}//func 

void mouseReleased() {
  hold=false;
  hold2=false;
}//func 

void keyPressed() {
}

// --------------------------------------------------------------------------

void avoidClipping() {
  // avoid clipping :
  // https : //
  // forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
  perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func
//
1 Like