Live Web Wk6: Midterm

Both are a work in progress, hoping to have a better “play” page soon: 

Code with socket io:

All code versions, including the mini tests I did for the oscillating sine waves + sound. ( i know i’m not using github properly, but this really helps me keep track of the different vs in a tangible way. will aim to use github better in the future):


Biggest thank you to Professor Shawn for helping me squash many bugs and explaining things so well! So much appreciation.

Screenshots of Process:

a.) Preliminary research online. Found some helpful diagrams.

Screenshot 2019-10-14 01.01.22

b.) First tried to code oscillating sine waves with varying frequencies. Also included a make frequency sound on hover function. Very bare bones test.

Screenshot 2019-10-14 14.39.38

c.) rough Sketch design for the site.

Screenshot 2019-10-14 01.02.08

d.)Tried a bunch of things out with making sine waves, used the web audio api, and really tried to understand how socket io works. I worked on the html, css + js part first before doing the socket io stuff. I definitely need to work on the “play” page more.

Questions + Answers:

  • Why does the oscillator.stop() work when I do mouseout? Read somewhere that you can not call the “start()” function for oscillators more than once? True???
    • Answer (Thank you Professor Shawn!): yes! need to create oscillator each time! also need to go through for loop to stop all elements.Screenshot 2019-10-15 12.15.49.png
      Screenshot 2019-10-15 13.01.19
  • I was trying to make the sine waves animate when user clicks. The “clearRect()” in javascript allows for animations because it redraws the background BUT it makes a white background. So I couldn’t overlap the sine waves without having the white background cover up the previously drawn one. Is there a way to get a transparent background with “clearRect()”? Or what’s a good work around?
    • Answer: have to add all sine waves into one canvas. No way of overlapping canvases with animation over it (without getting the background).
  • Trying to access a variable within a function to have as a global variable. Why won’t it work though? I added a “return” but it keeps saying it is undefined when I console.log it outside of the function.
    • Answer: didn’t have much to do with making a global var. had to do with adding a removing my click event listener. Have to remove the event listener if it is not the one clicked on. Shawn wrote the snippet below!Screenshot 2019-10-15 12.19.15.png

Bits of Research:

  • A source
  • The highest frequency that most humans can hear is 20,000 cycles per second or 20,000 Hz.
  • “Sound travels much slower than light. The audible sound spectrum consists of sounds between frequencies of 20 Hz and 20,000 Hz. These waves are very large and very slow compared to light waves. Sound waves are approximately 1,000,000,000,000 times larger than light waves.”
  • The pitch of the note A has a frequency of 440 Hz.
  • Sound and color are produced differently. Sound comes from an object that acts mechanically to produce a sound. But objects appear colored because of the interaction of white light with the object. For ex: when light hits an object, the object absorbs certain parts of the light; it absorbs all the colors but blue. The light leaving the object would then contain whatever color is left, in this case blue.

Resources for Web Audio API: 

Resources for JS, Canvas & Animation: 

Resources for Start + Stop Web Audio API Oscillator on Hover (had issues with this):

Resources for Mouse Movement:

Resources for my CSS Wave Animation (Homepage):

Resources for Socket io:

Resources for JS + CSS Animations: