tempComparator=round(map(sin(active), -1, 1, 0, lights.length-1)); // Transforma la onda sinusoidal del activo a la longitud de los leds
20
// println(tempComparator, sin(active)); // Información extra
21
if (tempComparator==pos) {
22
brightness=255;
23
} else {
24
tempProximity=round(map(abs(pos-tempComparator), 0, contiguousLeds, 200, 0)); // Transforma la distancia al led central al brillo, según cuantos sean los leds contiguos
25
// println(tempProximity, round(map(tempProximity, 0, lights.length, 255, 0))); // Información extra
26
brightness=tempProximity;
27
}
28
fill(brightness, 0, 0); // Color (brillo)
29
30
rect(0+(pos*w), heightY, w, w); // Leds
31
}
32
}
33
34
voidsetup() {
35
size(400, 100);
36
37
stroke(255, 0, 0, 80); // Pintar los rectangulos transparentes.
38
frameRate(speed*60);
39
posY=height/2; // Se debe iniciar aquí ya que height si no no se establece bien.
40
if (amount==0) {
41
lights=newLED[width/ledSize]; // Establecer el tamaño del array a una grid horizontal del tamaño ancho/celda
42
} else {
43
lights=newLED[abs(amount)]; // Tamaño definido por usuario, no puede ser negativo.
44
}
45
for (inti=0; i<lights.length; i++) {
46
47
lights[i] =newLED(i, posY, ledSize);
48
}
49
}
50
51
voiddraw() {
52
background(0);
53
active+=0.01; // Aumentamos todo el rato el led activo, el programa ya se encargará de interpretar.
54
for (inti=0; i<lights.length; i++) { // Bucle for se podría poner como (int i : lights.length), pero no acepta arrays de objetos, solo de ints
“Coche Fantastico” by Adrian
https://openprocessing.org/sketch/803058
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
Coche Fantastico
xxxxxxxxxx
int amount = 0; // Dejar en 0 para que llene la pantalla
int ledSize = 20; // Tamaño de los LED
float speed = 2; // Multiplicador de la velocidad del programa
int posY; // Altura a la que se dibujan los leds
int contiguousLeds = 5; // Numeros de leds que serán iluminados proximos al maximo
float active, tempComparator, tempProximity; // Variable que especifica que led debe estar encendido, y dos variables temporales
LED lights[];
class LED {
int heightY, w, pos;
float brightness;
LED(int setupPos, int pY, int pW) { // Clase constructora
pos = setupPos;
heightY = pY;
w = pW;
brightness = 0;
}
void update() {
tempComparator = round(map(sin(active), -1, 1, 0, lights.length-1)); // Transforma la onda sinusoidal del activo a la longitud de los leds
// println(tempComparator, sin(active)); // Información extra
if (tempComparator == pos) {
brightness = 255;
} else {
tempProximity = round(map(abs(pos-tempComparator), 0, contiguousLeds, 200, 0)); // Transforma la distancia al led central al brillo, según cuantos sean los leds contiguos
// println(tempProximity, round(map(tempProximity, 0, lights.length, 255, 0))); // Información extra
brightness = tempProximity;
}
fill(brightness, 0, 0); // Color (brillo)
rect(0+(pos*w), heightY, w, w); // Leds
}
}
void setup() {
size(400, 100);
stroke(255, 0, 0, 80); // Pintar los rectangulos transparentes.
frameRate(speed*60);
posY = height/2; // Se debe iniciar aquí ya que height si no no se establece bien.
if (amount == 0) {
lights = new LED[width/ledSize]; // Establecer el tamaño del array a una grid horizontal del tamaño ancho/celda
} else {
lights = new LED[abs(amount)]; // Tamaño definido por usuario, no puede ser negativo.
}
for (int i = 0; i < lights.length; i++) {
lights[i] = new LED(i, posY, ledSize);
}
}
void draw() {
background(0);
active += 0.01; // Aumentamos todo el rato el led activo, el programa ya se encargará de interpretar.
for (int i = 0; i < lights.length; i++) { // Bucle for se podría poner como (int i : lights.length), pero no acepta arrays de objetos, solo de ints
lights[i].update();
}
}
See More Shortcuts