Created
April 8, 2010 17:02
-
-
Save rhyolight/360283 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ORectangle = function(w,h) { | |
var width = w, height = h; | |
return { | |
getWidth: function() { return width; }, | |
getHeight: function() { return height; }, | |
setWidth: function(w) { width = w; }, | |
setHeight: function(h) { height = h; }, | |
area: function() { return width * height }, | |
toString: function() { | |
return '(' + this.getWidth() + 'X' + this.getHeight() + ')' | |
} | |
}; | |
}; | |
PositionedORectangle = function(w,h,xIn,yIn) { | |
var x = xIn, | |
y = yIn, | |
rect = new ORectangle(w,h), | |
me = { | |
getX: function() { return x; }, | |
setX: function(xIn) { this.x = xIn; }, | |
getY: function() { return y; }, | |
setY: function(yIn) { this.y = yIn; }, | |
distanceFrom: function(otherRect) { | |
return Math.sqrt( | |
Math.pow(this.getX() - otherRect.getX(), 2) | |
+ Math.pow(this.getY() - otherRect.getY(), 2) | |
); | |
}, | |
toString: function() { | |
return rect.toString() + ' at ' + this.getX() + ',' + this.getY(); | |
} | |
}; | |
return mixin(rect, me); | |
}; | |
ColoredPositionedORectangle = function(w,h,xIn,yIn,clr) { | |
var color = clr, | |
rect = new PositionedORectangle(w,h,xIn,yIn), | |
me = { | |
getColor: function() { return color; }, | |
setColor: function(clr) { this.color = clr; }, | |
toString: function() { | |
return color + ' ' + rect.toString() + ' at ' + this.getX() + ',' + this.getY(); | |
} | |
}; | |
return mixin(rect, me); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment