Skip to content

Instantly share code, notes, and snippets.

View bmoren's full-sized avatar

Ben Moren bmoren

View GitHub Profile
@bmoren
bmoren / nonRepRand.js
Created January 16, 2016 19:24
Non Repeating Random Number Utility, with loop callback and end-to-end elimination
/*
Create a new nonRepRand instance like this, you can have multiple, just use a diff variable name:
var numberGenerator = new nonRepRand(1,5);
use the .next() method to get the next number, see example below
.next() method, can take a callback which will fire when the nonRepRand generator loops around the set, ie. if nonRepRand(1,5), .next(callBack) will fire the callback after generating it's 5th value, the callback will be passed a value of true.
nonRepRand() will never give you end to end repeating numbers. for example if the 5th value of the set is a "3" and the first value of the next loop is a "3", nonRepRand will automatically get you a new value instead of a "3", so the values can never be next to one another.
@bmoren
bmoren / edgeLayer.js
Last active April 6, 2016 02:30
p5js sketch to layer 1pixel per sheet of paper for depth printing
var sideA;
var depth = 500; //choose how deep to make the guillotine slit scan
function preload(){
sideA = loadImage("usd.jpg");
}
function setup() {
createCanvas(3300,2550) //300 pixels per inch 8.5x11
pixelDensity(1); //turn off pixel density so calcualtions for page size are independent of screen pixel density
@bmoren
bmoren / app.js
Created April 28, 2016 19:29
Js/Jq basics
$(function(){
console.log("jquery is good!")
// //+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+Datatypes_~+~+~+~+~+~+~+~+~+~+~+~+
// //strings
// "string"
// 'string'
//
// 'the quick brown fox jumped over a log'
@bmoren
bmoren / non-rep-rand.js
Created August 22, 2016 02:34
non repeating random, more efficiently.
var pRandom = 1;
var total = 5; // top end of range
var rand = Math.floor( Math.random()*total ); //get a rand
while(rand == pRandom){ //are we the same, if so try again until we are not.
rand = Math.floor( Math.random()*total ); //get a new random if we are the same
console.log("try again");
}
pRandom = rand; //store the current random number to check against next time.
/* .field-content img{display:none}*/
/*#zone-branding-wrapper{border-bottom: 1px solid black}*/
h1{letter-spacing: 0}
#page-title{display:none}
#page-title{padding: 0px 0px 30px 10px}
#section-header, #section-content{background-color: white}
#zone-footer-wrapper{border-top: 1px solid black}
a:link, a, a:visited{color: blue; text-decoration:underline}
@bmoren
bmoren / mouse_not_moving.js
Created November 12, 2016 21:09
Mouse not moving
// +~+~+~+~+~ raw jQ/jS +~+~+~+~+~~+
var timeout = null;
$(document).on('mousemove', function() {
clearInterval(timeout);
timeout = setInterval(function() {
console.log('Mouse idle...');
//this is where you put the code to do things...
}, 200); //rate of interval
});
@bmoren
bmoren / index.html
Created February 7, 2017 15:03
p5.svg.js boilerplate
<html>
<head>
<meta charset="UTF-8">
<script language="javascript" type="text/javascript" src="p5.js"></script>
<script language="javascript" type="text/javascript" src="p5.svg.js"></script>
<script language="javascript" type="text/javascript" src="sketch.js"></script>
<!-- this line removes any default padding and style. you might only need one of these values set. -->
<style> body {padding: 0; margin: 0;} </style>
</head>
@bmoren
bmoren / highlow.js
Created March 8, 2017 04:11
basic p5js high low with keys
var currentNumber = 0
var previousNumber = 0
var score = 0
function setup() {
createCanvas(windowWidth,windowHeight)
}
@bmoren
bmoren / sketch.js
Last active June 25, 2020 19:13
getting started with color tracking in tracking.js + p5.js
var colors;
var capture;
var trackingData;
function setup() {
createCanvas(windowWidth,windowHeight)
capture = createCapture(VIDEO); //capture the webcam
capture.position(0,0) //move the capture to the top left
capture.style('opacity',0.5)// use this to hide the capture later on (change to 0 to hide)...
@bmoren
bmoren / updateJSON.php
Created April 28, 2017 15:47
append a json object to an array
<?php
$elements = json_encode( $_POST['data'],JSON_NUMERIC_CHECK ) . ',';
openlog("myScriptLog", LOG_PID | LOG_PERROR, LOG_LOCAL0);
syslog(LOG_INFO, $elements);
// $test = "{