-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
211 lines (193 loc) · 4.85 KB
/
Copy pathindex.js
File metadata and controls
211 lines (193 loc) · 4.85 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
let font;
let squaresLetters = [];
let isGenerated = false;
let isFree = true;
let squaresTransition = [];
let cols;
let rows;
let graphic;
let step;
let size;
let colors = [
["#FB2E0F", "#AAC3EB", "#F2BD3D", "#CFDB93"],
["#FB2E0F"],
["#CFDB93"],
["#AAC3EB"],
["#F2BD3D"],
];
let randomColor;
let colorIndex;
let galleryZone;
let animationStarted = false;
let animationStartTime = 0;
let animationFinished = false;
let fs; //font size
function resizingText(minRem, vw, maxRem) {
const remToPx = 16;
const minPx = minRem * remToPx;
const maxPx = maxRem * remToPx;
const vwPx = (vw / 100) * windowWidth;
return Math.max(minPx, Math.min(vwPx, maxPx));
}
function preload() {
font = loadFont("assets/fonts/Roboto-Bold.ttf");
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(239, 239, 239);
graphic = createGraphics(windowWidth, windowHeight);
size = windowWidth / 30;
fs = resizingText(0.5, 13, 500);
cols = ceil(windowWidth / size);
rows = ceil(windowHeight / size);
for (let i = 0; i < cols * size; i = i + size) {
for (let j = 0; j < rows * size; j = j + size) {
squaresTransition.push(new SquareTransition(i, j));
}
}
graphic.fill(255);
graphic.textFont(font);
graphic.textSize(fs);
graphic.textAlign(CENTER, CENTER);
graphic.text(
"Software \nPerforming \nArts Gallery",
width / 2,
height / 2 - 50
);
randomColor = Math.floor(Math.random(2) * colors.length);
}
let fillPoints = [];
function generateFillPoints() {
step = width / 95;
for (let y = 0; y < height; y += step) {
for (let x = 0; x < width; x += step) {
let col = graphic.get(x, y);
if (col[0] == 255) {
colorIndex =
Math.floor(x / step + y / step) % colors[randomColor].length;
let c = colors[randomColor][colorIndex];
fillPoints.push({ x, y, c });
}
}
}
}
function draw() {
noStroke();
//fill(0, 255, 255);
if (!isGenerated) {
generateFillPoints();
for (let pt of fillPoints) {
let square = new SquareLetter(pt.x, pt.y, pt.c);
square.isLetter = true;
if (pt.x > width / 2 - (1 / 10) * width && pt.y > (height / 3) * 2) {
square.isGallery = true;
}
squaresLetters.push(square);
}
isGenerated = true;
}
let isMoving = false;
squaresLetters.forEach((square) => {
square.show();
square.move();
if (random(1) < 0.01) square.speed = 0.5;
if (square.isLetter && square.x < square.start + square.size) {
isMoving = true;
}
});
if (!isMoving && !animationStarted) {
animationStarted = true;
animationStartTime = millis();
squaresTransition.forEach((square) => {
square.appearance = random(0, 2000);
});
}
if (animationStarted && !animationFinished) {
let currentTime = millis() - animationStartTime;
//console.log(currentTime);
squaresTransition.forEach((square) => {
square.update(currentTime);
square.show();
});
if (squaresTransition.every((c) => !c.isFree)) {
setTimeout(() => {
animationFinished = true;
}, 1000);
}
}
if (animationFinished) {
background(0);
window.location.href = "pages/gallery.html";
}
}
function mousePressed() {
window.location.href = "pages/gallery.html";
}
class SquareLetter {
constructor(x, y, color) {
this.start = x;
this.x = x;
this.y = y;
this.speed = 0;
this.size = windowWidth / 110;
this.color = color;
this.isLetter = false;
this.isGallery = false;
}
show() {
fill("#050505");
square(this.x - 1, this.y + 1, this.size);
if (this.isLetter) {
fill(this.color);
}
square(this.x, this.y, this.size);
}
move() {
if (this.isLetter) {
if (this.x < this.start + this.size) {
this.x += this.speed;
this.y -= this.speed;
}
}
}
}
class SquareTransition {
constructor(x, y) {
this.x = x;
this.y = y;
this.size = size;
this.isFree = true;
this.appearance = 0;
this.color;
this.shouldShow = false;
}
show() {
if (this.shouldShow) {
randomColor = Math.floor(Math.random(2) * colors.length);
colorIndex =
Math.floor(this.x / step + this.y / step) % colors[randomColor].length;
this.color = colors[randomColor][colorIndex];
fill(this.color);
square(this.x, this.y, this.size);
}
}
update(currentTime) {
if (currentTime >= this.appearance) {
this.shouldShow = true;
this.isFree = false;
}
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
graphic = createGraphics(windowWidth, windowHeight);
graphic.fill(255);
graphic.textFont(font);
fs = resizingText(0.5, 13, 500);
graphic.textSize(fs);
graphic.textAlign(CENTER, CENTER);
graphic.text("Software \nPerforming \nArts", width / 2, height / 2);
fillPoints = [];
squaresLetters = [];
isGenerated = false;
}