/** * Quemaduras del Sol Simulator * * June 2011 Paul Williamson */ static final int NUM_LEDs = 40; static final int NUM_SEGS = 16; static final int SUN_BRIGHTNESS = 100; // 0 - 255, where 255 is brightest static final int RAYS_BRIGHTNESS = 100; // 0 - 255, where 255 is brightest static final int FRAME_RATE = 30; static final int NUM_PATTERNS = 3; // Dark image of the sun shape to use as a background PImage sunImage; // Image of each of the EL wire segments illuminated PImage[] raysImages = new PImage[NUM_SEGS]; /* Pixel coordinates of each LED. 0 - 15 are the inner circle, 16-39 are the outer vertices starting at the top and going clockwise */ int[] LEDsX = { 439, 508, 558, 579, 579, 552, 500, 438, 367, 300, 246, 220, 220, 249, 300, 360, 398, 457, 482, 521, 659, 634, 758, 679, 608, 690, 650, 491, 402, 250, 316, 304, 147, 137, 185, 100, 40, 139, 147, 314 }; int[] LEDsY = { 223, 251, 300, 369, 441, 500, 553, 583, 580, 553, 502, 435, 361, 297, 246, 220, 40, 150, 188, 117, 145, 284, 399, 508, 491, 553, 652, 637, 760, 651, 603, 647, 647, 539, 486, 507, 397, 295, 142, 155 }; // Current value of each LED. Set to black for off. Same order as above. color[] LEDs = new color[NUM_LEDs]; // Current value of each EL wire segment. true = lit, false = dark. // starting at the top and going clockwise boolean[] wireSegs = new boolean[NUM_SEGS]; void setup() { size(800,800); frameRate(FRAME_RATE); sunImage = loadImage("sun_background_800.png"); raysImages[ 0] = loadImage("ray0.png"); raysImages[ 1] = loadImage("ray1.png"); raysImages[ 2] = loadImage("ray2.png"); raysImages[ 3] = loadImage("ray3.png"); raysImages[ 4] = loadImage("ray4.png"); raysImages[ 5] = loadImage("ray5.png"); raysImages[ 6] = loadImage("ray6.png"); raysImages[ 7] = loadImage("ray7.png"); raysImages[ 8] = loadImage("ray8.png"); raysImages[ 9] = loadImage("ray9.png"); raysImages[10] = loadImage("raya.png"); raysImages[11] = loadImage("rayb.png"); raysImages[12] = loadImage("rayc.png"); raysImages[13] = loadImage("rayd.png"); raysImages[14] = loadImage("raye.png"); raysImages[15] = loadImage("rayf.png"); noStroke(); // Start with everything turned off for (int i = 0; i < NUM_LEDs; i++) LEDs[i] = 0; for (int i = 0; i < NUM_SEGS; i++) wireSegs[i] = false; } void draw() { // Run the simulated Arduino program nextFrame(); // Start with a fresh background image each time. tint(SUN_BRIGHTNESS); image(sunImage, 0, 0); noTint(); // Draw all the LEDs for (int i = 0; i< NUM_LEDs; i++) { fill(LEDs[i]); ellipse(LEDsX[i], LEDsY[i], 10, 10); } //!!! Draw all the EL wire segments tint(RAYS_BRIGHTNESS); for (int i = 0; i < NUM_SEGS; i++) { if (wireSegs[i]) { // This segment is illuminated, so draw it. image(raysImages[i], 0, 0); } } noTint(); println(frameRate); } /* This program runs at the frame rate and: * loads the LED colors into LEDs[] * loads the EL Wire states into wireSegs[] Any kind of logic is OK here, but for the moment we will do the following: * run each pattern until it declares itself finished by returning 1 */ //int frameNumber = 0; int pattern = 0; void nextFrame() { if (pattern >= NUM_PATTERNS) pattern = 0; switch(pattern) { case 0: pattern += pattern_all_on(); break; case 1: pattern += pattern_spinny(); break; case 2: pattern += pattern_blinky(); break; } } // Variables shared among the patterns should be left at zero. int pattern_counter = 0; // This pattern just turns everything on for a while. int pattern_all_on() { if (pattern_counter == 0) { for (int i = 0; i < NUM_LEDs; i++) LEDs[i] = color(int(random(0,255)), int(random(0,255)), int(random(0,255))); for (int i = 0; i < NUM_SEGS; i++) wireSegs[i] = true; } if (pattern_counter == FRAME_RATE * 2) { pattern_counter = 0; return 1; } else { pattern_counter += 1; return 0; } } int pattern_spinny() { if (pattern_counter == 0) // start with all dark { for (int i = 0; i < NUM_LEDs; i++) LEDs[i] = 0; for (int i = 0; i < NUM_SEGS; i++) wireSegs[i] = false; } int whichLED = pattern_counter % NUM_LEDs; int whichSeg = pattern_counter % NUM_SEGS; LEDs[whichLED] = 0; LEDs[(whichLED + 1) % NUM_LEDs] = color(int(random(0,255)), int(random(0,255)), int(random(0,255))); wireSegs[whichSeg] = false; wireSegs[(whichSeg + 1) % NUM_SEGS] = true; pattern_counter += 1; if (pattern_counter == 144) { pattern_counter = 0; return 1; } else { return 0; } } int pattern_blinky() { color inner_circle_color = color(int(random(0,255)), int(random(0,255)), int(random(0,255))); color outer_halo_color; if (pattern_counter % 20 < 10) outer_halo_color = color(int(random(0,255)), int(random(0,255)), int(random(0,255))); else outer_halo_color = 0; for (int i = 0; i < 16; i++) // LEDs in the inner circle LEDs[i] = inner_circle_color; for (int i = 16; i < NUM_LEDs; i++) // LEDs in the outer halo LEDs[i] = outer_halo_color; if (pattern_counter % 20 == 0) for (int i = 0; i < NUM_SEGS; i++) wireSegs[i] = true; else if (pattern_counter % 20 == 10) for (int i = 0; i < NUM_SEGS; i++) wireSegs[i] = false; pattern_counter += 1; if (pattern_counter == 300) { pattern_counter = 0; return 1; } else return 0; }