// Source code licensed under Apache License 2.0.
// Copyright © 2019 William Ngan. (https://github.com/williamngan/pts)
window.demoDescription = "A silly and elaborate character that responds to sound. Music snippet taken from Space Travel Clichés composed by MrGreenH";
//// Demo code starts (anonymous function wrapper is optional) ---
(function() {
Pts.quickStart( "#pt", "#e2e6ef" );
// Note: use Sound.loadAsBuffer instead if you need support for Safari/iOS browser. (as of Apr 2019)
// See this example: http://ptsjs.org/demo/edit/?name=sound.freqDomain
var sound;
Sound.load( "/assets/spacetravel.mp3" ).then( s => {
sound = s.analyze(bins);
}).catch( e => console.error(e) );
var bins = 256;
var ctrls, radius;
var colors = ["#f06", "#62e", "#fff", "#fe3", "#0c9"];
// Draw play button
function playButton() {
if (!sound || !sound.playing) {
form.fillOnly("#f06").rect( [[0,0], [50,50]] );
form.fillOnly('#fff').polygon( Triangle.fromCenter( [25,25], 10 ).rotate2D( Const.half_pi, [25,25] ) );
} else {
form.fillOnly("rgba(0,0,0,.2)").rect( [[0,0], [50,50]] );
form.fillOnly("#fff").rect( [[18, 18], [32,32]] );
}
}
function getCtrlPoints( t ) {