Guest User

Untitled

a guest
Jun 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <style>
  5. body {
  6. margin: 0px;
  7. padding: 0px;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <canvas id="myCanvas" width="1200" height="1000"></canvas>
  13. <script>
  14. function Point(x, y) {
  15. this.X = x;
  16. this.Y = y;
  17. }
  18. var canvas = document.getElementById('myCanvas');
  19. var context = canvas.getContext('2d'); // returns a drawing context on the canvas
  20. var alpha = Math.PI * 0.275,
  21. beta = -Math.PI * 0.35,
  22. ratioA = 0.775,
  23. ratioB = 0.45,
  24. MIN_LENGTH = 5;
  25.  
  26. function drawLine(rootPoint, r, theta) {
  27. context.beginPath(); // builds a line
  28. var endX = rootPoint.X + r*Math.cos(theta);
  29. var endY = rootPoint.Y + r*Math.sin(theta);
  30. var endPoint = new Point(endX, endY);
  31.  
  32. context.moveTo(rootPoint.X, rootPoint.Y); // initial position
  33. context.lineTo(endPoint.X, endPoint.Y); // end position
  34. context.stroke(); // draws line
  35.  
  36. if (r*ratioA < MIN_LENGTH || r*ratioB < MIN_LENGTH) {
  37. return;
  38. }
  39. drawLine(endPoint, r*ratioA, theta+alpha); // reduces length by ratio A
  40. drawLine(endPoint, r*ratioB, theta+beta); // adds angle beta
  41. }
  42. var startPoint = new Point(300, 500);
  43. drawLine(startPoint, 200, Math.PI * 3/2);
  44. </script>
  45. </body>
  46. </html>
Add Comment
Please, Sign In to add comment