Skip to content

Instantly share code, notes, and snippets.

View macklinu's full-sized avatar

Mackie Underdown macklinu

View GitHub Profile
@macklinu
macklinu / flickr.js
Last active December 11, 2015 19:08
D3 Flickr
d3.json("nhl.json", function(json) {
d3.select("body")
.selectAll("img")
.data(json.items)
.enter()
.append("img")
.attr("class", "nhl")
.attr("src", function (d) {return d.media.m});
});
@macklinu
macklinu / spinningCurve.pde
Last active December 12, 2015 03:09
spinning curve
// Spinning Curve
//
// p.js
/* @pjs pauseOnBlur="true"; */
void setup() {
size(600, 600);
smooth();
frameRate(15);
@macklinu
macklinu / mouseCursor.pde
Last active December 12, 2015 03:09
mouse cursor
// Mouse Cursor
//
// p.js
/* @pjs pauseOnBlur="true"; */
int circleX, circleY;
int circleSize = 200;
float mouseHoverDist;
int numClicks = 0;
@macklinu
macklinu / gist:5364219
Created April 11, 2013 15:16
arduino timer pseudocode
float t_random[numLeds]; // random timer
float t_reset[numLeds]; // reset timer
if (millis() - t_random[i] > t_reset[i]) { // when you've surpassed a random time for an LED
toggle_led[i]; // turn it on
t_reset[i] = millis(); // make the reset time the current time
t_random[i] = random(bottomRange, topRange); // create a new random timer value for that LED
}
@macklinu
macklinu / gist:5366648
Created April 11, 2013 19:53
check position of DPST switch
// check position of rocker function
// t = top pin connection to switch
// b = bottom pin connection to switch
int checkRocker(int t, int b) {
int top = digitalRead(t);
int bottom = digitalRead(b);
if (top == LOW && bottom == HIGH) return 0; // top position
else if (top == HIGH && bottom == HIGH) return 1; // middle position
else if (top == HIGH && bottom == LOW) return 2; // low position
}
@macklinu
macklinu / barcode.pde
Created April 11, 2013 22:18
use a barcode scanner to store a barcode as a string in Processing
String barcode = "";
void setup() {}
void draw() {}
void keyPressed() {
barcode+=key;
if (key == '\n') { // we've reached the end of the barcode
println(barcode);
@macklinu
macklinu / randomLED.ino
Last active December 16, 2015 03:09
an array of LEDs that turns on and off at random times (within a range)
const int numLeds = 4;
const int pins[] = {
2, 3, 4, 5};
long t_random[numLeds];
long t_reset[numLeds];
long top_range = 2000;
long bottom_range = 100;
int previous_led_state[numLeds];
int led_state[numLeds];
@macklinu
macklinu / givennames.py
Created April 24, 2013 01:23
HTML parsing python (output files for an installation piece)
#!/usr/bin/python
# get a list of androgynous names and write it to a .txt file
# requires BeautifulSoup library
# imports
from bs4 import BeautifulSoup
import urllib2
import sys
import os
/*
Serial Event example
When new serial data arrives, this sketch adds it to a String.
When a newline is received, the loop prints the string and
clears it.
A good test for this is to try it with a GPS receiver
that sends out NMEA 0183 sentences.
@macklinu
macklinu / Asteroid.pde
Last active December 23, 2015 11:49
Asteroids snippet
class Asteroid {
PVector location;
PVector velocity;
PVector acceleration;
float mass;
String tweet;
float x, y, w, h;
boolean hit;
boolean dead;
float hitTime, textTime;