summaryrefslogtreecommitdiff
path: root/docs/dymaxion/soundmanagerv297a-20101010/demo/animation-2b/script/animation.js
blob: 61d2382b7f2ffa651f0fdc1d2f15325267298dd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
soundManager.flashVersion = 9;
soundManager.url = '../../swf/';
soundManager.useHighPerformance = true;
soundManager.wmode = 'transparent';
soundManager.debugMode = false;

var points = [];
var o = null;
var lastX = 0;
var lastY = 0;
var threshhold = 4;
var threshMax = 32;
var noise = null;
var screenX = 0;

function doPaint(e) {
  var x = (e||event).clientX;
  var y = (e||event).clientY;
  var diff = Math.max(Math.abs(x-lastX),Math.abs(y-lastY));
  if (diff>threshhold) {
    lastX = x;
    lastY = y;
    points.push(new Point(x,y,Math.min(diff/(32),3)));
  }
  return false;
}

function stopPaint() {
  document.onmousemove = null;
  document.onmouseup = null;
  // soundManager.play('up');
}

function startPaint(e) {
  // soundManager.play('down');
  document.onmousemove = doPaint;
  document.onmouseup = stopPaint;
  lastX = (e||event).clientX;
  lastY = (e||event).clientY;
  screenX = (window.innerWidth?window.innerWidth:document.documentElement.clientWidth||document.body.clientWidth);
  e?e.stopPropagation():event.returnValue = false;
  return false;
}

function initPoints() {
  o = document.createElement('img');
  o.src = 'image/point.png';
  o.className = 'point';
  document.onmousedown = startPaint;
  document.onmouseup = stopPaint;
}

function Point(x,y,scale) {
  var self = this;
  this.data = {
    x: x,
    y: y,
    scale: scale,
    scalePX: parseInt(32*scale)
  }
  this.o = o.cloneNode(false);
  this.o.style.left = (x-(this.data.scalePX/2))+'px';
  this.o.style.top = (y-(this.data.scalePX/2))+'px';
  this.o.style.width = this.o.style.height = this.data.scalePX+'px';
  var screenX2 = parseInt(screenX/2);
  noise.play({volume:parseInt(Math.min(1,scale/3)*100),pan:(x<screenX2?(screenX2-x)/screenX2*-100:(x-screenX2)/screenX2*100)});
  document.body.appendChild(this.o);
}

soundManager.onload = function() {
  noise = soundManager.createSound({
    id:'noise',
    url:'../animation/audio/fingerplop.mp3',
    multiShot: true,
    autoLoad: true
  });
  soundManager.createSound({
    id:'down',
    url:'../_mp3/click-low.mp3',
    multiShot: true,
    autoLoad: true
  });
  soundManager.createSound({
    id:'up',
    url:'../_mp3/click-high.mp3',
    multiShot: true,
    autoLoad: true
  });
  initPoints();
}

soundManager.onerror = function() {
  alert('d\'oh, something didn\'t work - SM2 failed to start.');
}