Created
October 9, 2018 19:16
-
-
Save danvers/33d444dae41fbe9228278a39a3f35e1e to your computer and use it in GitHub Desktop.
shout a random letter and find a match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0> | |
<style> body {padding: 0; margin: 0 auto;} </style> | |
<script src="p5.min.js"></script> | |
<script src="addons/p5.dom.min.js"></script> | |
<script src="addons/p5.sound.min.js"></script> | |
<script src="sketch.js"></script> | |
<style type="text/css"> | |
html, body { | |
height: 100%; | |
} | |
body { | |
margin: 0; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} | |
</style> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Shout at the computer, to let this script stop | |
* Just a basic script on audio interfaces | |
*/ | |
var font, fontsize = 32 | |
var mic; | |
function preload() { | |
font = loadFont('assets/Museo_Slab_500_2.otf'); | |
} | |
function setup() { | |
var cnvs = createCanvas(690, 600); | |
mic = new p5.AudioIn(); | |
mic.start(); | |
cnvs.mouseClicked(resetSketch); | |
} | |
function resetSketch(){ | |
textFont(font); | |
textSize(fontsize); | |
textAlign(CENTER, CENTER); | |
frameRate(10); | |
background(255); | |
translate(0,200); | |
micLevel = mic.getLevel(); | |
if(micLevel >0.1){ | |
frameRate(0); | |
} | |
var gap = 52; | |
var margin = 10; | |
push(); | |
translate(margin * 4, margin * 4); | |
var counter = 65; | |
var rnd = floor(random(65,90)); | |
for (y = 0; y < height - gap; y += gap) { | |
for (x = 0; x < width - gap; x += gap) { | |
if(counter > 90) break; | |
var letter = char(counter); | |
if(counter == rnd){ | |
fill(255,0,255); | |
}else{ | |
fill(111); | |
} | |
text(letter, x, y); | |
counter++; | |
} | |
} | |
pop(); | |
} | |
function draw() { | |
resetSketch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment