Skip to content

Instantly share code, notes, and snippets.

View flordefuego's full-sized avatar

Flor de Fuego flordefuego

View GitHub Profile
@flordefuego
flordefuego / hydraP5jsGyroscope.js
Created February 17, 2023 20:30
Gyroscope example for Hydra with p5js
//p5 sketch from https://editor.p5js.org/remarkability/sketches/1D90zhu4a
p = new P5()
let permissionGranted = false;
let cx, cy;
cx = p.width/2;
cy = p.height/2;
// DeviceOrientationEvent, DeviceMotionEvent
if (typeof(DeviceOrientationEvent) !== 'undefined' && typeof(DeviceOrientationEvent.requestPermission) === 'function') {
// ios 13 device
DeviceOrientationEvent.requestPermission()
p = new P5({mode: 'WEBGL'})
p.draw= ()=>{
p.background(0,0,0,0);
p.orbitControl(5);
p.fill(255);
p.torus(150,15,5);
}
p.hide();
p = new P5()
p.draw= ()=>{
p.noStroke();
p.rect(p.width/2,p.height/2,100)
}
p.hide();
s0.init({src:p.canvas})
/*
_hydra_texture // cc ojack.xyz + teddavis.org 2021
edit hydra code within // hydraSandbox tags for changes w/o recompiling p5!
cheatsheets: https://ojack.xyz/hydra-functions/ + https://hydra-book.naotohieda.com/
*/
let img;
let genie;
function preload() {
img = loadImage('https://raw.githubusercontent.com/flordefuego/test_to_upload_stuff/main/genie.png');
genie = loadModel('https://raw.githubusercontent.com/flordefuego/test_to_upload_stuff/main/genie.obj')
//Animated gif with Ted Davis help
await loadScript("https://cdn.jsdelivr.net/npm/p5.glitch@latest/p5.glitch.js") //loads p5glitch library in Hydra
let glitch;
p = new P5() //comment this line after using it once
glitch = new Glitch(p);
img = p.loadImage('https://media3.giphy.com/media/v1.Y2lkPTc5MGI3NjExYzA0ZmE1ZDNmNTU1NzJkNDg3MWFmZWViZWVkOTk1OTEzMmQ5OWQ4OSZjdD1z/3o6fJ3xFENBRxVFvUc/giphy.gif', function(im) {
});
await loadScript("https://unpkg.com/total-serialism/build/ts.es5.min.js")
const Rand = TotalSerialism.Stochastic;
const rot = Rand.shuffle([ Math.PI / 2,0])
const tapeAmmount = Rand.shuffle([ 200, 90, 145])
const tapeAmmount2 = Rand.shuffle([90, 130, 50, 160, 100])
const rot2 = Rand.shuffle([ Math.PI / 2,0])
const ran = Rand.drunk(10, 5, 1, 4);
p = new P5();
let r;
let j;
let myText;
let myFeedback;
p.draw=()=>{
p.textSize(80);
p.clear();
p.rect((p.frameCount%p.width/2),p.height/2,100)
//Passing Clouds by Flor de Fuego
await loadScript("https://hyper-hydra.glitch.me/hydra-blend.js")
gradient(1)
.rotate(() => Math.PI / 2)
.blend(osc(10, 0, 0.5)
.modulateRotate(osc(3), 2), 0.9)
.glow(solid(0.8, 0.5, 1), 0.4)
//.hue(0.8)
//Adaptation from Echopon https://gist.github.com/echophon/1c7325f907b0e4eb1850e956c25dafd4
// to try this example, run the processing sketch in the folder processing.
// clicking on the sketch window sends the mouse x and y position to hydra via osc
// set port to listen to osc messages. default port is 57101
// 49162 is the default OSC port that Orca sends from
msg.setPort(49162)
//init a single letter object for Hydra to use & to match the msg we send from Orca
window.z = [0,0,0,0]
//update on msg received
let libs = ['https://unpkg.com/hydra-synth', 'includes/libs/hydra-synth.js',"https://cdn.jsdelivr.net/npm/[email protected]/dist/p5.asciify.min.js"]
// hydra canvas + init
let hc = document.createElement('canvas') // hydra canvas + custom size
hc.width = 640 // window.innerWidth // for full res
hc.height = 360 // window.innerHeight // for full res
let hydra = new Hydra({detectAudio: false,canvas: hc})
noize = noise // use noize() since noise() is taken by p5js
let pg // store hydra texture