Created
May 28, 2018 22:18
-
-
Save AvneeshSarwate/75e3ea83cdd6e4487060150efd1bff95 to your computer and use it in GitHub Desktop.
prototyping arduino/led graphics on 60x50 pixel display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var w = 1280*1.2, | |
h = 720*1.2; | |
function setup(){ | |
createCanvas(w, h); | |
} | |
var cos = Math.cos; | |
var sin = Math.sin; | |
var sinN = n => (sin(n)+1)/2; //sin normalized [0-1] | |
var cosN = n => (cos(n)+1)/2; //cos normalized [0-1] | |
var xPix = 60; //number of pixels in x dimension on LED screen | |
var yPix = 50; //number of pixels in y dimension on LED screen | |
var xLen = w/xPix; //number of p5 pixels per LED pixel in x dimension | |
var yLen = h/yPix; //number of p5 pixels per LED pixel in y dimension | |
var frames = 0; //counter for number of frames | |
var dist = (x1, y1, x2, y2) => ((x1-x2)**2 + (y1-y2)**2)**(0.5); //normal distance function | |
//takes 0-1 scaled x and y coordinates and a frame number count, returns an RGB value color array (3 values [0-255]) | |
function colorMap1(x, y, time){ | |
return [((x * time/6.5) % 1) * 255, ((y * time/3.5) % 1) * 255, sinN(time/2.5) * 255]; | |
} | |
//same parameters as colorMap1 | |
function colorMap2(x, y, time){ | |
var circlepoint = [sinN(time/5), cosN(time/3)]; | |
return [dist(x,y,0.5,0.5)*255, dist(x,y,circlepoint[0],circlepoint[1])*255, sinN(time/11)*255]; | |
} | |
function draw(){ | |
clear(); | |
//loop through the pixels | |
for(var x = 0; x < xPix; x++){ | |
for(var y = 0; y < yPix; y++){ | |
//set the color for the pixels | |
var c = colorMap2(x/xPix, y/yPix, frames); | |
stroke(c); | |
fill(c); | |
rect(x * xLen, y*yLen, xLen, yLen); | |
} | |
} | |
frames++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment