Advertisement
Guest User

Untitled

a guest
Jun 13th, 2022
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isHexaDecimal(hexaNumber){
  2.     if (hexaNumber.length===7&&hexaNumber.match(/#[a-f0-9A-F]{6}/)){
  3.         return true
  4.     }else{
  5.         return false
  6.     }
  7. }
  8. function isPositiveNumber(number,_weakmapValue){
  9.     if (typeof number==='number'&&number>=0){
  10.         _weakmapValue.set(this,number)
  11.     }else{
  12.         throw Error(`${number} must be positive Number`)
  13.     }
  14. }
  15. const _color=new WeakMap()
  16. const _x1=new WeakMap()
  17. const _y1=new WeakMap()
  18. const _x2=new WeakMap()
  19. const _y2=new WeakMap()
  20. const _x3=new WeakMap()
  21. const _y3=new WeakMap()
  22. const _radius=new WeakMap()
  23. const _width=new WeakMap()
  24. const _heigth=new WeakMap()
  25.  
  26.  
  27. class Shape{
  28.     constructor(x1,y1,color){
  29.         isPositiveNumber.call(this,x1,_x1);
  30.         isPositiveNumber.call(this,y1,_y1);  
  31.        
  32.         if (isHexaDecimal(color)){
  33.              _color.set(this,color)
  34.         }else{
  35.             throw Error('Color must be in Hexadecimal format')
  36.         }
  37.      
  38.     }
  39.  
  40.     set color(value) {
  41.         if (isHexaDecimal(value)){
  42.             _color.set(this,value);
  43.         }else{
  44.             throw Error('Color must be in Hexadecimal format')
  45.         }
  46.     }
  47.     get color(){
  48.         return _color.get(this)
  49.     }
  50.     draw(){
  51.         console.log('Waiting to draw')
  52.     }
  53.     set x1(value){
  54.         isPositiveNumber(value,_x1);
  55.     }
  56.     get x1(){
  57.         return _x1.get(this)
  58.     }
  59.     set y1(value){
  60.         isPositiveNumber(value,_y1);
  61.     }
  62.     get y1(){
  63.         return _y1.get(this)
  64.     }
  65.  
  66.    
  67. }
  68. class Circle extends Shape{
  69.    
  70.     constructor(x1,y1,color,radius){
  71.         super(x1,y1,color)
  72.         isPositiveNumber.call(this,radius,_radius);
  73.     }
  74.     set radius(value){
  75.         isPositiveNumber.call(this,value,_radius);
  76.     }
  77.     get radius(){
  78.         return _radius.get(this)
  79.     }
  80. }
  81. Circle.prototype.draw=function(ctx){
  82.     ctx.beginPath();
  83.     ctx.arc(this.x1, this.y1, this.radius, 0, 2 * Math.PI);
  84.     ctx.fillStyle = this.color;
  85.     ctx.fill();
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement