Skip to content

Instantly share code, notes, and snippets.

View jaycody's full-sized avatar

Jason Stephens jaycody

View GitHub Profile
@jaycody
jaycody / guardian.py
Last active November 11, 2017 06:56
Data validator : checks for positive integer
#! /usr/bin/python -tt
""" Guardian of the function threshold"""
def check_this(x):
"""Returns None if value is anything other than a positive int"""
if not isinstance(x, int):
return None, x
@jaycody
jaycody / pro_switchBlendModes.pde
Created March 31, 2017 22:45
keyPress switch blend modes
void keyPressed() {
// different blend modes
if (key == '1') {
depthImageBlendMode = BLEND;
println("Blend mode: BLEND");
}
else if (key == '2') {
depthImageBlendMode = ADD;
println("Blend mode: ADD");
@jaycody
jaycody / pro_keyCommands.pde
Created March 31, 2017 22:42
keyPressed and ready to go
// Handle keypress to adjust parameters
void keyPressed() {
println("*** FRAMERATE: " + frameRate);
// up arrow to move kinect down
if (keyCode == UP) {
kinecter.kAngle++;
kinecter.kAngle = constrain(kinecter.kAngle, 0, 30);
kinecter.kinect.tilt(kinecter.kAngle);
@jaycody
jaycody / pro_switchCase.pde
Last active February 20, 2017 09:36
switch_case
/* switch case example - unknown source:
When you want to create a simple menu or perhaps a program
that moves through different screens, the best way to do it
is by using a switch. This is clearer and faster than the
alternative if-else structure in these circumstances.
A switch will allow the user to easily move back and
forth through different screen, for example via keyboard
or mouse input. To keep things clearly readable,
my advise is to refer to seperate functions for each
@jaycody
jaycody / mocha_chai.test-template.js
Created November 11, 2016 23:27
template for automated unit tests with Mocha test runner and Chai assertion library
/* eslint-env node, mocha */
import "babel-core/external-helpers";
let chai = require('chai');
chai.should();
chai.expect();
import Point from '../src/oak-roots/Rect';
// calls each test
@jaycody
jaycody / validator.js
Created November 11, 2016 08:48
validation function for permissive inputs
//////////////////////////////
// Validate point & point-like objects
//////////////////////////////
static isPointLike(thing) {
// RETURNS true if exactly what we want
if (thing instanceof Point) return true;
//////////////////////
// RETURNS true if its kinda-like what we want, that is:
@jaycody
jaycody / p5-sliders.js
Last active September 22, 2018 12:21
create and update sliders in p5.js
/////SLIDERS//////
in setup()
slider = createSlider(min, max, initial);
slider.position(x,y);
slider.style('width', '80px');
in draw()
var val = slider.value();
background(val);
@jaycody
jaycody / pro_sort_vertices.pde
Created June 18, 2016 03:48
use Selection Sort to sort all of the vertices according to their relative angle from the center
/*thx shiffman!
http://shiffman.net/general/2011/12/23/night-4-sorting-the-vertices-of-a-polygon/
One solution for solving this problem is to always
sort all of the vertices according to their relative angle from the center.
Let’s say you calculate the center of the polygon as the average location of all vertices.
void mousePressed() {
vertices.add(new PVector(mouseX,mouseY));
}
@jaycody
jaycody / pro_record_frames.pde
Created June 18, 2016 03:41
record image sequence (start and stop)
void draw() {
// If we are recording call saveFrame!
if (recording) {
saveFrame("output/frames####.png");
}
}
void keyPressed() {
// If we press r, start or stop recording!
if (key == 'r' || key == 'R') {
@jaycody
jaycody / pro-trails_with_blendMode.pde
Last active May 13, 2016 18:50
trails with alpha rectangle - UPDATED with blendMode(SUBSTRACT);
/*trails with alpha rectangle - UPDATED with blendMode(SUBSTRACT);
There’s the quite well-known technique of painting a more or less transparent rectangle each frame (instead of a full background)
in order to get objects to create more or less long trails,
but if you set the alpha below a certain value, like 25, then you start getting smudgy ‘leftovers'
//shiffman's quick hack
fill(0,1);
rect(0,0,width, height);
//updated with blendMode