generated from bbtgnn/type-and-code-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
152 lines (133 loc) · 4.11 KB
/
code.js
File metadata and controls
152 lines (133 loc) · 4.11 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
export const configurazione = {
testo: "e", // c spype
dimensione: 0.8,
interlinea: 0.7,
allineamento: "centro",
percorsoFont: "./assets/InputMonoCondensed-BoldItalic.ttf",
sensibilitàMicrofonoBase: 10,
densitàPuntiBase: 1,
nascondiInterfaccia: false,
};
/**
* Disegna punto
* Metti qui quello che vuoi disegnare per ogni punto della font!
*
* @typedef {Object} Ingredienti
* @property {number} x - La coordinata x del punto
* @property {number} y - La coordinata y del punto
* @property {number} angolo - L'angolo della curva della font in quel punto
* @property {number} indice - Il numero del punto nella sequenza (0, 1, 2, 3, ...)
* @property {number} unita - Unita' di misura: corrisponde al 10% della dimensione più piccola della finestra (larghezza o altezza)
* @property {number} volume - Il volume del microfono - Varia da 0 a 1
* @property {number} frameCount - Il numero di frame passati dall'avvio del programma
* @property {number} [alpha] - Device orientation alpha angle (z-axis rotation) - Varia da 0 a 360
* @property {number} [beta] - Device orientation beta angle (front-to-back tilt) - Varia da -90 a 90
* @property {number} [gamma] - Device orientation gamma angle (left-to-right tilt) - Varia da -90 a 90
*
* @param {Ingredienti} ingredienti
*/
export function disegnaPunto({
x,
y,
angolo,
indice,
unita,
volume,
frameCount,
alpha = 0,
beta = 0,
gamma = 0,
}) {
// Ogni 60 frame alterna il testo
let myrand4 = floor(random(100, 180)); //
if (frameCount % myrand4 === 0) {
let myrand0 = floor(random(2)); // genera 0 o 1
if (myrand0 % 2 === 0) {
configurazione.testo = " spype ";
} else {
configurazione.testo = "e";
}
}
const testi = ["e", "psyce", "federico palumbo", "ABARoma"];
// Mappa alpha (0-360) sull'indice dell'array
let index = floor(map(alpha, 0, 360, 0, testi.length)) % testi.length;
configurazione.testo = testi[index];
// Usa beta per modificare la dimensione: genera un moltiplicatore (da 0.5 a 1.5)
let sizeModifier = map(beta, -90, 90, 0.5, 1.5);
// Usa gamma per controllare il canale blu del colore (livello di blu da 0 a 255)
let bValue = map(gamma, -90, 90, 0, 255);
const size = sin((frameCount + indice) * 0.01) * (volume * unita * 1) * unita;
const adjustedSize = size * sizeModifier;
let r = random(255);
let g = random(255);
//let b = random(255);
let b = bValue; // sostituisci il canale blu con il valore controllato
fill(r, g, b);
noStroke();
let larghezza = map(volume, 0, 1, 4, 50);
let myrand = randomGaussian(larghezza, larghezza * 2);
let myrand2 = randomGaussian(larghezza, larghezza / 2);
let myrand3 = randomGaussian(-10, 10);
push();
translate(x, y);
ellipse(
myrand3,
random(-100, 100),
((adjustedSize * myrand) / myrand) * myrand2 * 0.01
);
pop();
/* rumore tv
let larghezza = map(volume, 0, 1, 50, 600);
let myrand = randomGaussian(larghezza, larghezza * 2);
stroke("red");
rect(x * 1.2 - myrand / 2, y + myrand / 20, myrand / 80, 1, 2);
*/
/*
const size = sin((frameCount + indice) * 6) * ((volume * unita) / 2) * unita;
if (indice % 2 == 0) {
fill("black");
} else {
fill("white");
}
noStroke();
push();
translate(x, y);
ellipse(0, 0, size);
pop();
*/
}
/**
* Carica le risorse necessarie
* Esempio: carica immagini, suoni, ecc.
*/
export function caricamentoRisorse() {}
/**
* Imposta le impostazioni iniziali
* Esempio: impostazioni di frame rate, misura degli angoli, ecc.
*/
export function impostazioni() {
frameRate(30);
angleMode(DEGREES);
}
/**
* Disegna sotto i punti
* @param {function} disegnaTesto - La funzione che disegna il testo
*/
export function sotto(disegnaTesto) {
background("black");
// [INFO] Rimuovi il commento per disegnare il testo
let r = random(255);
let g = random(255);
let b = random(255);
fill(r, g, b);
disegnaTesto();
}
/**
* Disegna sopra i punti
* @param {function} disegnaTesto - La funzione che disegna il testo
*/
export function sopra(disegnaTesto) {
// [INFO] Rimuovi il commento per disegnare il testo
// fill("black");
// disegnaTesto();
}