Skip to content

Instantly share code, notes, and snippets.

View bmoren's full-sized avatar

Ben Moren bmoren

View GitHub Profile
@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 / 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
});
/* .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 / 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.
@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 / 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 / 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 / idlestate.js
Created November 17, 2015 18:30
idle state for mouse movement in p5.js
//if the mouse is not moving for x time then do something.
mouseIsMoving = false;
function setup(){
createCanvas(windowWidth,windowHeight);
}
function draw() {
@bmoren
bmoren / sketch.js
Last active October 14, 2015 05:14
Rectangle Rectangle Collision p5js
var posx,posy, size
var times = 0
function setup() {
createCanvas(windowWidth,windowHeight);
posx = width/2
posy = height/2
size = 100;
meSize = 100;
@bmoren
bmoren / app.js
Created October 1, 2015 23:04
jQuery demo
//init jQuery to do things once the DOM (page) is ready.
$(function(){ // fucntion aka. do something NOW //dont comment me out!
// alert("hi han solo") //a good way to check that everything is working properly at the start.
/*
//this is the first basic example, cool!
$("#juju").hide(); //hide juju at the beginning