Help with Object Oriented Programming
in
Programming Questions
•
1 year ago
Hello, I am just learning to write sketches using OOP and I'm not quite sure how to implement the patch.
I have read the Object tutorial here on processing.org, and I've also read the OOP chapter out of Ira Greenberg's processing book. I get the concepts of OOP, but the specific implementation is baffling me.
I took a procedural patch I had written and attempted to rewrite it in OOP format. I've wrangled it such that the compiler doesn't complain at all, but when I run the sketch it just outputs a blank screen.
What I don't quite get is how to pass variables to constructors, how to write other methods that modify specific variables of constructors, etc.
In this patch I am trying to write a curve that follows the mouse cursor, and the cursor would also have a circle around it. I'd like to be able to modify the control point variables and have them constantly updating with a random() function or some similar thing. Currently, all I get is a black screen.
What am I missing here?
- import processing.opengl.*;
- Tentacle t1;
- void setup()
- {
- size(screen.width, screen.height, OPENGL);
- //background(0);
- t1 = new Tentacle(100, 100, 0, 0, mouseX, mouseY, 600, 600);
- }
- void draw(){
- background(0);
- stroke(255);
- strokeWeight(10);
- fill(150, 20, 180, 80);
- smooth();
- t1.crv();
- t1.circle(50);
- }
- class Tentacle{
- float cx1, cy1, x1, y1, x2, y2, cx2, cy2, modX, modY, c;
- Tentacle(float cx1, float cy1, float x1, float y1, float x2, float y2, float cx2, float cy2){
- this.cx1 = cx1; //control point
- this.cy1 = cy1;
- this.x1 = x1; //curve startpoint
- this.y1 = y1;
- this.x2 = x2; //curve endpoint
- this.y2 = y2;
- this.cx2 = cx2; //2nd control point
- this.cy2 = cy2;
- }
- //curve properties
- void crv(){
- curve(this.cx1, this.cy1, this.x1, this.y1, this.x2, this.y2, this.cx2, this.cy2);
- }
- void circle(float c){
- this.c = c;
- this.x2 = x2;
- this.y2 = y2;
- ellipse(this.c, this.c, this.x2, this.y2);
- }
- }
1