-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
103 lines (91 loc) · 2.52 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
let font;
let transcript;
let authors = ["special", "mountAinmAn", "bateau"];
let messages = [];
let time = -1; // in seconds
// cursor
let x = 0;
let y = 20;
function preload() {
font = loadFont('SourceCodePro-Regular.ttf');
transcript = loadStrings('transcript.txt');
}
function setup() {
createCanvas(800,800);
background('black');
textSize(14);
textFont(font);
for (entry of transcript) {
let splitLine = entry.split('#');
let wipe = (splitLine[2] == 'Y') ? true : false;
message = new Message(
parseInt(splitLine[0]),
parseFloat(splitLine[1]),
wipe,
splitLine[3]
);
messages.push(message);
}
noLoop();
}
async function draw() {
for (message of messages) {
await new Promise(r => setTimeout(r, message.delay*1500));
message.print();
}
}
class Message {
constructor(author, delay, wipe, message) {
this.author = author;
this.delay = delay;
this.wipe = wipe;
this.message = message;
}
print() {
if (this.wipe) {
background('black');
x = 0;
y = 20;
}
let username;
let userWidth;
switch(this.author) {
case 0: // special text
textStyle(BOLD);
fill(color('#00ff41')); // matrix green
text(this.message, x, y);
y += 15;
break;
case 1: // person 1
// printing username
username = authors[1] + ":";
userWidth = textWidth(username);
textStyle(BOLD);
fill(color('#a9dde2'));
text(username, x, y);
x += userWidth;
// printing message
textStyle(NORMAL);
fill(color('white'));
text(this.message, x, y);
x = 0;
y += 15
break;
case 2: // person 2
// printing username
username = authors[2] + ":";
userWidth = textWidth(username);
textStyle(BOLD);
fill(color('#c1ac6d'));
text(username, x, y);
x += userWidth;
// printing message
textStyle(NORMAL);
fill(color('white'));
text(this.message, x, y);
x = 0;
y += 15
break;
}
}
}