Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>canvas</title>
  6. <style>
  7. canvas {
  8. border: 1px solid black;
  9. }
  10. </style>
  11. </head>
  12. <body>
  13. <canvas id="canvas" width="256" height="256"></canvas>
  14. <script>
  15.  
  16. var canvas = document.getElementById('canvas');
  17. var ctx = canvas.getContext("2d");
  18. var width = 256;
  19. var height = 256;
  20.  
  21. function drawDots(ctx,nodes) {
  22. ctx.save();
  23. for(node of nodes){
  24. let s = node.s;
  25. ctx.fillStyle=`rgba(${node.r*255|0}, ${node.g*255|0}, ${node.b*255|0},node.a)`;
  26. ctx.fillRect(node.x-(s/2),node.y-(s/2),s,s);
  27. }
  28. ctx.restore();
  29. }
  30. function drawEdges(ctx,edges) {
  31. ctx.save();
  32. for(edge of edges){
  33. let c1 = edge.a.data;
  34. let c2 = edge.b.data;
  35. ctx.strokeStyle=`rgba(${(c1.r+c2.r)*127|0}, ${(c1.g+c2.g)*127|0}, ${(c1.b+c2.b)*127|0},0.5)`;
  36. if(edge.stress){
  37. ctx.lineWidth=Math.max(1,(4-edge.stress)+1);
  38. // console.log("static");
  39. } else {
  40. ctx.lineWidth=1;
  41.  
  42. }
  43. ctx.beginPath();
  44. ctx.moveTo(edge.a.x*scale,edge.a.y*scale);
  45. ctx.lineTo(edge.b.x*scale,edge.b.y*scale);
  46. ctx.stroke();
  47. ctx.closePath();
  48. }
  49. ctx.restore();
  50. }
  51. function colorFromImage() {
  52. //idata
  53. let p = (Math.random()*idata.width*idata.height)|0;
  54. return {
  55. r:idata.data[p*4]/255,
  56. g:idata.data[p*4+1]/255,
  57. b:idata.data[p*4+2]/255
  58. }
  59. }
  60.  
  61. requestAnimationFrame(function loop(t){
  62. ctx.clearRect(0,0,width,height);
  63.  
  64. requestAnimationFrame(loop);
  65. });
  66.  
  67.  
  68. </script>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement