glowing line
in
Programming Questions
•
3 years ago
Hi list,
I've distilled the harukit example to just the glowing line for a lightsaber effect. My question is, is there a way to use it like the line object, ie glowingLine(0, 0, 200, 200)?
Thanks,
Justin
public int lmode = 2;
public int by = 8; //line thickness
PGraphics pg;
public color [] A;
float rr, gg, bb, dis;
int gain = 5;
float[] cc = new float[3];
void setup() {
frameRate(3000);
size(500, 500, P3D);
loadPixels();
A = pixels;
pg = createGraphics(width, height, P3D); //offscreen graphics buffer for transparency
colorMode(RGB, 350);
hint(ENABLE_OPENGL_4X_SMOOTH);
lights();
noStroke();
background(110);
for(int i=0; i<3; i++) {
cc[i] = random(40) + random(40) + random(40) + random(40) + random(40);
}
}
void draw() {
lights();
stroke(255);
for(int y=0; y<pg.height; y++) {
for(int x=0; x<pg.width; x++) {
// kx+=0.5;
int pos = y*pg.width + x;
// int ka =int(ky)*pg.width+int(kx);
color col = pg.pixels[pos];
// color col =A[pos];
rr = col >> 16 & 0xff;
gg = col >> 8 & 0xff;
bb = col & 0xff;
if( lmode ==1) dis = dist(mouseX,mouseY,x,y)/by; //spot
if( lmode ==2) dis = dist(mouseX,mouseY,mouseX,y)/by; //lightsaber
rr += cc[0]/dis-gain;
gg += cc[1]/dis-gain;
bb += cc[2]/dis-gain;
A[x+y*pg.width] = color(rr, gg, bb);
}
}
line(0, 0, 200, 200);
}
I've distilled the harukit example to just the glowing line for a lightsaber effect. My question is, is there a way to use it like the line object, ie glowingLine(0, 0, 200, 200)?
Thanks,
Justin
public int lmode = 2;
public int by = 8; //line thickness
PGraphics pg;
public color [] A;
float rr, gg, bb, dis;
int gain = 5;
float[] cc = new float[3];
void setup() {
frameRate(3000);
size(500, 500, P3D);
loadPixels();
A = pixels;
pg = createGraphics(width, height, P3D); //offscreen graphics buffer for transparency
colorMode(RGB, 350);
hint(ENABLE_OPENGL_4X_SMOOTH);
lights();
noStroke();
background(110);
for(int i=0; i<3; i++) {
cc[i] = random(40) + random(40) + random(40) + random(40) + random(40);
}
}
void draw() {
lights();
stroke(255);
for(int y=0; y<pg.height; y++) {
for(int x=0; x<pg.width; x++) {
// kx+=0.5;
int pos = y*pg.width + x;
// int ka =int(ky)*pg.width+int(kx);
color col = pg.pixels[pos];
// color col =A[pos];
rr = col >> 16 & 0xff;
gg = col >> 8 & 0xff;
bb = col & 0xff;
if( lmode ==1) dis = dist(mouseX,mouseY,x,y)/by; //spot
if( lmode ==2) dis = dist(mouseX,mouseY,mouseX,y)/by; //lightsaber
rr += cc[0]/dis-gain;
gg += cc[1]/dis-gain;
bb += cc[2]/dis-gain;
A[x+y*pg.width] = color(rr, gg, bb);
}
}
line(0, 0, 200, 200);
}
1