xxxxxxxxxx
66
// Co-created by hannahilea (https://hannahilea.github.io/)
// and David Brooks in a creative coding session while at the
// Recurse Center (www.recurse.com/)
// See polished version at https://hannahilea.com/projects/wonderful-world/
// earth borrowed from https://editor.p5js.org/codingtrain/sketches/tttPKxZi
let angle = 0;
let r = 200;
let earth;
let mySound;
function preload() {
soundFormats('mp3', 'ogg');
mySound = loadSound('world.mp3');
earth = loadImage('earth.jpg');
}
function setup() {
let cnv = createCanvas(500, 500, WEBGL);
cnv.mousePressed(canvasPressed);
textAlign(CENTER, CENTER);
}
function canvasPressed() {
// playing a sound file on a user gesture
// is equivalent to `userStartAudio()`
if (mySound.isPlaying()) {
mySound.pause();
} else {
mySound.play();
}
}
function draw() {
// Get our values!
rate = map(mouseY, 0, height, 0.5, 2);
let spinAmt;
if (mouseY < height/2) {
spinAmt = map(mouseY, 0, height, 0.001, 0.03, true)
// console.log(spinAmt);
} else {
// spinAmt = map(mouseY, 0, height, 0.02, 0.54, true)
spinAmt = map(mouseY-height/2, 0, height, 0.02, 0.5);
}
pan = map(mouseX, 0, width, -1., 1.);
let c = color(map(pan, -1, 1, 0, 256),
map(pan, -1, 1, 256, 0),
0);
// Draw stuff
background(c);
rotateY(angle);
lights();
fill(200);
noStroke();
angle += spinAmt;
texture(earth);
sphere(r);
// Update our audio
mySound.rate(rate);
mySound.pan(pan);
}