> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.dwfK6-Hdzga/rev.738
 * 
 * authors: 
 *   
 *   
 *   
 *   Jay McGavren
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   
 *   

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// This sketch builds on a prior work, "Modified clone of 'Untitled Sketch'", created by cathy
// http://studio.sketchpad.cc/sp/pad/view/ro.9ZZTlCLOV1ApR/rev.743

// This sketch builds on a prior work, "Untitled Sketch", created by andor & jbuck & [unnamed author]
// http://sketchpad.cc/sp/pad/view/ro.Op7D7jlSYfN/rev.300



/*
  Andor Salga
  Sol
  Processing compliant
*/

import processing.opengl.*;

float rotSun = 0.0;
float rotEarth = 0.0;
float rotMoon = 0.0;
float zoom = 0;
PFont infoFont;

int COLOR_MAX = 255;
int XYZ_MAX = 255 * 3;

RangedValue red = new RangedValue(0, COLOR_MAX, 0.1, 0);
RangedValue green = new RangedValue(0, COLOR_MAX, 0.05, 150);
RangedValue blue = new RangedValue(0, COLOR_MAX, 0.04, 100);
RangedValue lightX = new RangedValue(0, XYZ_MAX, 0.1, 450);
RangedValue lightY = new RangedValue(0, XYZ_MAX, 0.1, 0);
RangedValue lightZ = new RangedValue(0, XYZ_MAX, 0.1, 300);
RangedValue shine = new RangedValue(0, 5, 0.002, 0);
RangedValue cameraX = new RangedValue(0, XYZ_MAX, 0.1, 150);
RangedValue cameraY = new RangedValue(0, XYZ_MAX, 0.1, 0);
RangedValue cameraZ = new RangedValue(0, XYZ_MAX, 0.1, 100);

void setup(){
  size(400, 400, OPENGL);
  noStroke();
  infoFont = createFont("Arial", 28);
  textFont(infoFont);
}

void displayText(myString){
  fill(25, 70, 20);
  textFont(infoFont); 
  text(myString, 0, 30); 
}

void draw()
{
  background(0);
  lightSpecular(red.getValue(), blue.getValue(), green.getValue());
  
  pointLight(200, 200, 200, lightX.getValue(), lightY.getValue(), lightZ.getValue());

  specular(204, 102, 0);
  shininess(shine.getValue());

  // push matrix to center of the viewport
  pushMatrix();
  translate(width/2, height/2, 150 + zoom);
  
  // draw the sun
  fill(255,0,0);
  rotSun += 0.005;
  rotateX(rotSun);
  rotateY(rotSun);
  box(60);
  
  // push on another matrix and rotate and trans
  pushMatrix();
  rotateY(rotEarth += 0.01);
  translate(0, 0, 80);
  
  fill(25, 70, 20);
  
  sphereDetail(int(zoom + 16));
  box(25);
  
  pushMatrix();
  rotateZ(rotMoon += 0.08);
  translate(0, 40, 0);
  fill(0, 0, 128);
  box(10);

  popMatrix();
  popMatrix();
  popMatrix();
}


class RangedValue {

  float value, increment, max, min;
  RangedValue(float newMin, float newMax, float newIncrement, float newValue) {
    min = newMin;
    max = newMax;
    increment = newIncrement;
    value = newValue;
  }
  
  float getValue() {
    if (value < min) {
        value = min;
        increment = abs(increment);
    }
    else if (value > max) {
        value = max;
        increment = abs(increment) * -1;
    }
    value = value + increment;
    return value;
  }
  
}