Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle McDonald kylemcdonald

View GitHub Profile
@kylemcdonald
kylemcdonald / thin.h
Created Nov 1, 2011
morphological thinning for openFrameworks
View thin.h
#pragma once
#include "ofMain.h"
inline void thin(ofPixels& img) {
int w = img.getWidth(), h = img.getHeight();
int ia1=-w-1,ia2=-w-0,ia3=-w+1,ib1=-0-1,ib3=-0+1,ic1=+w-1,ic2=+w-0,ic3=+w+1;
unsigned char* p = img.getPixels();
vector<unsigned int> q;
for(int y = 1; y + 1 < h; y++) {
for(int x = 1; x + 1 < w; x++) {
int i = y * w + x;
@kylemcdonald
kylemcdonald / lineart.h
Created Nov 4, 2011
lineart rendering for openFrameworks
View lineart.h
#pragma once
#include "ofMain.h"
void drawModel(ofMesh& mesh) {
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), &mesh.getVerticesPointer()->x);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(ofVec3f), &mesh.getNormalsPointer()->x);
if(mesh.getNumIndices()){
glDrawElements(ofGetGLPrimitiveMode(mesh.getMode()), mesh.getNumIndices(), GL_UNSIGNED_INT, mesh.getIndexPointer());
}else{
View oneliner.fs
/*
GLSL fragment shader implementing the one line synthesis pattern.
http://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html
*/
#extension GL_EXT_gpu_shader4 : enable
const int width = 512; // assumes you're drawing at 512x512
void main() {
int t = int(gl_FragCoord.y) * width + int(gl_FragCoord.x);
int c = t*5&(t>>7)|t*3&(t*4>>10);// miiro
View ArduinoTemperatureFlashlight.ino
#include <i2cmaster.h>
#include "Wire.h"
#include "BlinkM_funcs.h"
const float lowReading = 75;
const float highReading = 110;
const int blinkm_addr = 0;
const unsigned char separatorCharacter = 255;
void setup(){
@kylemcdonald
kylemcdonald / combine.sh
Created Jan 5, 2012
Combine all static libraries in the current directory into a single static library.
View combine.sh
#!/bin/bash
read -p "Enter the name for the combined library: " name
for f in *.a
do
/usr/bin/ar x $f
done
rm *SYMDEF*
/usr/bin/ar rcs $name *.o
rm *.o
@kylemcdonald
kylemcdonald / MeshJitter.py
Created Jan 12, 2012
Rhino/Python script the randomly jitters mesh vertices along their normals, scaled by the face size.
View MeshJitter.py
import rhinoscriptsyntax as rs
import math, random
obj = rs.GetObject("Select mesh", rs.filter.mesh, True)
sigma = rs.GetReal("Gaussian sigma", .1)
vertices = rs.MeshVertices(obj)
faces = rs.MeshFaceVertices(obj)
normals = rs.MeshVertexNormals(obj)
if vertices and faces:
modified = []
View sketchup_downloader.rb
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'httparty'
unless ARGV[0] && ARGV[1]
puts "Usage: ruby sketchup_downloader.rb path/to/terms.csv path/to/folder"
exit 1
end
@kylemcdonald
kylemcdonald / scratchml.xml
Created Jan 22, 2012 — forked from jamiew/scratchml.xml
ScratchML draft spec v3
View scratchml.xml
<sml>
<!--
# SCRATCH MARKUP LANGUAGE, WORKING DRAFT
http://scratchml.com
* version -- minor versions for small changes, major for incompatibilities
* info -- general file metadata: author info, client info etc.
* turntable - hardware metadata
* mixer -- hardware metadata
@kylemcdonald
kylemcdonald / the-list-of-life.md
Created Apr 14, 2012
A short story about lists.
View the-list-of-life.md

THE LIST OF LIFE

By T. Q. McReilly-Wigglesworth

I stumbled onto this short story, written by a fictional author, embedded within a novel, after searching for a "list of unlistable things". It originally appeared in "FOOL THE GUESSER: A Novel Written in Two Weeks", which was written as part of the Iowa City Poetry Marathon in 2010. I've had trouble determining the author. The original text is available at the Marathon website but has been edited to correct for what appear to be OCR errors. - Kyle McDonald


I have a habit of making up lists. My very first list, which I wrote in first grade, was a list of all lists I wanted to make in the future. That list began with my second list, which was called "a list of my very first list." My third list came next, but I lost it soon after I made it. My fourth list was a list of lists I'd lost. My fifth was a list of things that might have been on my third list. My seventh was a l

@kylemcdonald
kylemcdonald / ofxGlobalUtils.h
Created Jun 22, 2012
openFrameworks utilities for working with the mouse and screen even when an app does not have focus
View ofxGlobalUtils.h
#pragma once
#include "ofGraphics.h"
#include "ofImage.h"
class ofGlobalListener {
public:
ofGlobalListener();
virtual void globalMouseDown(float x, float y) = 0;
};