WingScreen: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
(air app code)
Line 96: Line 96:


== Desktop Emulator ==
== Desktop Emulator ==
[[File:HSV.jpg|960px]]


=== Main ===
=== Main ===

Revision as of 12:38, 11 September 2014

A side wing for teh screen

                                               /---------\
                                               |         |
                                  RGB LEDs --  *         |
                                           \   |         |
            .__                             -  *         |
    __  _  _|__| ____    ____                  |         |
    \ \/ \/ /  |/    \  / ___\                 *         |
     \     /|  |   |  \/ /_/  >                |         |
      \/\_/ |__|___|  /\___  /                 *         |
                    \//_____/                  |         |
   ('''' .|'', '||''| .|''|, .|''|, `||''|,    *         |
    `'') ||     ||    ||..|| ||..||  ||  ||    |         |
   `...' `|..' .||.   `|...  `|...  .||  ||.   *         |
                                               |         |
                                               *         |
                                               |         |
                                               *         |
                                               |         |
                                               *         |
                                               |         |
                      /---------\              *         |
                      |  micro  |              |         |
   USB-----|~|--------|  puter  |              *         |
                      \---------/              |         |
                             \                 *         |
                              \----------------|         |
                                               \---------/

StripHSV

Rainbeau test sketch for strip of addressable RGB LEDs.

Requires http://fastled.io/ library.

#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 12

// Spacing between pixel/color
#define HSV_PAD 22

// Delay between cycles
#define LOOP_DELAY 20

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 11
// #define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

byte count = 0;

void setup() { 
      // Uncomment/edit one of the following lines for your leds arrangement.
      FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
      
      // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<NEOPIXEL, DATA_PIN, RGB>(leds, NUM_LEDS);

      // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      
      FastLED.setBrightness(64);
}

void loop() { 
  // Rainbeau
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i] = CHSV(count + (i * HSV_PAD), 255, 255);
  }
  FastLED.show();
  
  count++;
  
  delay(LOOP_DELAY);
}

Desktop Emulator

HSV.jpg

Main

package 
{
	import flash.display.Screen;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.geom.Rectangle;
	
	/**
	 * ...
	 * @author thex
	 */
	public class Main extends Sprite 
	{
		private var wing:Wing;
		
		public function Main():void 
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			initUI();
		}
		
		private function initUI():void
		{			
			var appBounds:Rectangle = stage.nativeWindow.bounds;
			var screen:Screen = Screen.getScreensForRectangle(appBounds)[0];
			var screenSize:Rectangle = screen.bounds;
			
			/* Set in compile config
			  stage.nativeWindow.x = 0;
			  stage.nativeWindow.y = 0;
			*/
			  
			stage.nativeWindow.width = screenSize.width;
			
			wing = new Wing(12, screenSize.width, stage.stageHeight);
			addChild(wing);
		}
		
	}
	
}

Wing

package  
{
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.utils.getTimer;
	
	/**
	 * ...
	 * @author thex
	 */
	public class Wing extends Sprite 
	{
		private var count:int = 0;
		private var dots:Array = new Array();
		
		public function Wing(dotCount:int, wingWidth:int, wingHeight:int ) 
		{
			trace("Wing: " + wingWidth.toString() + ", " + wingHeight.toString());
			
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox(wingWidth, wingHeight, 1.571, 0, 0);			
			
			this.graphics.beginGradientFill(GradientType.LINEAR, [0x3f3f3f, 0x000000], [1, 1], [0, 220], matrix);
			this.graphics.drawRect(0, 0, wingWidth, wingHeight);
			
			count = dotCount;
			
			initDots();
			
			this.addEventListener(Event.ENTER_FRAME, frameHandler);
		}
		
		private function initDots():void
		{
			var dot:Dot;
			var xOff:Number = (width - (count * Dot.WIDTH)) / count;
			
			for (var i:int = 0; i < count; i++)
			{
				dot = new Dot();
				dot.x = i * (xOff + Dot.WIDTH) + (xOff/2);
				dot.y = height - Dot.HEIGHT;
				
				dot.draw(HSVColor.HSV2RGB(i * 30));
				
				addChild(dot);
				
				dots.push(dot);
			}
		}
		
		private function update():void
		{
			var dot:Dot;
			var hue:Number;
			
			var phase:Number = (getTimer() / 20);
			
			for (var i:int = 0; i < count; i++)
			{
				dot = dots[i];
				
				// Magiq time Rainbeau
				hue = i * 30 + phase;
				hue %= 360;
				
				dot.draw(HSVColor.HSV2RGB(hue));
			}
		}
		
		private function frameHandler(e:Event):void
		{
			update();
		}
		
	}

}

Dot

package  
{
	import flash.display.Sprite;
	import flash.filters.GlowFilter;
	
	/**
	 * ...
	 * @author thex
	 */
	public class Dot extends Sprite 
	{
		public static var WIDTH:int = 64;
		public static var HEIGHT:int = 16;
		
		private static var OFF_COLOR:int = 0xcfcfcf;
		
		private var glowFilter:GlowFilter;
		
		public function Dot() 
		{			
			draw(OFF_COLOR);
		}
		
		public function draw(color:int):void
		{
			this.graphics.beginFill(color);
			this.graphics.drawRect(0, 0, WIDTH, HEIGHT);
			
			glowFilter = new GlowFilter(color, 1, 96, 256, 24, 1);
			filters = [glowFilter];
		}
		
	}

}

HSVColor

package  
{
	/**
	 * ...
	 * @author thex
	 */
	public class HSVColor 
	{
		
		public function HSVColor() 
		{
			
		}
		
		public static function HSV2RGB(h:Number, s:Number = 1.0, v:Number = 1.0):int
		{
			/*
			 * 
			 *  Ported from:
			 *   http://www.cs.rit.edu/~ncs/color/t_convert.html
			 * 
			 *  h = 0-360
			 *  s = 0-1, v = 0-1
			 */
			
			var r:Number;
			var g:Number;
			var b:Number;
			
			var i:int;
			
			var f:Number;
			var p:Number;
			var q:Number;
			var t:Number;

			if( s == 0 ) {
				// achromatic (grey)
				r = g = b = v;
				return 256 * 256 * r + 256 * g + b;
			}

			h /= 60.0;			// sector 0 to 5
			i = Math.floor( h );
			f = h - i;			// factorial part of h
			p = v * ( 1 - s );
			q = v * ( 1 - s * f );
			t = v * ( 1 - s * ( 1 - f ) );

			switch( i ) {
				case 0:
					r = v;
					g = t;
					b = p;
					break;
				case 1:
					r = q;
					g = v;
					b = p;
					break;
				case 2:
					r = p;
					g = v;
					b = t;
					break;
				case 3:
					r = p;
					g = q;
					b = v;
					break;
				case 4:
					r = t;
					g = p;
					b = v;
					break;
				default:		// case 5:
					r = v;
					g = p;
					b = q;
					break;
			}
			
			r = Math.round(r * 255);
			g = Math.round(g * 255);
			b = Math.round(b * 255);
			
			return 256 * 256 * r + 256 * g + b;
		}
		
	}

}