Browse Source

Approaching some sort of working map controls

main
Luke Murphy 4 years ago
parent
commit
571ef246a3
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. BIN
      voicegardens/static/images/background.jpg
  2. BIN
      voicegardens/static/images/solarpunk.png
  3. 11
      voicegardens/static/styles.css
  4. 98
      voicegardens/static/voicegardens.js

BIN
voicegardens/static/images/background.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 KiB

BIN
voicegardens/static/images/solarpunk.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 MiB

11
voicegardens/static/styles.css

@ -1,8 +1,15 @@
/* Custom CSS styles */ /* Custom CSS styles */
html,
body { body {
margin: 0px; height: 100%;
overflow: hidden; }
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
} }
canvas { canvas {

98
voicegardens/static/voicegardens.js

@ -5,27 +5,23 @@
// //
var archiveUrl = window.location + "add-to-archive"; var archiveUrl = window.location + "add-to-archive";
var backgroundImage;
var canvas; var canvas;
var microphone; var microphone;
var mouseInitialDrag = false;
var newSoundJustRecorded = false; var newSoundJustRecorded = false;
var playButton; var playButton;
var recordButton; var recordButton;
var recorder; var recorder;
var recording; var recording;
var recordingTimeout = 30000; // 30 seconds (in milliseconds) var recordingTimeout = 30000; // 30 seconds (in milliseconds)
var screenH;
var screenW;
var screenX; var screenX;
var screenY; var screenY;
var shapes = []; var shapes = [];
var stopButton; var stopButton;
var toH; var toScreenX;
var toW; var toScreenY;
var toX; var zoom = 1;
var toY; var zoomSensitivity = 0.005;
var zoom = 0.01; // zoom step per mouse tick
function record() { function record() {
/** /**
* Starting recording. * Starting recording.
@ -97,11 +93,11 @@ function setupRecording() {
stopButton.mousePressed(stop); stopButton.mousePressed(stop);
playButton = createButton("play"); playButton = createButton("play");
playButton.position(10, 70); playButton.position(10, 75);
playButton.mousePressed(play); playButton.mousePressed(play);
playButton = createButton("archive"); playButton = createButton("archive");
playButton.position(10, 105); playButton.position(10, 110);
playButton.mousePressed(archive); playButton.mousePressed(archive);
} }
@ -134,8 +130,8 @@ class GeneratedShape {
this.w = 20; this.w = 20;
this.h = 20; this.h = 20;
this.x = random(width); this.x = windowWidth / 2;
this.y = random(height); this.y = windowHeight / 2;
this.xSpeed = 1.8; this.xSpeed = 1.8;
this.ySpeed = 1.8; this.ySpeed = 1.8;
@ -213,47 +209,30 @@ class GeneratedShape {
} }
} }
function preload() {
/**
* Pre-load images for the background.
**/
backgroundImage = loadImage("../static/images/solarpunk.png");
}
function setup() { function setup() {
/** /**
* The p5.js initial setup function. * The p5.js initial setup function.
**/ **/
createCanvas(windowWidth, windowHeight); createCanvas(windowWidth, windowHeight);
screenW = toW = backgroundImage.width; screenX = toScreenX = 0;
screenH = toH = backgroundImage.height; screenY = toScreenY = 0;
screenX = toX = screenW / 2;
screenY = toY = screenH / 2;
// setupRecording(); setupRecording();
// fill("red"); fill("red");
} }
function draw() { function draw() {
/** /**
* The p5.js draw loop. * The p5.js draw loop.
**/ **/
clear(); background("pink");
noStroke();
screenX = lerp(screenX, toScreenX, 0.1);
screenX = lerp(screenX, toX, 0.1); screenY = lerp(screenY, toScreenY, 0.1);
screenY = lerp(screenY, toY, 0.1); translate(screenX, screenY);
screenW = lerp(screenW, toW, 0.1);
screenH = lerp(screenH, toH, 0.1); scale(zoom);
image(
backgroundImage,
screenX - screenW / 2,
screenY - screenH / 2,
screenW,
screenH
);
if (newSoundJustRecorded === true) { if (newSoundJustRecorded === true) {
shapes.push(new GeneratedShape()); shapes.push(new GeneratedShape());
@ -274,35 +253,20 @@ function mouseWheel(event) {
/** /**
* Mouse wheel zoom handling. * Mouse wheel zoom handling.
**/ **/
var delta = -event.delta; zoom += zoomSensitivity * event.delta;
// zoom in
if (delta > 0) {
for (var i = 0; i < delta; i++) {
if (toW > 5 * width) return; // max zoom
toX -= zoom * (mouseX - toX);
toY -= zoom * (mouseY - toY);
toW *= zoom + 1;
toH *= zoom + 1;
}
}
// zoom out
if (delta < 0) {
for (var i = 0; i < -delta; i++) {
if (toW < width) return; // min zoom
toX += (zoom / (zoom + 1)) * (mouseX - toX);
toY += (zoom / (zoom + 1)) * (mouseY - toY);
toH /= zoom + 1;
toW /= zoom + 1;
}
}
} }
function mouseDragged(event) { function mouseDragged() {
/** /**
* Mouse drag movement handling. * Mouse drag movement handling.
**/ **/
toX += mouseX - pmouseX; toScreenX += mouseX - pmouseX;
toY += mouseY - pmouseY; toScreenY += mouseY - pmouseY;
}
function windowResized() {
/**
* Canvas re-draw handling.
**/
resizeCanvas(windowWidth, windowHeight);
} }

Loading…
Cancel
Save