Skip to content

Instantly share code, notes, and snippets.

View mattneary's full-sized avatar

Matt Neary mattneary

View GitHub Profile
@mattneary
mattneary / plot.js
Created November 13, 2011 16:30
Plot functions in JavaScript canvas. Arguments: function, canvas element, scaleWindow object
function plotF( f, elem, scaleWindow) {
var scaleWindow = scaleWindow || {
xMin: -8,
xMax: 8,
yMin: -8,
yMax: 8
};
scaleWindow.yMax = [-scaleWindow.yMin, (scaleWindow.yMin = -scaleWindow.yMax)][0]; //Swap Max/Min to make more intuitive
var pdy = elem.height/(scaleWindow.yMax-scaleWindow.yMin),
pdx = elem.width/(scaleWindow.xMax-scaleWindow.xMin);
@mattneary
mattneary / annotated.js
Created November 19, 2011 18:17
Decimal to Binary
function(
n, //Number
i,a //PLaceholders
){
for( //Loop
a=[i=0]; //Initialize (Avoid comma in assignment)
a[i]=n>>i&1, //Save bit
n>>i++; //Check if there are more bits and increment
);
return a
@mattneary
mattneary / annotated.js
Created November 19, 2011 18:44
Grayscale to Color
function toColor(grayscale) {
var hexes = [0, 64, 128, 192, 255],
answers = [[]];
for( var i = 0; i < 5; i++ ) {
//Cycle through first value
for( var j = 0; j < 5; j++ ) {
//Cycle through second value
for( var k = 0; k < 5; k++ ) {
//Cycle through third value
Test
Test
Test
Test
@mattneary
mattneary / index.html
Created January 1, 2012 00:35
api edited gist
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
@mattneary
mattneary / gist:1545783
Created January 1, 2012 00:39
api edited gist
We couldn’t find that file to show.
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>