We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Everything's gone green
Page Index Toggle Pages: 1
Everything's gone green (Read 1798 times)
Everything's gone green
Jun 1st, 2010, 2:28pm
 
ok, simple feedback spiral.

only i draw using pure white and the trail ends up green.

why so?

Code:

public static final int TEXSIZE = 400;
public static final int HTEXSIZE = 200;

PGraphics tex, tex2;
float angle;

void setup() {
size(400, 400);
tex = createGraphics(TEXSIZE, TEXSIZE, P3D);
tex2 = createGraphics(TEXSIZE, TEXSIZE, P3D);
angle = 0.08;
frameRate(25);
tex.background(0);
tex2.background(0);
}

void draw() {
tex.beginDraw();
tex.background(0);

// rotate around centre
tex.translate(HTEXSIZE, HTEXSIZE);
tex.rotate(angle);

// copy old image (using a slightly bigger copy so it flares)
tex.imageMode(CORNERS);
tex.image(tex2, -HTEXSIZE - 1, -HTEXSIZE - 2, HTEXSIZE + 5, HTEXSIZE + 2);

// draw new ellipse at centre
tex.stroke(255, 255, 255);
int x = (int)random(0, 30);
int y = (int)random(0, 30);
tex.ellipse(0, 0, x, y);
tex.endDraw();

// copy back to front
image(tex, 0, 0);

// copy for next time
try {
tex2 = (PGraphics)tex.clone();
} catch (Exception e) {println("Error: " + e);}
}


i figure that the trail gets fractions of the new pixels, which is why it fades. but why does it do green?
Re: Everything's gone green
Reply #1 - Jun 2nd, 2010, 1:41am
 
Wild guess: maybe the default light source of P3D is yellowish-greenish? Not even sure how to change it.
Note: if you change tex2 to PImage, you can avoid the usage of .clone():
Code:
public static final int TEXSIZE = 400;
public static final int HTEXSIZE = 200;

PGraphics tex;
PImage tex2;
float angle;

void setup() {
size(400, 400);
tex = createGraphics(TEXSIZE, TEXSIZE, P3D);
angle = 0.08;
frameRate(25);
tex.background(0);
tex2 = tex.get();
}

void draw() {
[...]

// copy for next time
tex2 = tex.get();
}
Re: Everything's gone green
Reply #2 - Jun 2nd, 2010, 8:29am
 
Adding
Code:
tex.filter(GRAY); 


right after the image() call will get rid of the green.  It makes the smoke trail dimmer, but that should be fixable.  That doesn't really fix the issue though, just papers over it.  I would guess it's some kind of artifact of the scaling algorithm used for textures.  

What's odd to me is that it's green.  A single pixel is four bytes representing alpha, red, green, blue in that order.  Processing treats it like an int (which is also four bytes) and if there was some kind of weird effect where the least-significant bits get random "noise", I would expect that to show up as blue, not green.  So, it beats me.

I like the effect, though.  One thing I would suggest is making tex and tex2 a little bigger than the window, to get rid of the "clipping" effect at the corners.  Something like:

Code:

public static final int TEXSIZE = 600;
public static final int HTEXSIZE = TEXSIZE/2;

PGraphics tex, tex2;
float angle;

void setup() {
size(400, 400);
tex = createGraphics(TEXSIZE, TEXSIZE, P3D);
tex2 = createGraphics(TEXSIZE, TEXSIZE, P3D);
angle = 0.08;
frameRate(25);
tex.background(0);
tex2.background(0);
}

void draw() {
tex.beginDraw();
tex.background(0);

// rotate around centre
tex.translate(HTEXSIZE, HTEXSIZE);
tex.rotate(angle);

// copy old image (using a slightly bigger copy so it flares)
tex.imageMode(CORNERS);
tex.image(tex2, -HTEXSIZE - 1, -HTEXSIZE - 2, HTEXSIZE + 5, HTEXSIZE + 2);

// draw new ellipse at centre
tex.stroke(255, 255, 255);
int x = (int)random(0, 30);
int y = (int)random(0, 30);
tex.ellipse(0, 0, x, y);
tex.endDraw();

// copy back to front, centered
image(tex, - (TEXSIZE - width)/2, - (TEXSIZE -height)/2);

// copy for next time
try {
tex2 = (PGraphics)tex.clone();
} catch (Exception e) {println("Error: " + e);}
}
Re: Everything's gone green
Reply #3 - Jun 2nd, 2010, 10:04am
 
making it grey only helps if it's white, and it isn't always white (was using random colours, all of which were going greenish, switched to using pure white as a sanity check). and it's also already fading more than i'd like it to, am pretty sure it shouldn't.

and cheers philho for the tip. was scratching my head as to how to do it and clone was the first thing that jumped out at me from the javadoc. i guess both are mostly a copy of 400x400 ints at the end of the day. (or 600x600 now smitty's had his way!)

nice effect though. here's an xscreensaver thing i never quite finished that did the same:

...
Page Index Toggle Pages: 1