Advertisement
basictomonokai

Javascriptの中でProcessingの個別命令を呼び出す

Feb 18th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <meta charset="utf-8">
  5.   <title>Processing Demo</title>
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.16/processing.min.js"></script>
  7. </head>
  8. <body>
  9.   <canvas id="canvas" width="200" height="200"></canvas>
  10.  
  11.   <script>
  12.   function sketchProc(processing) {
  13.     processing.setup = function() {
  14.       processing.size(200, 200);
  15.       processing.background(125);
  16.       processing.fill(255,255,255);
  17.       processing.noLoop();
  18.     }
  19.  
  20.     processing.draw = function() {
  21.  
  22. for(var i=1 ; i<=400 ; i++) {
  23.     var rand1 = Math.floor( Math.random() * 256 )+1 ;
  24.     var rand2 = Math.floor( Math.random() * 200 )+1 ;
  25.     var rand3 = Math.floor( Math.random() * 199 )+1 ;
  26.     var rand4 = Math.floor( Math.random() * 10 )+10 ;
  27.     processing.fill(128, rand1, 255); // 塗りつぶしの色をランダムに決める
  28.     processing.ellipse(rand2, rand3, rand4, rand4); // ランダムな位置に円を描画
  29. };
  30.  
  31. processing.fill(255,255,255);
  32. processing.text("Hello World!", 20, 20);
  33. processing.rect(10, 10, 10, 10);
  34. processing.rect(80, 80, 10, 10);
  35. processing.ellipse(50,50, 50, 50);
  36.  
  37.  
  38.  
  39.     }
  40.   }
  41.  
  42.   var canvas = document.getElementById("canvas");
  43.   var p = new Processing(canvas, sketchProc);
  44.  
  45.  
  46.  
  47.  
  48.   </script>
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement