BrU32

JS Canvas/Web Audio API Flying Through Space SImulation SRC

Sep 12th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <center>
  2. <canvas id="canv" width = "460" height = "360" style=background:lightgray>
  3. </canvas>
  4. </div>
  5. <svg viewBox="0 0 100% 100%" class="inv">
  6. <use xlink:href="#main" class="clear"></use>
  7. </svg>
  8. </h1>
  9. </section>
  10. <script>
  11. function RollSlott(){
  12. var Bar=parseFloat(Math.random()*101.9);
  13. var Barr=parseFloat(Math.random()*21.9);
  14. //document.body.innerHTML=(Bar+":"+Barr);
  15. var PlayLen=1.1;
  16. if(Bar!=0){
  17. Bar--
  18. }else if(Bar!=21){
  19. Bar++
  20. }
  21. var context = new AudioContext();
  22. oscillator=context.createOscillator();
  23. oscillator.type = 'sine';
  24. oscillator.frequency.value = Bar;
  25. oscillator.connect(context.destination);
  26. oscillator.start(0);
  27. //oscillator.stop(PlayLen);
  28. //oscillator.disconnect(PlayLen);
  29. }
  30. </script>
  31. <body onload="script:
  32. draw();
  33. var rolls=10;
  34. while(rolls!=0){
  35. rolls--;
  36. var Timer1 = setTimeout ('RollSlott();',0.03)
  37. }"/>
  38. <script>
  39. c = document.getElementById("canv");
  40. var ctx = c.getContext("2d");
  41. id = ctx.createImageData(460,360);
  42. function draw() {
  43. var w=c.width;
  44. var h=c.height;
  45. window.requestAnimationFrame(draw);
  46. var r;
  47. for (var p = 4 * (w * h - 4); p >= 1; p -= 4) {
  48. r = Math.random();
  49. id.data[p] = id.data[p+1] = id.data[p+2] = 255 * Math.pow(r, 985.6);
  50. id.data[p+3] = 255;
  51. }
  52. ctx.putImageData(id, 0, 0);
  53. }
  54. draw();
  55. </script>
  56. </body>
  57. </html>
  58. </center>
Advertisement
Add Comment
Please, Sign In to add comment