-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk.js
More file actions
60 lines (53 loc) · 2.34 KB
/
disk.js
File metadata and controls
60 lines (53 loc) · 2.34 KB
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
/********************************************
SURF 2022
Copyright (c) 2022 Elaine Demetrion
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
********************************************/
/**Represents one Disk*/
class Disk {
/*Constructor for the Disk
@param p: the namespace the Disk will exist within
@param x, y: the coordinates of the Disk
@param radius: the radius of the Disk
@param id *optional*: the disk's id number.*/
constructor(p, x, y, radius, id = -1) {
this.p = p;
this.x = x;
this.y = y;
this.radius = radius;
this.id = id; //keeps track of which disk this is. Kept the same across rotated disks.
this.parents = []; //array of two Disks that are the parents. Should be the Disks rotated to the right physical location. Used to generate the ontological graph.
}
/*Draws the Disk.
@param fillColor: the color of the disk [r,g,b,a]
@param strokeColor: the color of the disk outline [r,g,b,a]*/
displayDisk(fillColor = [200], strokeColor = [0]) {
this.p.fill(fillColor);
this.p.stroke(strokeColor);
this.p.strokeWeight(this.radius*0.1);
this.p.ellipse(this.x, this.y, this.radius*2, this.radius*2);
//if(printSomething) { this.p.print(performance.now());}
}
/*Draws the Disk text. Is a separate method because of how we use transforms in stackingCone.
@param color: the color of the text [r,g,b,a]*/
displayDiskText(color = [0]) {
this.p.fill(color);
//this.p.fill(0);
this.p.textSize(this.radius*0.8);
this.p.textAlign(this.p.CENTER,this.p.CENTER);
this.p.noStroke();
this.p.text(this.id, 0, 0);
}
/*Compares whether two disks are the same.
@param disk1, disk2: the two disks to compare
@return T/F: whether the disks are "equivalent". Considered equivalent if id is the same or if they share all other info.*/
static isEqual(disk1, disk2) {
return (disk1.x == disk2.x && disk2.y == disk.y && disk1.radius == disk2.radius) || disk1.id == disk2.id;
}
/*Compares whether this instance of a disk is equivalent to another.
@param disk: the disk to compare this instance to
@return T/F: whether the disks are "equivalent". Considered equivalent if id is the same or if they share all other info.*/
equals(disk) {
return (this.x == disk.x && this.y == disk.y && this.radius == disk.radius) || this.id == disk.id;
}
}