Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function draw1(){
  6. var canvas = document.getElementById('myCanvas');
  7. var context = canvas.getContext('2d');
  8.  
  9. context.save();
  10. context.translate(400,0);
  11. context.fillRect(0,0,100,100);
  12. context.restore();
  13. context.save();
  14. context.translate(0,400);
  15. context.fillRect(0,0,100,100);
  16. context.restore();
  17. context.save();
  18. context.translate(400,400);
  19. context.fillRect(0,0,100,100);
  20. context.restore();
  21. context.save();
  22. context.translate(0,0);
  23. context.fillRect(0,0,100,100);
  24. context.restore();
  25. context.beginPath();
  26. context.arc(250,250,25,2*Math.PI,0);
  27. context.closePath();
  28. context.stroke();
  29. }
  30.  
  31. function draw2(){
  32. var canvas = document.getElementById('myCan');
  33. var ctx = canvas.getContext('2d');
  34. var w = canvas.offsetWidth -2;
  35. var h = canvas.offsetWidth -2;
  36. alert("Wymiary płótna szachownicy: "+w+" x "+h);
  37. var szerokoscPola=Math.floor(w/8);
  38. var dlugoscPola=Math.floor(h/8);
  39. var wiersz=0;
  40. var krok=0;
  41. while(wiersz<h)
  42. {
  43. if(krok%2==0)
  44. {
  45. for (i=0; i<w; i=i+szerokoscPola*2)
  46. {
  47. ctx.fillRect(i,wiersz,szerokoscPola,dlugoscPola)
  48. }
  49. }
  50. else
  51. {
  52. for (i=0; i<w; i=i+szerokoscPola*2)
  53. {
  54. ctx.fillRect(i+szerokoscPola,wiersz,szerokoscPola,dlugoscPola)
  55. }
  56. }
  57.  
  58. wiersz=wiersz+dlugoscPola;
  59. krok++;
  60. }
  61. }
  62. </script>
  63. </head>
  64. <body>
  65. <canvas id="myCanvas" width="500" height="500" style="border:1px solid #d3d3d3;">
  66. Your browser does not support the HTML5 canvas tag.</canvas>
  67. <canvas id="myCan" width="1000" height="500" style="border:1px solid #d3d3d3;">
  68. Your browser does not support the HTML5 canvas tag.</canvas>
  69. <script>draw1();draw2();</script>
  70. <form>
  71. <input id="szer" type="text" placeholder="Podaj szerokość"><br/>
  72. <input id="dlug" type="text" placeholder="Podaj długość">
  73. <input id="submit" type="button" value="Rysuj!">
  74. </form>
  75.  
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement