Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Graphic(id, width, height){
  2.   this.id     = id;
  3.   this.width  = width;
  4.   this.height = height;
  5.  
  6.   var canvas    = document.createElement("canvas");
  7.   canvas.id     = this.id;
  8.   canvas.width  = this.width;
  9.   canvas.height = this.height;
  10.   document.body.appendChild(canvas);
  11. }
  12.  
  13. Graphic.prototype.init = function(){
  14.   var c    = document.getElementById(this.id);
  15.   this.ctx = c.getContext("2d");
  16. };
  17.  
  18. Graphic.prototype.drawRectangle = function(x, y, width, height){
  19.   this.ctx.fillStyle = "gold";
  20.   this.ctx.fillRect(x, y, width, height);
  21. };
  22.  
  23. Graphic.prototype.stick = function(points){
  24.   var canvas       = document.getElementById(this.id);
  25.   var widthCanvas  = canvas.clientWidth;
  26.   var heightCanvas = canvas.clientHeight;
  27.   var gap          = 0;
  28.   var nbrGap = points.length + 1;
  29.  
  30.   for(var i = 0; i < points.length; i++){
  31.     gap += 40;
  32.     this.ctx.fillStyle = "#e74c3c";
  33.     this.ctx.fillRect(gap, 500 - points[i], 25, points[i]);
  34.   }
  35. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement