Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isHexaDecimal(hexaNumber){
- if (hexaNumber.length===7&&hexaNumber.match(/#[a-f0-9A-F]{6}/)){
- return true
- }else{
- return false
- }
- }
- function isPositiveNumber(number,_weakmapValue){
- if (typeof number==='number'&&number>=0){
- _weakmapValue.set(this,number)
- }else{
- throw Error(`${number} must be positive Number`)
- }
- }
- const _color=new WeakMap()
- const _x1=new WeakMap()
- const _y1=new WeakMap()
- const _x2=new WeakMap()
- const _y2=new WeakMap()
- const _x3=new WeakMap()
- const _y3=new WeakMap()
- const _radius=new WeakMap()
- const _width=new WeakMap()
- const _heigth=new WeakMap()
- class Shape{
- constructor(x1,y1,color){
- isPositiveNumber.call(this,x1,_x1);
- isPositiveNumber.call(this,y1,_y1);
- if (isHexaDecimal(color)){
- _color.set(this,color)
- }else{
- throw Error('Color must be in Hexadecimal format')
- }
- }
- set color(value) {
- if (isHexaDecimal(value)){
- _color.set(this,value);
- }else{
- throw Error('Color must be in Hexadecimal format')
- }
- }
- get color(){
- return _color.get(this)
- }
- draw(){
- console.log('Waiting to draw')
- }
- set x1(value){
- isPositiveNumber(value,_x1);
- }
- get x1(){
- return _x1.get(this)
- }
- set y1(value){
- isPositiveNumber(value,_y1);
- }
- get y1(){
- return _y1.get(this)
- }
- }
- class Circle extends Shape{
- constructor(x1,y1,color,radius){
- super(x1,y1,color)
- isPositiveNumber.call(this,radius,_radius);
- }
- set radius(value){
- isPositiveNumber.call(this,value,_radius);
- }
- get radius(){
- return _radius.get(this)
- }
- }
- Circle.prototype.draw=function(ctx){
- ctx.beginPath();
- ctx.arc(this.x1, this.y1, this.radius, 0, 2 * Math.PI);
- ctx.fillStyle = this.color;
- ctx.fill();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement