-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSector.pde
131 lines (119 loc) · 3.02 KB
/
Sector.pde
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
class Sector
{
PGraphics sector;
float sectorSize;
float relativeRotation;
boolean mirror;
boolean skeleton;
float radius = width * 1.75;
Sector(float _sectorSize, float _relativeRotation, boolean _mirror, boolean _skeleton)
{
sectorSize = _sectorSize;
relativeRotation = _relativeRotation;
mirror = _mirror;
skeleton = _skeleton;
media = getMedia();
drawSector();
}
void drawSector()
{
drawSectorShape();
media.mask(sector);
reposition();
}
void drawSectorShape()
{
float opposite = radius * sin(sectorSize);
float adjacent = radius * cos(sectorSize);
float controlMultiplier = (1 + sectorSize/TWO_PI);
float controlX1 = radius * controlMultiplier * sin(sectorSize/3);
float controlY1 = -radius * controlMultiplier * cos(sectorSize/3);
float controlX2 = radius * controlMultiplier * sin(2*sectorSize/3);
float controlY2 = -radius * controlMultiplier * cos(2*sectorSize/3);
sector = createGraphics(media.width, media.height);
sector.beginDraw();
sector.translate(-mediaOffsetX, -mediaOffsetY);
sector.fill(getFillColour());
sector.stroke(getStrokeColour(), getStrokeOpacity());
sector.strokeWeight(getStrokeWeight());
sector.translate(centrePoint.x, centrePoint.y);
sector.beginShape();
sector.rotate(relativeRotation/2);
sector.vertex(-0.75, 0.5);
sector.vertex(0.75, 0.5);
sector.rotate(relativeRotation/2);
sector.vertex(0, -radius);
if (mirror) {
sector.bezierVertex(-controlX1, controlY1, -controlX2, controlY2, -opposite, -adjacent);
// sector.vertex(-opposite, -adjacent);
} else {
sector.bezierVertex(controlX1, controlY1, controlX2, controlY2, opposite, -adjacent);
// sector.vertex(opposite, -adjacent);
}
sector.endShape(CLOSE);
sector.endDraw();
}
void reposition()
{
pushMatrix();
translate(centrePoint.x, centrePoint.y);
if (mirror) {
rotate(relativeRotation);
} else {
rotate(-relativeRotation);
}
translate(-centrePoint.x, -centrePoint.y);
makeSectorImage();
popMatrix();
}
void makeSectorImage()
{
PImage imageContent;
if (skeleton) {
imageContent = sector;
} else {
imageContent = media;
}
if (mirror) {
scale(-1.0, 1.0);
image(imageContent, -(2 * centrePoint.x) + mediaOffsetX, mediaOffsetY, imageContent.width, imageContent.height);
} else {
image(imageContent, mediaOffsetX, mediaOffsetY, imageContent.width, imageContent.height);
}
}
PImage getMedia()
{
if (mediaType == "video") {
return video;
}
return photo;
}
int getFillColour()
{
if (mediaType == "video") {
return 245;
}
return 255;
}
int getStrokeColour()
{
if (skeleton) {
return 0;
}
return 255;
}
float getStrokeWeight()
{
if (skeleton) {
return 1;
}
return 0.5;
}
int getStrokeOpacity()
{
if (skeleton) {
return 255;
}
return 0;
}
}