Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- class Shape
- {
- constructor(x, y) //define coordenadas da forma
- {
- this.x = x;
- this.y = y;
- }
- toString()
- {
- return "(" + this.x + ", " + this.y + ")";
- }
- isCircle()
- {
- return 0;
- }
- isRectangle()
- {
- return 0;
- }
- }
- class Rectangle extends Shape
- {
- constructor(x, y, width, height)
- {
- super(x,y);
- this.width = width;
- this.height = height;
- }
- draw_rectangle(ctx){
- ctx.fillStyle = "#ff0000";
- ctx.fillRect(this.x, this.y, this.width, this.height);
- }
- isRectangle()
- {
- return 1;
- }
- }
- class Circle extends Shape
- {
- constructor(x, y, radius)
- {
- super(x,y);
- this.radius = radius;
- }
- //Polimorfismo
- isCircle(){
- return 1;
- }
- draw_circle(ctx){
- ctx.fillStyle = "#0000cc";
- ctx.beginPath();
- ctx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
- ctx.fill();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment