Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Star
- private Star stern;
- void setup() {
- size(400, 400);
- //Variablen deklarieren
- float innerRadius = 50;
- float outerRadius = 100;
- int branches = 8; // Segmente in meiner Sprache
- // Konstruktor - Anzahl an Segmente, AußenRadius Size, InnenRadius Size
- stern = new Star(branches, outerRadius, innerRadius);
- }
- void draw() {
- background(255);
- translate(width/2, height/2);
- strokeWeight(0.05);
- rotate(frameCount*-0.01);
- fill(0, 0, 255);
- stern.starRender();
- }
- //Star CLass
- public class Star {
- private int segmente;
- private float radius;
- private float innerRadius;
- private float x, y;
- Star(int anzahlDerSegmente, float radius,float innerRadius) {
- this.segmente = anzahlDerSegmente;
- this.radius = radius;
- this.innerRadius = innerRadius;
- }
- // bei dem Innerenkreis muss noch die Häflte des ausgerechneten Winkel addiert werden.
- public void starRender () {
- float angle = TWO_PI/segmente;
- float halfAngle = angle/2;
- // 1 Bogenmaß sind ~ 51 Grad = TwoPi hat 6 Bodenmaß Einheiten = 360 Grad
- // Wenn ich nun Two Pi durch Segemente mache, bekomme ich den Winkel raus, die druch die Segemente geteilt wird
- // Und dann nochmal dadruch, um den Mittelpunkt des Winkel vom ausgerechneten Winkel zu bekommen
- // (Winkel * die Anzahl)+die Hälfte des Winkels nochmal drauf ERGIBT WINKEL + HAELFTE WINKEL
- beginShape(TRIANGLE_FAN);
- for (int i = 1; i <= segmente; i++) {
- x = radius * cos(angle*i);
- y = radius * sin(angle*i);
- //fill(0,0,255);
- vertex(x, y);
- x = innerRadius * cos(angle*i+halfAngle);
- y = innerRadius * sin(angle*i+halfAngle);
- //fill(255,0,0);
- vertex(x, y);
- }
- endShape();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement