Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Graphic(id, width, height){
- this.id = id;
- this.width = width;
- this.height = height;
- var canvas = document.createElement("canvas");
- canvas.id = this.id;
- canvas.width = this.width;
- canvas.height = this.height;
- document.body.appendChild(canvas);
- }
- Graphic.prototype.init = function(){
- var c = document.getElementById(this.id);
- this.ctx = c.getContext("2d");
- };
- Graphic.prototype.drawRectangle = function(x, y, width, height){
- this.ctx.fillStyle = "gold";
- this.ctx.fillRect(x, y, width, height);
- };
- Graphic.prototype.stick = function(points){
- var canvas = document.getElementById(this.id);
- var widthCanvas = canvas.clientWidth;
- var heightCanvas = canvas.clientHeight;
- var gap = 0;
- var nbrGap = points.length + 1;
- for(var i = 0; i < points.length; i++){
- gap += 40;
- this.ctx.fillStyle = "#e74c3c";
- this.ctx.fillRect(gap, 500 - points[i], 25, points[i]);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement