How to use P3d with contorl P5 GUI library?

edited December 2017 in Library Questions

****Hi, I am new to processing and am using processing 3.3.6

Wondering if anyone can help me make the GUI interface render in 2D ?

The idea is to have a sphere in the middle (able to rotate with mouseX,Y ->using peacy cam) and on click GUI button will render 2D pattern(ellipse for example) on the canvas and play sound

Below is my code:

import peasy.*;

!import processing.sound.*;

import controlP5.*;

ControlP5 cp5;


PeasyCam cam;

PVector [][] globe;

int total = 100;

// button data

  Button pollution;

// --- set up control

 boolean populationpatternon = true;
 boolean deathpatternon = true;
 boolean socialpatternon = true;
 boolean pollutionpatternon = true;


void setup(){
  size(1000,1000,P3D);
  hint(ENABLE_DEPTH_TEST);
  globe = new PVector[total][total];
  cam = new PeasyCam(this,200);
  hint(DISABLE_DEPTH_TEST);

  cp5 = new ControlP5(this);
  pollution = cp5.addButton("pollution").setValue(0).activateBy(ControlP5.RELEASE);

}

public void pollution(){
  println("Button Pressed pollution");
  pollutionpatternon = !pollutionpatternon;
}

void draw(){
  background(255);
  lights();
  lightSpecular(255, 255, 255); 
  directionalLight(255, 255, 255, 1, 1, -1); 
  drawsphere(); 


  if(pollutionpatternon == true){
    pollutionpattern();
  }
}

void drawsphere(){
  lights();
  float r = 50;

  for(int i = 0; i < total; i ++){ 
    float lat = map(i, 0,total,-HALF_PI,HALF_PI); 
    for(int j = 0; j <total; j ++){
    float lon = map(j, 0,total,-PI,PI);
    float x = r * sin(lon)*cos(lat);
    float y = r * sin(lon)*sin(lat);
    float z = r * cos(lon);
    globe[i][j] = new PVector(x,y,z);
    }
  }
  for(int i = 0; i < total; i ++){  
    for(int j = 0; j <total; j ++){
    PVector v = globe[i][j];
    stroke(20);
    strokeWeight(2);
    point(v.x, v.y, v.z);
    }
  }
}

void pollutionpattern(){
  ellipse(300,100,100,100);
}

Answers

Sign In or Register to comment.