Advertisement
Guest User

Untitled

a guest
Mar 11th, 2014
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Rectangle(x, y, width, height) {
  2.    
  3.     this.x = x;
  4.     this.y = y;
  5.     this.width = width;
  6.     this.height = height;
  7.    
  8.     this.boxColor = "red";
  9. }
  10.  
  11. Rectangle.prototype.middle = function() { return { x: this.x + this.width * 0.5, y: this.y + this.height * 0.5 }; }
  12.  
  13. Rectangle.prototype.contains = function(point) {
  14.  
  15.     if (point.x > this.x && point.x < this.x + this.width &&
  16.         point.y > this.y && point.y < this.y + this.height) {
  17.        
  18.             return true;
  19.         }
  20.     return false;
  21. }
  22.  
  23. Rectangle.prototype.draw = function() {
  24.    
  25.     context.fillStyle = this.boxColor;
  26.     context.fillRect(this.x,this.y,this.width,this.height);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement