a simple question about classes
in
Programming Questions
•
2 years ago
I'm new to processing so this may be a super simple question; I'm trying to understand classes, but i can't seem to get them to work in the most simple sense. Can someone explain what i'm not doing in order to activate the class? The final result should just be a box rotating in 3d space, which i had working without using classes.
- import guicomponents.*;
- import processing.opengl.*;
- //declare
- GVertSlider sdrScale;
- float zoom;
- float zoomfactor;
- //class array and integer
- Particle p[];
- int num;
- void setup(){
- size(500,500,OPENGL);
- smooth();
- fill(000);
- frameRate(30);
- rectMode(CENTER);
- GComponent.globalColor = GCScheme.getColor(this, GCScheme.GREEN_SCHEME);
- GComponent.globalFont = GFont.getFont(this, "Serif", 11);
- sdrScale = new GVertSlider(this, 0, 0, 10, height);
- sdrScale.setLimits(200, 0, height);
- sdrScale.setInertia(1);
- zoomfactor = 45.0f / height;
- zoom = 0.1 * zoomfactor * sdrScale.getValue();
- reinitialize();
- }
- void draw(){
- background(000);
- lights();
- }
- void reinitialize() {
- pushMatrix();
- translate(width/2, height/2, -200);
- noStroke();
- scale(zoom);
- rotateX(frameCount*PI/150);
- rotateY(frameCount*PI/170);
- rotateZ(frameCount*PI/90);
- num=int(random(2,20));
- p=new Particle[num];
- for(int i=0; i<num; i++) p[i]=new Particle();
- fill(255);
- stroke(255);
- line(-100, 0, 0, 100, 0, 0);
- line(0, -100, 0, 0, 100, 0);
- line(0, 0, -100, 0, 0, 100);
- popMatrix();
- }
- void handleSliderEvents(GSlider slider){
- zoom = zoomfactor * slider.getValue() * 0.1f;
- }
- //Particle class
- class Particle{
- float f;
- float x,y,rad,gray;
- float dir,dirD,speed;
- Particle(){
- f=random(2,10);
- x=random(width);
- y=random(height);
- rad=random(3,15);
- gray=random(100,255);
- dir=random(360); // a random direction in angles.
- dirD=random(-2,2); // a random direction in angles.
- speed=random(1.5,4);
- }
- void draw(){
- box(90);
- fill(255);
- stroke(255);
- line(-100, 0, 0, 100, 0, 0);
- line(0, -100, 0, 0, 100, 0);
- line(0, 0, -100, 0, 0, 100);
- translate(f*10,f*10);
- }
1