Creating instances from a class with a for-loop
in
Programming Questions
•
9 months ago
Hello,
im still quite new to processing && programming in general, so bear with me if this is actually an obvious thing to you :)
What im trying to get is a circle divided in a certain number of segments. The number of segments can be controlled via the keyboard (Later ControlP5).
im still quite new to processing && programming in general, so bear with me if this is actually an obvious thing to you :)
What im trying to get is a circle divided in a certain number of segments. The number of segments can be controlled via the keyboard (Later ControlP5).
I already wrote a class creating a segment. Right now I made it so the Constructor asks for the center of the circle (which is width/2, height/2) and the "void display" is fed with the angles of the starting-anchorpoint, the ending-anchorpoint and the radius of course.
The Sketch works without giving out an error, but it doesnt show anything.
What am I doing wrong?
Edit: The Code its all about:
What am I doing wrong?
Edit: The Code its all about:
- Kreissegment meinSegment;
- int segmentzahl = 4;
- int segmentmaximum = 12;
- //░░███░░░████░░█████░░█░░░█░░████░░░░░░░
- //░█░░░░░░█░░░░░░░█░░░░█░░░█░░█░░░█░░░░░░
- //░░███░░░████░░░░█░░░░█░░░█░░████░░░░░░░
- //░░░░░█░░█░░░░░░░█░░░░█░░░█░░█░░░░░░░░░░
- //░░███░░░████░░░░█░░░░░███░░░█░░░░░░░░░░
- void setup() {
- size(600,600);
- meinSegment = new Kreissegment(width/2, height/2);
- }
- //░░███░░░████░░░░█░░░░░███░░░█░░░░░░░░░░
- //░████░░░████░░░░███░░░█░░░░░░░█░░░░░░░░
- //░█░░░█░░█░░░█░░█░░░█░░█░░░░░░░█░░░░░░░░
- //░█░░░█░░████░░░█░░░█░░░█░░█░░█░░░░░░░░░
- //░█░░░█░░█░░░█░░█████░░░█░█░█░█░░░░░░░░░
- //░████░░░█░░░█░░█░░░█░░░░█░░░█░░░░░░░░░░
- void draw(){
- //CONTROL FOR INCREASING /DECREASING SPLITS
- if(keyPressed) {
- if (key == 'a' || key == 'A') {
- segmentzahl ++;
- }
- if (key == 'y' || key =='Y') {
- segmentzahl --;
- }
- }
- for (int segmentnumber = 1; segmentnumber <= segmentmaximum; segmentnumber += 1){
- meinSegment.display (0 + ((segmentnumber -1) *(360 /segmentzahl)), ((360 /segmentzahl)*(segmentnumber)), 200);
- }
- if (segmentzahl <=0) {
- segmentzahl = 1;
- }
- }
- //█░DRAW-ENDE░░░░░░░░░░░░░░░░░░░░░░░░DRAW-ENDE░█
- //██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ██
- class Kreissegment {
- //GLOBAL VARIABLES
- float x = 0;
- float y = 0;
- float wina = 0;
- float winb = 0;
- float rad = 0;
- //CONSTRUCTOR
- Kreissegment(float _x, float _y) {
- x = _x;
- y = _y;
- // wina = _wina;
- // winb = _winb;
- // rad = _rad;
- }
- //FUNCTIONS
- void display(float _wina, float _winb, float _rad) {
- //Zierelement setzen
- float winc = (((winb - wina)/2) + wina); //Winkelhalbierende d. Kreissegments für Zierelement
- float radc = ((rad /5) *6); //Setzen des Radius für den Zierpart des Kreissegments
- //░░░░░
- //Curve-start
- float curvestartx = x + (sin(radians(wina))*rad);
- float curvestarty = y + (cos(radians(wina))*rad);
- //Controlpoint-start /where does it come from?
- float controlstartx = curvestartx + (sin(radians(wina-90))*rad);
- float controlstarty = curvestarty + (cos(radians(wina-90))*rad);
- //Curve-end
- float curveendx = x + (sin(radians(winb))*rad);
- float curveendy = y + (cos(radians(winb))*rad);
- //Controlpoint-end /in what direction will it lead to?
- float controlendx = curveendx + (sin(radians(winb))*rad);
- float controlendy = curveendy + (sin(radians(winb))*rad);
- //Zierelement
- float distortionx = x + (sin(radians(winc))*radc);
- float distortiony = y + (cos(radians(winc))*radc);
- //░░░░░
- beginShape();
- curveVertex(controlstartx, controlstarty); //Control start
- curveVertex(curvestartx, curvestarty); //Anchor start
- curveVertex(distortionx, distortiony); //Zierelement
- curveVertex(curveendx, curveendy); //Anchor end
- curveVertex(controlendx, controlendy); //Control end
- endShape();
- }
- }
1