/** * Esfera. * David Pena. * * Distribucion aleatoria uniforme sobre la superficie de una esfera. * * Modifications by subpixel (v3) */ /* * Modifications by subpixel: * v1: * removal of unused global arrays; * calculate end point of a hair as the hairLength distance from the hair base, not as a point at a fixed distance from the centre of the sphere (which causes hairs to stretch); * reverse Ymouse reactivity so ball spins in the direction of mouse movement instead of against it; * added start/pause functionality on mouse click event * v2: 2008-11-09 * renamed/repurposed some identifiers * Globals: cuantos -> NUM_HAIRS, lista[] -> HAIRS[], radio -> BASE_RADIUS, * hairmin/max -> MIN/MAX_HAIR_LENGTH, rx/ry -> RX/RY * class pelo -> class Hair * dibujar() -> draw() * new class Oscillator * Oscillator introduced for the radius of the inner sphere, the base of the "outer sphere" (the hairs), * and also the number of hairs displayed. * The inner sphere is now red so you can see it * Moving the mouse increases the "heart rate" of the inner sphere (which gradually slows down) * Moving the mouse also increases the base radius of the outer sphere based on the speed * v3: 2008-11-17 * Extracted class Hair and class Oscillator to separate files. * Removed redundant FRAME variable (can use global frameCount if necessary) * Added some keyboard controls. * [up]/[down] control outer sphere osciallation step * [z] toggles pause for inner sphere oscillator * [x] toggles pause for outer sphere oscillator * [c] toggles pause for hair count osciallator * Added some 3D text * Added some snaking tentacles; three new osciallators control parameters. */ import processing.opengl.*; // ------------------------------------------------------------ // Global variables // ------------------------------------------------------------ boolean looping = false; // Opening state of the sketch. Set true to open un-paused. int FRAME_RATE = 30; int NUM_HAIRS = 800; // Number of hairs Hair[] HAIRS; // Array/list of hairs float BASE_RADIUS; // Radius of the sphere float MIN_HAIR_LENGTH; // Minimum hair length float MAX_HAIR_LENGTH; // Maximum hair length float RX = 0; float RY = 0; Oscillator innerOscillator; // Oscillator for inner sphere Oscillator outerOscillator; // Oscillator for outer sphere (base of hairs) Oscillator countOscillator; // Oscillator for number of hairs to display Oscillator to1; Oscillator to2; Oscillator to3; PFont font; void init() { //E frame.setUndecorated(true); super.init(); } // ------------------------------------------------------------ // Main setup method. // ------------------------------------------------------------ void setup() { size(640, 480, OPENGL); // Set the canvas size, and use OpenGL rendering frameRate(FRAME_RATE); if (!looping) noLoop(); // Opportunity to open the sketch in a paused state BASE_RADIUS = height/4; // The central sphere is half the window height (radius therefore 1/4 window height) MIN_HAIR_LENGTH = BASE_RADIUS * 0.1; // Minimum hair length set proportionally to the sphere radius MAX_HAIR_LENGTH = BASE_RADIUS * 0.4; // Maximum hair length ser proportionally to the sphere radius HAIRS = new Hair[NUM_HAIRS]; // Initialise the array for the number of hairs for (int i=0; i