I cant figure out how to use 'class'
in
Programming Questions
•
3 years ago
I am new to processing and am having some serious trouble. I can't figure how to get this object into it's own class so i can put in other objects without conflicts. here's the code and have a look, please.
- float[] x = new float[5];
float[] y = new float[5];
float segLength = 30;
void setup() {
size(1000, 500);
smooth();
strokeWeight(5);
stroke(255, 80);
noFill();
}
void draw() {
background(0,100,180);
dragSegment(0, mouseX, mouseY);
dragSegment(1, x[0], y[0]);
dragSegment(2, x[1], y[1]);
dragSegment(3, x[2], y[2]);
dragSegment(4, x[3], y[3]);
}
void dragSegment(int i, float xin, float yin) {
float dx = xin - x[i];
float dy = yin - y[i];
float angle = atan2(dy, dx);
x[i] = xin - cos(angle) * segLength;
y[i] = yin - sin(angle) * segLength;
segment(x[i], y[i], angle);
}
void segment(float x, float y, float a) {
pushMatrix();
translate(x, y);
rotate(a);
ellipse(20, 0, 30, 30);
line(0,0,10,0);
popMatrix();
}
1