-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
117 lines (94 loc) · 2.65 KB
/
sketch.js
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
// Stèv Animated Text
// version without mouse interaction to avoid conflict when embedded in iframe
// and adding a clickable link (ie. to Homepage)
let rate = 3;
let upperBound;
let lowerBound;
let numberOfRectangles = 4;
let shape = [];
let textArray = ['S', 'T', 'È', 'V', '[‘s', 't', 'ɛ', 'v]', 'ス', 'テ', 'ー', 'ヴ']
let textArrayNumberOfSymbols = (textArray.length - 1);
let textCenterCalibrationCoeff = 1.35;
// rectangle + text class
class drawRectangle {
constructor(offset) {
this.offset = offset;
this.textArrayOffset = offset;
this.textIndex = this.offset + 1;
this.initAlpha = 0;
this.currentAlpha = 0;
this.finalAlpha = 255;
this.size = width/numberOfRectangles;
this.textPositionX = this.textIndex * this.size - (this.size/2);
this.leftBound = offset * this.size;
this.rightBound = this.leftBound + this.size;
}
changeCharacter() {
if (random(100000) > 99500) {
this.currentAlpha = this.finalAlpha;
this.textArrayOffset += 4;
}
/*
if (this.leftBound < mouseX &&
mouseX < this.rightBound &&
mouseY < lowerBound &&
mouseY > upperBound &&
frameCount%rate == 0) {
this.currentAlpha = this.finalAlpha;
this.textArrayOffset += 4;
} */
if (this.textArrayOffset > this.offset+9) {
this.textArrayOffset = this.offset;
}
}
backToWhite() {
this.currentAlpha = lerp(this.currentAlpha,
this.initAlpha,
random(0.03, 0.1));
}
showText() {
if (this.textArrayOffset < 5) {
textSize(25);
} else if (this.textArrayOffset < 7) {
textSize(28);
} else if (this.textArrayOffset > 7) {
textSize(24);
}
textFont('Arial');
textAlign(CENTER);
//draw white text
fill(255, 255, 255, this.currentAlpha);
text(textArray[this.textArrayOffset],
this.textPositionX,
lowerBound/textCenterCalibrationCoeff);
//draw black text
fill(0, 0, 0, 255-this.currentAlpha);
text(textArray[this.textArrayOffset],
this.textPositionX,
lowerBound/textCenterCalibrationCoeff);
}
showRect() {
fill(0, 0, 0, this.currentAlpha);
rect(this.leftBound, upperBound, this.size, lowerBound);
}
}
//-----------
function setup() {
createCanvas(95, 40);
noStroke();
upperBound = 1;
lowerBound = height - 2;
for (i = 0; i < 4; i ++) {
shape[i] = new drawRectangle(i);
}
}
function draw() {
background(255);
// draw rectangles
for (i = 0; i < 4; i ++) {
shape[i].backToWhite();
shape[i].changeCharacter();
shape[i].showRect();
shape[i].showText();
}
}