-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
140 lines (109 loc) · 3.28 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
interface IDrawable {
draw(): any;
}
abstract class Shape {
x: number;
y: number;
color: string;
constructor(x: number, y: number, color: string) {
this.x = x;
this.y = y;
this.color = color;
}
abstract displayDetails(): string;
abstract area(): number;
abstract circumference(): number;
}
class Circle extends Shape {
radius: number;
constructor(x: number, y: number, color: string, radius: number) {
super(x, y, color);
this.radius = radius;
}
displayDetails(): string {
return `x: ${this.x} y: ${this.y} color: ${this.color} radius: ${this.radius}`;
}
area(): number {
return Math.PI * Math.pow(this.radius, 2)
}
circumference(): number {
return 2 * Math.PI * this.radius;
}
}
var cir = new Circle (0,0,"000000",2);
console.log(cir.area());
class Square extends Shape implements IDrawable {
length: number;
static draw: any;
constructor(x: number, y: number, color: string, length: number) {
super(x, y, color);
this.length = length;
}
displayDetails(): string {
return `x: ${this.x} y: ${this.y} color: ${this.color} length: ${this.length}`;
}
area(): number {
return Math.pow(this.length, 2)
}
circumference(): number {
return 4 * this.length;
}
draw(){
var main: HTMLElement = document.getElementById("starlet");
var temp: string = "";
for (var k = 0; k < this.y-1; k++){
temp += "<br>"
}
for (var i=0;i<this.length; i++){
temp += "<br>"
var str = "<span style='color:#fff'>_</span>"
temp += str.repeat(this.x)
for (var j=0;j<this.length; j++){
temp += "<span style='color:#" + this.color + "'>*</span>";
}
}
return main.innerHTML += temp;
}
}
var square1 = new Square(3,5,"ff0000",10);
square1.draw();
var square2 = new Square(4, 5, "00ff00", 17);
square2.draw();
class Rectangle extends Shape implements IDrawable {
width: number;
height: number;
constructor(x: number, y: number, color: string, width: number, height: number) {
super(x, y, color);
this.width = width;
this.height = height;
}
displayDetails(): string {
return `x: ${this.x} y: ${this.y} color: ${this.color} width: ${this.width} height: ${this.height}`;
}
area(): number {
return this.width * this.height;
}
circumference(): number {
return (2 * this.width) + (2 * this.height);
}
draw() {
var main: HTMLElement = document.getElementById("starlet");
var temp: string = "";
for (var k = 0; k < this.y - 1; k++) {
temp += "<br>"
}
for (var i = 0; i < this.height; i++) {
temp += "<br>"
var str = "<span style='color:#fff'>_</span>"
temp += str.repeat(this.x)
for (var j = 0; j < this.width; j++) {
temp += "<span style='color:#" + this.color + "'>*</span>";
}
}
return main.innerHTML += temp;
}
}
var rectangle1 = new Rectangle(8, 4, "ff0000", 40, 6);
rectangle1.draw();
var rectangle2 = new Rectangle(5, 5, "00ff00", 5, 15);
rectangle2.draw();