Advertisement
RobertBerger

processingjs+libwebsocket_test_1

Jun 14th, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Conter-test</title>
  5. <canvas id="drawing"></canvas>
  6. <script src="processing-1.4.8.min.js"></script>
  7. <body>
  8. <script>
  9. var a0=0;
  10. var socket = new WebSocket('ws://127.0.0.1:7681',
  11.                            'dumb-increment-protocol');
  12.  
  13. // Add a connect listener
  14. socket.onmessage = function(event) {
  15.     a0 = parseInt(event.data);
  16.     console.log(event.data + ' ' + a0);
  17. //    socket.send("reset\n");
  18. };
  19.  
  20. function pad(num, size) {
  21.     var s = "000000000" + num;
  22.     return s.substr(s.length-size);
  23. }
  24.  
  25. function sketch(p) {
  26.   var minval = 9999;  
  27.   var maxval = 0;  
  28.   var r = 0;  
  29.   var f = null;  
  30.  
  31.   p.setup = function() {
  32.     p.background(0);
  33.     p.size(600, 300);
  34.     p.fill(202, 35, 55);
  35.     p.textSize(80);
  36.     p.text("Hello 1234!", 50, 100);
  37.   }
  38.  
  39.   p.draw = function() {
  40.      p.background(0);  
  41.     p.fill(0,127,127);  
  42.     p.text(pad(a0,4),p.width/4, p.height-110);
  43.     if (p.__mousePressed) {
  44.       minval = 9999;     maxval = 0;
  45.       p.text("MALAKIA",p.width/4,p.height-10);
  46.       socket.send("reset\n");
  47.     } else {
  48.       p.text("MULUKULA",p.width/4,p.height-10);
  49.     }
  50.   }
  51. }
  52.  
  53. var canvas = document.getElementById("drawing");
  54. var processingInstance = new Processing(canvas,sketch);
  55. </script>
  56.  
  57. </body>
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement