/** * Esfera. * David Pena. * * Distribucion aleatoria uniforme sobre la superficie de una esfera. * * Modifications by subpixel: * 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 */ import processing.opengl.*; // ------------------------------------------------------------ // Global variables // ------------------------------------------------------------ boolean looping = false; // Opening state of the sketch. Set true to open un-paused. int NUM_HAIRS = 1200; // 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; float FRAME = 0; // Current frame number Oscillator OSC_INNER; // Oscillator for inner sphere Oscillator OSC_OUTER; // Oscillator for outer sphere (base of hairs) Oscillator OSC_COUNT; // Oscillator for number of hairs to display // ------------------------------------------------------------ // Main setup method. // ------------------------------------------------------------ void setup() { size(640, 480, OPENGL); // Set the canvas size, and use OpenGL rendering 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