amelia
YaBB Newbies
Offline
Posts: 4
object oriented programming question
Dec 1st , 2007, 4:59pm
Hi, I am new to object oriented programming, and the below code draws nothing to the screen ... what do I do wrong - do I activate my objects wrong??? import processing.opengl.*; int amt, lnSections, cnters; // amount of objects activated void setup(){ size(700, 700, OPENGL); amt = 50; lnSections = 3; cnters = 50; // setup the line class for(int i=0; i< theLine.length; i++){ theLine[i] = new Line(20, 20, 40, 40, 200, 200, 200, 200); } // end forloop // set up the line section class for(int i=0; i< lnSec.length; i++){ lnSec[i] = new LnSec(); } // end forloop } void draw(){ background(0); stroke(200); // draw the lines for(int i=0; i< theLine.length; i++){ theLine[i].drawLine(); } // end forloop // draw the line sections for(int i=0; i< lnSec.length; i++){ lnSec[i].drawLnSec(); } // end forloop } // end draw Line [] theLine = new Line[amt]; class Line{ int x, y, x1, y1, r, g, b, a; // each line can be addressed Line(int x, int y, int x1, int y1, int r, int g, int b, int a){ this.x = x; this.y = y; this.y1 = y1; this.y1 = y1; this.r = r; this.g = g; this.b = b; this.a = a; } // a simple draw line function, where each single line has its own parameters void drawLine(){ stroke(r, g, b, a); line(x, y, x1, y1); } // end draw-function } //end Line class LnSec [] lnSec = new LnSec[lnSections]; class LnSec{ int tx, ty, tz; // each lineSection can now be addressed LnSec(){ } // here I activate the Line class, in order to draw the array // of the line class in line sections ... void drawLnSec(){ pushMatrix(); translate(20, 20, 0); // testposition //translate(tx, ty, tz); for(int i=0; i>theLine.length; i++){ theLine[i].x = i*5; theLine[i].y = i*5; theLine[i].x1 = i*3; theLine[i].y1 = i*8; theLine[i].r = 200; theLine[i].g = 200; theLine[i].b = 200; theLine[i].a = 200; } // end forloop popMatrix(); } // end draw-function } //end LnSec class