Advertisement
Guest User

Untitled

a guest
May 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
  5. <title>Drawing</title>
  6. </head>
  7. <body ng-app = "canvasDrawing2" ng-controller = "canvasController">
  8. <canvas id="mainCanvas" width="600" height="300" style="border: 1px solid black"></canvas>
  9. <div>
  10. <input type = "button" value = "Start" ng-click = "draw()"/>
  11. <input type = "button" value = "Stop" ng-click = "stop()"/>
  12. </div>
  13. </body>
  14. </html>
  15. var app = angular.module("canvasDrawing2",[]);
  16. app.controller("canvasController",function($scope){
  17. $scope.ctx = document.getElementById("mainCanvas").getContext("2d");
  18. $scope.draw = function(){
  19. var colors = [255,0,0];
  20. for(var i = 25; i < 300; i+=50){
  21. for(var k = 25; k < 600; k+=50){
  22. $scope.ctx.beginPath();
  23. $scope.ctx.arc(k, i, 25, 0, 2*Math.PI);
  24. $scope.ctx.fillStyle = "rgb("+ colors[0] +","+ colors[1] + ","+ colors[2] +")";
  25. if(colors[0] == 255){
  26. colors = [0,255,0];
  27. }
  28. else if(colors[1] == 255){
  29. colors = [0,0,255];
  30. }
  31. else{ colors = [255,0,0];}
  32. $scope.ctx.stroke();
  33. $scope.ctx.fill();
  34. $scope.ctx.closePath();
  35. }
  36. }
  37. };
  38. $scope.stop = function(){ $scope.ctx.clearRect(0,0, 600, 300);};
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement