Advertisement
hak8or

In class procesing 3d sphere

Mar 12th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.73 KB | None | 0 0
  1.  
  2. void setup() {
  3.     // make it so sketch is the size of browser window
  4.     size(window.innerWidth, window.innerHeight);
  5.    
  6.     // Generate 90
  7.     circle_things;
  8. }
  9.  
  10. class Color_struct{
  11.     int red;
  12.     int blue;
  13.     int green;
  14.    
  15.     // Colors based on seperate RGB vals.
  16.     Color_struct(int _red, int _green, int _blue){
  17.         red = _red;
  18.         green = _green;
  19.         blue = _blue;
  20.     }
  21.    
  22.     // Base color with just one input.
  23.     Color_struct(int base_color){
  24.         red = green = blue = base_color;
  25.     }
  26. }
  27.  
  28. // Holds a blinking thing
  29. class Circle_thing{
  30.     Color_struct base_color = new Color_struct(50);
  31.     Color_struct end_color =  new Color_struct(150);
  32.     Color_struct current_color = new Color_struct(51);
  33.    
  34.     // How fast things update. For now, just the color.
  35.     final int speed = 3;
  36.    
  37.     // Which direction we are changing colors too.
  38.     boolean to_color_1 = false;
  39.    
  40.     // Current rotation in degrees
  41.     int rotation = 0;
  42.     boolean rotation_direction = true;
  43.    
  44.     // Width of the circle.
  45.     final int max_circle_width = 150;
  46.     int current_circle_width = 0;
  47.    
  48.     Circle_thing(int _rotation, int _current_color){
  49.         rotation = _rotation;
  50.         curent_color = new Color_struct(_current_color);
  51.     }
  52.    
  53.     // Updates the scene.
  54.     void update(){
  55.         // Check if we need to change the color direction.
  56.         if (current_color.red + speed > end_color.red && !to_color_1){
  57.             to_color_1 = true;
  58.         }
  59.    
  60.         // And the other direction.
  61.         if (current_color.red - speed < base_color.red && to_color_1){
  62.             to_color_1 = false;
  63.         }
  64.    
  65.         // Now change the color in the approriate direction.
  66.         if (!to_color_1) {
  67.             current_color.red = current_color.blue = current_color.green = current_color.red + speed;
  68.         } else {
  69.             current_color.red = current_color.blue = current_color.green = current_color.red - speed;
  70.         }
  71.        
  72.         // Flip use negative speed for rotating in other direction.
  73.         if (rotation > 180) { rotation_direction = !rotation_direction };
  74.         if (rotation < 0)   { rotation_direction = !rotation_direction };
  75.        
  76.         // Increment the rotation by speed;
  77.         if (rotation_direction) {rotation = rotation + speed; } else { rotation = rotation - speed; }
  78.        
  79.         // Do some rotation to width conversion.
  80.         current_circle_width = map(rotation, 0, 180, 0, max_circle_width);
  81.     }
  82.    
  83.     // Draws this circle thing.
  84.     void display(){
  85.         fill(current_color.red, current_color.blue, current_color.green);
  86.         ellipse(mouseX, mouseY, current_circle_width, 150);
  87.     }
  88. }
  89.  
  90. Circle_thing circle_thing = new Circle_thing(30, 90);
  91. ArrayList<Circle_thing> circle_things;
  92.  
  93. void draw() {
  94.     background(50, 50, 50);
  95.  
  96.     circle_thing.update(); 
  97.     circle_thing.display();
  98.  
  99.     // draw with mouse
  100.     // fill(255,0,0);
  101.     // ellipse(mouseX, mouseY, 20, 20);
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement