import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 

public class udk_01_stubbe_2 extends BApplet {
// flower setup
int leaf = 7;
int spheres = 20;

// flower color
int c1 = 0xff6C0101;
int c2 = 0xffE20000;
int c3 = 0xffFF0F00;
int c4 = 0xffFF5C00;
int c5 = 0xffFFB700;
int c6 = 0xffFFE9B2;

// flower vovement
// float rotation = 0;
float xmag, ymag = 0;
float newXmag, newYmag = 0;

// small sphere positions
float[] posX = new float[spheres];
float[] posY = new float[spheres];
float[] posZ = new float[spheres];

// size leafs
float[] sizeLeaf = new float [leaf];


void setup() {
  size(400, 400);
  noStroke();
  colorMode(RGB, 1);
  background(0.5f, 0.5f, 0.45f);
  // random sphere positions
  for(int j=0; j<spheres; j++) {
    posX[j] = random(-20,20);
    posY[j] = random(-20,20);
    posZ[j] = random(20,50);
  }
  // random leaf size
  for(int j=0; j<leaf; j++) {
    sizeLeaf[j] = random(.9f,1.1f);
  }
   
}

void loop() {
 // pseudo camera setup
  translate(width/2, height/2+10,250);
  
  // yMouse -> yAxis
  newXmag = mouseX/(float)(width);
  newYmag = mouseY/(float)(height);
  float diff = xmag-newXmag;
  if (abs(diff) >  0.01f) { xmag -= diff/4.0f; }
  diff = ymag-newYmag;
  if (abs(diff) >  0.01f) { ymag -= diff/4.0f; }
  rotateX(-ymag+1.1f);
  rotateZ(-xmag);
  
  // automated Movement (modify zRotation)
  //rotateZ(rotation);
  //rotation += .01;

  // build Big Sphere
  push();
    //noStroke();
    fill(c6);
    translate(0,0,7);
    sphere(6);
  pop();

    for(int j=0; j<spheres; j++) {
    // sphere movement
    posX[j] += random(-1,1);
    posY[j] += random(-1,1);
    posZ[j] += random(-1,1);

    // build lines to small spheres
      push();
      stroke(c6);
      beginShape(LINE_STRIP);
        curveVertex(0, 0, 0);
        curveVertex(0, 0, 2);
        curveVertex(posX[j], posY[j], posZ[j]);
        curveVertex(0, 0, -10);
      endShape();
      noStroke();
      // build small spheres
      fill(c6);
      translate(posX[j], posY[j], posZ[j]);
      sphere(posZ[j]/45);
    pop();
  }
  
  //build leafes
  push();
  for(int i=0; i<leaf; i++) {
    scale(sizeLeaf[i]);
    rotateZ(0.9f);
    beginShape(QUAD_STRIP);
      fill(c1);vertex(0.00f,-0.68f,0.00f);
      fill(c2);vertex(9.11f,-4.94f,8.88f);
      fill(c2); vertex(8.11f,-2.47f,10.48f);
      fill(c1);vertex(0.00f,-0.34f,0.00f);
      fill(c1);vertex(0.00f,-0.00f,0.00f);
      fill(c2);vertex(9.45f,-0.00f,7.40f);
      fill(c2);vertex(8.11f,2.47f,10.48f);
      fill(c1);vertex(0.00f,0.34f,0.00f);
      fill(c1);vertex(0.00f,0.68f,0.00f);
      fill(c2);vertex(9.11f,4.94f,8.88f);
    endShape();
    beginShape(QUAD_STRIP);
      fill(c2);vertex(9.11f,-4.94f,8.88f);
      fill(c3);vertex(19.64f,-8.58f,13.21f);
      fill(c3);vertex(19.57f,-4.29f,14.95f);
      fill(c2);vertex(8.11f,-2.47f,10.48f);
      fill(c2);vertex(9.45f,-0.00f,7.40f);
      fill(c3);vertex(19.86f,-0.00f,13.65f);
      fill(c3);vertex(19.57f,4.29f,14.95f);
      fill(c2);vertex(8.11f,2.47f,10.48f);
      fill(c2);vertex(9.11f,4.94f,8.88f);
      fill(c3);vertex(19.64f,8.58f,13.21f);
    endShape();
    beginShape(QUAD_STRIP);
      fill(c3);vertex(19.64f,-8.58f,13.21f);
      fill(c4);vertex(32.23f,-8.49f,13.42f);
      fill(c4);vertex(32.83f,-4.24f,14.32f);
      fill(c3);vertex(19.57f,-4.29f,14.95f);
      fill(c3);vertex(19.86f,-0.00f,13.65f);
      fill(c4);vertex(32.81f,0.00f,13.79f);
      fill(c4);vertex(32.83f,4.24f,14.32f);
      fill(c3);vertex(19.57f,4.29f,14.95f);
      fill(c3);vertex(19.64f,8.58f,13.21f);
      fill(c4);vertex(32.23f,8.49f,13.42f);
    endShape();
    beginShape(QUAD_STRIP);
      fill(c4);vertex(32.23f,-8.49f,13.42f);
      fill(c5);vertex(42.61f,-2.84f,8.80f);
      fill(c5);vertex(44.19f,-1.42f,8.23f);
      fill(c4);vertex(32.83f,-4.24f,14.32f);
      fill(c4);vertex(32.81f,0.00f,13.79f);
      fill(c5);vertex(45.27f,0.00f,7.70f);
      fill(c5);vertex(44.19f,1.42f,8.23f);
      fill(c4);vertex(32.83f,4.24f,14.32f);
      fill(c4);vertex(32.23f,8.49f,13.42f);
     fill(c5);vertex(42.61f,2.84f,8.80f);
    endShape();
  }
  
pop();
}

// Bäh!


}
