You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

7 years ago
  1. window.onload = function() {
  2. var video = document.getElementById('video');
  3. var canvas = document.getElementById('canvas');
  4. var context = canvas.getContext('2d');
  5. var trackerCyan = new tracking.ColorTracker(['cyan']);
  6. tracking.track('#video', trackerCyan, {
  7. camera: true
  8. });
  9. trackerCyan.on('track', function(event) {
  10. context.clearRect(0, 0, canvas.width, canvas.height);
  11. event.data.forEach(function(rect) {
  12. if (rect.color === 'custom') {
  13. rect.color = trackerCyan.customColor;
  14. }
  15. context.strokeStyle = rect.color;
  16. context.strokeRect(rect.x, rect.y, rect.width, rect.height);
  17. context.font = '11px Helvetica';
  18. context.fillStyle = "#fff";
  19. context.fillText('x: ' + rect.x + 'px', rect.x + rect.width + 5, rect.y + 11);
  20. context.fillText('y: ' + rect.y + 'px', rect.x + rect.width + 5, rect.y + 22);
  21. actualizePosCyan(rect);
  22. });
  23. });
  24. };
  25. function actualizePosCyan(rect){
  26. sineWaveCyan.frequency=600-rect.y;
  27. sineWaveCyan.volume=(rect.x/450);
  28. console.log(sineWaveCyan.frequency);
  29. }
  30. var sineWaveCyan = new Pizzicato.Sound({
  31. source: 'wave',
  32. options: {
  33. frequency: 440
  34. }
  35. });
  36. /*var ringModulator = new Pizzicato.Effects.RingModulator({
  37. speed: 30,
  38. distortion: 1,
  39. mix: 0.5
  40. });
  41. sineWave.addEffect(ringModulator);*/
  42. sineWaveCyan.volume=0.1;
  43. sineWaveCyan.play();
  44. /*var drum = new Pizzicato.Sound('./sounds/drum.mp3', function() {
  45. // Sound loaded!
  46. drum.loop=true;
  47. drum.play();
  48. });*/
  49. function silence(){
  50. sineWaveCyan.volume=0;
  51. }