Skip to content

Commit 892e85f

Browse files
authored
Merge pull request #4 from ianmunrobot/add-view-#3
closes #3 Add view
2 parents 48d0dda + 0a957c2 commit 892e85f

File tree

7 files changed

+335
-56
lines changed

7 files changed

+335
-56
lines changed

app/event-emitter.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

app/index.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
const Tone = require('tone')
2-
const EventEmitter = require('./event-emitter')
2+
3+
const socket = require('./socket')
4+
const spaceCircle = require('./views/spaceCircle')
5+
const coolBlobs = require('./views/coolBlobs')
36

47
StartAudioContext(Tone.context, '#test').then(function(){
58

69
})
710

811
const drums = require('./basic-beat')
912

10-
var socket = io(window.location.origin)
11-
let room = window.location.pathname.slice(1);
1213

13-
// put the socket on global scope (required for paperscript file to access and emit events)
14-
window.socket = socket
14+
const canvas = document.getElementById('paperCanvas');
15+
paper.setup(canvas);
16+
paper.install(window);
17+
18+
// const drums = require('./basic-beat')
19+
let room = window.location.pathname.slice(1);
1520

1621
// synthesizer memory
1722
let synthesizers = {}
@@ -50,8 +55,8 @@ socket.on('populateSynths', (ids) => {
5055
ids.forEach(id => {
5156
let newXSynth1 = new Tone.DuoSynth({harmonicity: 1.5}).chain(reverb)
5257
let newYSynth2 = new Tone.DuoSynth({harmonicity: 1.5}).chain(reverb)
53-
newXSynth1.volume.value = -12;
54-
newYSynth2.volume.value = -12;
58+
newXSynth1.volume.value = -15;
59+
newYSynth2.volume.value = -15;
5560
synthesizers[id] = {
5661
x: newXSynth1,
5762
y: newYSynth2
@@ -61,19 +66,55 @@ socket.on('populateSynths', (ids) => {
6166

6267
socket.on('mouseDown', (event) => {
6368
changeFrequency(event.id, 'x', event.x)
64-
changeFrequency(event.id, 'y', event.x * 1.5)
69+
changeFrequency(event.id, 'y', event.x * 1.5)
6570
attack(event.id)
6671
})
6772

6873
socket.on('mouseDrag', (event) => {
6974
// console.log(event);
7075
let amplitude = Math.abs(event.delta[1]) + Math.abs(event.delta[2])
7176
changeAmplitude(event.id, amplitude)
72-
7377
changeFrequency(event.id, 'x', event.x)
7478
changeFrequency(event.id, 'y', event.x * 1.5)
7579
})
7680

7781
socket.on('mouseUp', (event) => {
7882
release(event.id)
7983
})
84+
85+
// drawing tool
86+
87+
var tool = new Tool()
88+
tool.minDistance = 10;
89+
tool.maxDistance = 30;
90+
91+
tool.onMouseDown = (event) => {
92+
var outEvent = {
93+
id: socket.id,
94+
x: event.point.x,
95+
y: event.point.y,
96+
}
97+
socket.emit('mouseDown', outEvent);
98+
}
99+
100+
tool.onMouseDrag = (event) => {
101+
var outEvent = {
102+
id: socket.id,
103+
x: event.point.x,
104+
y: event.point.y,
105+
delta: event.delta,
106+
middlePoint: event.middlePoint,
107+
}
108+
socket.emit('mouseDrag', outEvent)
109+
}
110+
111+
tool.onMouseUp =(event) => {
112+
var outEvent = {
113+
id: socket.id,
114+
x: event.point.x,
115+
y: event.point.y,
116+
}
117+
socket.emit('mouseUp', outEvent)
118+
}
119+
120+
coolBlobs();

app/socket.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var socket = io(window.location.origin)
2+
3+
// put the socket on global scope (required for paperscript file to access and emit events)
4+
// window.socket = socket
5+
6+
module.exports = socket

app/views/coolBlobs.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
const socket = require('../socket')
2+
3+
module.exports = function() {
4+
var paths = {}
5+
var count = 20
6+
var radiusSize = 100;
7+
var shadowBlur = 100;
8+
9+
var path1 = new Path.Circle({
10+
center: [-150, 200],
11+
radius: radiusSize,
12+
fillColor: 'white',
13+
alpha: 0,
14+
shadowColor: '#00fca4',
15+
shadowBlur: 100,
16+
shadowOffset: [view.size.width, 0]
17+
});
18+
19+
var path2 = new Path.Circle({
20+
center: [-150, 200],
21+
radius: radiusSize,
22+
fillColor: 'white',
23+
alpha: 0,
24+
shadowColor: '#00acfc',
25+
shadowBlur: 100,
26+
shadowOffset: [view.size.width, 0]
27+
});
28+
29+
var path3 = new Path.Circle({
30+
center: [-150, 200],
31+
radius: radiusSize,
32+
fillColor: 'white',
33+
alpha: 0,
34+
shadowColor: '#00e003',
35+
shadowBlur: 100,
36+
shadowOffset: [view.size.width, 0]
37+
});
38+
39+
var path4 = new Path.Circle({
40+
center: [-150, 200],
41+
radius: radiusSize,
42+
fillColor: 'white',
43+
shadowColor: '#0011ff',
44+
shadowBlur: 100,
45+
shadowOffset: [view.size.width, 0]
46+
});
47+
48+
// path1.blendMode = 'darken';
49+
// path2.blendMode = 'darken';
50+
// path3.blendMode = 'darken';
51+
// path4.blendMode = 'darken';
52+
53+
var symbol1 = new Symbol(path1)
54+
var symbol2 = new Symbol(path2)
55+
var symbol3 = new Symbol(path3)
56+
var symbol4 = new Symbol(path4)
57+
58+
var symbols = [symbol1, symbol2, symbol3, symbol4]
59+
60+
for (var i = 0; i < count; i++) {
61+
// The center position is a random point in the view
62+
var center = new Point((view.size.width * -1 + view.size.width * ((i % 4) / 4)) + (view.size.width / 8), Math.random() * view.size.height);
63+
var placedSymbol = symbols[Math.floor(Math.random() * 4)].place(center);
64+
placedSymbol.speed = Math.random() * 4 - 2;
65+
}
66+
67+
view.onFrame = (event) => {
68+
for (var i = 0; i < count; i++) {
69+
var item = project.activeLayer.children[i];
70+
item.position.y = item.position.y + item.speed
71+
if (item.position.y > view.size.height + 60 || item.position.y < -60) item.speed *= -1
72+
}
73+
}
74+
75+
// Space Circle Path:
76+
77+
socket.on('mouseDown', function(event) {
78+
var circlePath = new Path.Circle({
79+
center: [event.x, event.y],
80+
radius: 20,
81+
fillColor: 'cyan',
82+
});
83+
// create memory queue
84+
if (!paths[event.id]) {
85+
paths[event.id] = [];
86+
}
87+
paths[event.id].push(circlePath)
88+
window.setTimeout(function() {
89+
itemTimeout(circlePath, event.id);
90+
}, 300);
91+
})
92+
93+
socket.on('mouseDrag', function(event) {
94+
var last = paths[event.id][paths[event.id].length - 1]
95+
var circlePath = new Path.Circle({
96+
center: [event.x, event.y],
97+
radius: 20 + event.delta[1] + event.delta[2],
98+
fillColor: last.fillColor,
99+
});
100+
circlePath.fillColor.hue += Math.floor(Math.random() * 4)
101+
paths[event.id].push(circlePath)
102+
window.setTimeout(function() {
103+
itemTimeout(circlePath, event.id)
104+
}, 300)
105+
});
106+
107+
socket.on('mouseUp', function() {
108+
109+
})
110+
111+
var itemTimeout = function(pathToRemove, id) {
112+
var alpha = 1.0
113+
var fadeOut = window.setInterval(function() {
114+
if (alpha === 0) {
115+
window.clearInterval(fadeOut)
116+
pathToRemove.remove()
117+
paths[id].unshift()
118+
} else {
119+
pathToRemove.fillColor.alpha -= 0.1
120+
alpha -= 0.1
121+
}
122+
}, 20)
123+
}
124+
}

0 commit comments

Comments
 (0)