Advertisement
Zidinjo

Stern

Jan 18th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. //Star
  2.  
  3. private Star stern;
  4.  
  5. void setup() {
  6.   size(400, 400);
  7.   //Variablen deklarieren
  8.   float innerRadius = 50;
  9.   float outerRadius = 100;
  10.   int branches = 8; // Segmente in meiner Sprache
  11.  
  12.   // Konstruktor - Anzahl an Segmente, AußenRadius Size, InnenRadius Size
  13.   stern = new Star(branches, outerRadius, innerRadius);
  14. }
  15.  
  16. void draw() {
  17.   background(255);
  18.   translate(width/2, height/2);
  19.   strokeWeight(0.05);
  20.   rotate(frameCount*-0.01);
  21.   fill(0, 0, 255);
  22.   stern.starRender();
  23. }
  24.  
  25.  
  26. //Star CLass
  27.  
  28. public class Star {
  29.  
  30.   private int segmente;
  31.   private float radius;
  32.   private float innerRadius;
  33.   private float x, y;
  34.  
  35.   Star(int anzahlDerSegmente, float radius,float innerRadius) {
  36.     this.segmente = anzahlDerSegmente;
  37.     this.radius = radius;
  38.     this.innerRadius = innerRadius;
  39.   }
  40.  
  41.   // bei dem Innerenkreis muss noch die Häflte des ausgerechneten Winkel addiert werden.
  42.   public void starRender () {
  43.     float angle = TWO_PI/segmente;
  44.     float halfAngle = angle/2;
  45.    
  46.     // 1 Bogenmaß sind ~ 51 Grad = TwoPi hat 6 Bodenmaß Einheiten = 360 Grad
  47.     // Wenn ich nun Two Pi durch Segemente mache, bekomme ich den Winkel raus, die druch die Segemente geteilt wird
  48.     // Und dann nochmal dadruch, um den Mittelpunkt des Winkel vom ausgerechneten Winkel zu bekommen
  49.     // (Winkel * die Anzahl)+die Hälfte des Winkels nochmal drauf ERGIBT WINKEL + HAELFTE WINKEL
  50.  
  51.     beginShape(TRIANGLE_FAN);
  52.     for (int i = 1; i <= segmente; i++) {
  53.         x = radius * cos(angle*i);
  54.         y = radius * sin(angle*i);
  55.         //fill(0,0,255);
  56.         vertex(x, y);
  57.        
  58.         x = innerRadius * cos(angle*i+halfAngle);
  59.         y = innerRadius * sin(angle*i+halfAngle);
  60.         //fill(255,0,0);
  61.         vertex(x, y);
  62.     }
  63.     endShape();
  64.   }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement