Guest User

Untitled

a guest
Mar 6th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  3. class Shape
  4. {
  5.     constructor(x, y) //define coordenadas da forma
  6.     {
  7.         this.x = x;
  8.         this.y = y;
  9.     }
  10.    
  11.     toString()
  12.     {
  13.         return "(" + this.x + ", " + this.y + ")";
  14.     }
  15.  
  16.     isCircle()
  17.     {
  18.         return 0;
  19.     }
  20.  
  21.     isRectangle()
  22.     {
  23.         return 0;
  24.     }
  25. }
  26.  
  27.  
  28. class Rectangle extends Shape
  29. {
  30.     constructor(x, y, width, height)
  31.     {
  32.         super(x,y);
  33.         this.width = width;
  34.         this.height = height;
  35.     }
  36.  
  37.     draw_rectangle(ctx){
  38.         ctx.fillStyle = "#ff0000";  
  39.         ctx.fillRect(this.x, this.y, this.width, this.height);
  40.     }
  41.  
  42.     isRectangle()
  43.     {
  44.         return 1;
  45.     }
  46.  
  47. }
  48.  
  49.  
  50. class Circle extends Shape
  51. {
  52.     constructor(x, y, radius)
  53.     {
  54.         super(x,y);
  55.         this.radius = radius;
  56.     }
  57.     //Polimorfismo
  58.     isCircle(){
  59.         return 1;
  60.     }
  61.  
  62.     draw_circle(ctx){
  63.         ctx.fillStyle = "#0000cc";  
  64.         ctx.beginPath();  
  65.         ctx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);  
  66.         ctx.fill();
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment