-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
executable file
·142 lines (122 loc) · 3.54 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
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
const width = 1600;
const height = 1000;
const targetFrameRate = 20;
const fontsize = 50;
const message = "Tina";
// set the gap between letters and the left and top margin so that you can accurately set the parameters
const gap = 40;
const margin = 20;
const displacementAmount = 100;
const COLORS = {
background: "#F5F3F5"
};
const colors = [
"#6A5D93",
"#F2B453",
"#C74C63",
"#E5803F",
"#F5F3F5"
];
// const hoverFill = "#ed225d";
// const normalFill = "#FFFFFF";
let currentFill = colors[0];
let currentColorIndex = 0;
let font;
function preload() {
// Ensure the .ttf or .otf font stored in the assets directory
// is loaded before setup() and draw() are called
// font = loadFont("assets/Roboto-Light.ttf"); // Lighter, OK performance
// font = loadFont("assets/Adamas-Regular.otf"); // Heavier, Worse performance
font = loadFont("assets/London.ttf"); //
}
function setup() {
cnv = createCanvas(width, height);
cnv.mouseMoved(onMouseOver);
// cnv.mouseOut(onMouseOut);
// Set text characteristics
textFont(font);
textSize(fontsize);
textAlign(CENTER, CENTER);
frameRate(targetFrameRate);
}
function onMouseOver() {
// cvn.background = COLORS.stem;
currentFill = colors[currentColorIndex++];
if (currentColorIndex >= colors.length) currentColorIndex = 0;
}
function onMouseOut() {
currentFill = colors[currentColorIndex++];
if (currentColorIndex >= colors.length) currentColorIndex = 0;
}
function draw() {
translate(margin * 4, margin * 4);
// drawLetters();
drawMessage(message);
}
function drawMessage(msg) {
// frameRate(targetFrameRate - 10);
fill(currentFill);
// loop as long as there is space on the canvas
for (y = 0; y < height - gap - margin; y += gap) {
for (x = 0; x < width - gap - margin; x += gap * msg.length) {
// draw the message to the screen so that you start to view content
// variable for content is for (let i = 0; i < msg.length; i++) {
text(
msg,//msg[i],
x + random(displacementAmount),
y + random(displacementAmount)
);
// }
}
}
}
function drawMessageInGroups(msg) {
// frameRate(targetFrameRate - 10);
fill(currentFill);
// for loop as long as there is space on the canvas to fill screen
for (y = 0; y < height - gap - margin; y += gap + displacementAmount) {
for (x = 0; x < width - gap - margin; x += gap + displacementAmount) {
// draw the message to the screen
for (let i = 0; i < msg.length; i++) {
text(
msg[i],
x + random(displacementAmount),
y + random(displacementAmount)
);
}
}
}
}
function drawLetters() {
// set the counter to start at the character you want
// in this case 35, which is the # symbol
let counter = 35;
fill(currentFill);
// Loop as long as there is space on the canvas
for (y = 0; y < height - gap - margin; y += gap) {
for (x = 0; x < width - gap - margin; x += gap) {
// Use the counter to retrieve individual letters by their Unicode number
let letter = char(counter);
// // add different color to the vowels and other characters
// if (
// letter == "A" ||
// letter == "E" ||
// letter == "I" ||
// letter == "O" ||
// letter == "U"
// ) {
// fill("#ed225d");
// } else {
// fill(255);
// }
// draw the letter to the screen
text(
letter,
x + random(displacementAmount),
y + random(displacementAmount)
);
// increment the counter
counter++;
}
}
}