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 & HelpSyntax Questions › Making the switch from Alpha
Pages: 1 2 
Making the switch from Alpha (Read 8118 times)
Making the switch from Alpha
Apr 19th, 2005, 5:02pm
 
I wonder if those who were part of the Beta beta could provide some insight into the first steps what to do to make old sketches created in 0068 work again. Like what has completely changed and is done different now -

It's just a bit frustrating to look at a grey screen even though there is no error message. Maybe in my case it's because I'm not using any drawing funtions but work with pixels[]?

From what I guess, loop() does not exist anymore and is now draw()

Also it seems that if you want to use the pixels[] array you first have to initialize it with loadPixels() - but only after the size() command (which is somehow logical)

Now I also assume that I have to call updatePixels() if I made changes to the pixel[] array - is that correct?

Still I just get a grey screen.



Re: Making the switch from Alpha
Reply #1 - Apr 19th, 2005, 5:53pm
 
Ben's list is here: http://processing.org/faq/changes.html

To which I would add: BGraphics / BApplet / BImage etc now all begin with P.

I've had some issues with applets which create a separate BGraphics object, which I'll investigate when I have the time.  Could that be it?

PS This forum is for "bugs" with the website, I think, not for posting tutorials.
Re: Making the switch from Alpha
Reply #2 - Apr 19th, 2005, 7:02pm
 
Oops - I just read "Website, Reference, Example" and missed the "Bugs" part.... Sorry.

Anyway - just in case this entry gets moved into the correct forum - I've found out why I just saw grey:

Unlike in the old version, the current version seems to make use of the ALPHA part in the the main pixels[] array - in 0069 it was ignored as it was the background layer anyway.

So as a quick fix for now in all my old sketches I will have to add this

Code:

for (int i=pixels.length;--i>-1;)
{
pixels[i]|=0xff000000;
}
Re: Making the switch from Alpha
Reply #3 - Apr 19th, 2005, 7:29pm
 
you can also do this by calling filter(OPAQUE), which will set all the high bits of the pixels to be opaque.

if your image format is RGB (not ARGB) you shouldn't have to do this, so if that's that case, you might file that as a bug.
Re: Making the switch from Alpha
Reply #4 - Apr 19th, 2005, 8:33pm
 
Thanks for the hint - I'll make a quick check to see which is faster.

About the image format - I'm working with the main pixel[] array of the applet - what kind of format is it supposed to have - RGB or RGBA?
Re: Making the switch from Alpha
Reply #5 - Apr 19th, 2005, 9:13pm
 
Okay, I tried to compare filter(OPAQUE) against a normal for() loop, but somehow the screen does not refresh. Can someone please have a look at this code and tell me where's my fault:

Code:

void setup(){
size(500,500,JAVA2D);
loadPixels();
}

void draw(){
int t;

for (int i=pixels.length;--i>-1;pixels[i]=(int)random(0xffffffff)) {}


t=millis();
test();
println(millis()-t);

t=millis();
test2();
println(millis()-t);

println("------------");

updatePixels();
}

void test()
{
filter( OPAQUE );
}

void test2()
{
for (int i=pixels.length;--i>-1;pixels[i]|=0xff000000) {}
}


BTW - even though the screen does not update, it looks like the normal loop is something like 10 times faster than filter - which sounds a bit strange though.
Re: Making the switch from Alpha
Reply #6 - Apr 19th, 2005, 9:45pm
 
Pssst!  loadPixels()!   Wink

Re: Making the switch from Alpha
Reply #7 - Apr 19th, 2005, 10:12pm
 
Quote:
Pssst!  loadPixels()!


Oh yes - how stupid of me!


But still - no success. Here is an even simpler example:

Code:


void setup(){
size(500,500,JAVA2D);
}

void draw(){

loadPixels();
for (int i=pixels.length;--i>-1;pixels[i]=(int)random(0xffffffff)) { }
updatePixels();
}


Is it maybe that the applet itself doesn't have a pixels[] array anymore? Do I have to instance a PImage first and then use image() to render it?
Re: Making the switch from Alpha
Reply #8 - Apr 19th, 2005, 10:26pm
 
Okay - found the culprit: random(0xffffffff) doesn't work - I have to say 0xff000000 | (int)random(0xffffff))


Code:

void setup(){
size(500,500,JAVA2D);
}

void draw(){

loadPixels();
for (int i=pixels.length;--i>-1;pixels[i]=0xff000000 | (int)random(0xffffff)) { }
updatePixels();
}


Re: Making the switch from Alpha
Reply #9 - Apr 19th, 2005, 10:52pm
 
i'll make a note that we should maybe mention that in the reference.. that random() is gonna have an upper bound as you approach a 32 bit number..

filter(OPAQUE) is just using a for() loop too, nothing fancy. the idea is that you don't have to do set up it up yourself, that's all.
Re: Making the switch from Alpha
Reply #10 - Apr 19th, 2005, 11:03pm
 
Finally I think I've got it - here's my understanding:

filter(OPAQUE)

is not the same as

for (int i=pixels.length;--i>-1;pixels[i]|=0xff000000) {}

This works:

Code:

void setup(){
size(500,500);
}

void draw(){
loadPixels();
for (int i=pixels.length;--i>-1;pixels[i]=(int)random(0xffffff)) { }
fill_opaque();
updatePixels();

}

void fill_opaque()
{
for (int i=pixels.length;--i>-1;pixels[i]|=0xff000000) {}
}



But to use filter(OPAQUE) I have to use it before I set the pixels, plus I will have to clear the pixels[] array first and I have to OR the RGB values into the array:

Code:

void draw(){

background(0);
filter( OPAQUE );
loadPixels();
for (int i=pixels.length;--i>-1;pixels[i]|=(int)random(0xffffff)) { }
updatePixels();

}


Timing wise it's like I mentioned before - the for loop is something 8 to 10 times as fast.
Re: Making the switch from Alpha
Reply #11 - Apr 19th, 2005, 11:34pm
 
I forgot to mention, that the obvious case how to use filter does not work:

Code:

void draw(){
loadPixels();
for (int i=pixels.length;--i>-1;pixels[i]=(int)random(0xffffff)) { }
updatePixels();
filter( OPAQUE );
}


Is there an explanation why this doesn't work? Is there some kind of optimization inside of updatePixels() that ignores values with alpha=0?
Re: Making the switch from Alpha
Reply #12 - Apr 19th, 2005, 11:45pm
 
all pixel operations, like filter(), need to happen inside loadPixels/updatePixels:

Code:
loadPixels();
for (int i=pixels.length;--i>-1;pixels[i]=(int)random(0xffffff)) { }
filter( OPAQUE );
updatePixels();


RGB images are simpler to processing than ARGB images, actually it looks like there may be a bug.. since the image should just be RGB and show up just fine. i'll look into it.
Re: Making the switch from Alpha
Reply #13 - Apr 20th, 2005, 4:03am
 
Where is SplitInts and SplitFloats? Processing is telling me there is now just a Split. Didn't see that in the list-o changes.



You really hate your loyal Alpha users. Don't you??


-------------
Nevermind, I found it in the Revisions.txt.
But I still think you hate us.

-------------
thanks Fry. I found the trick -- switch away from "brief" or whatever on the language page.

now, all my circles are hosed (too big / deformed), and none of my text is showing. I'd cry, but since find/replace helped me fix most of the changes, i'll deal. (for now) Smiley
Re: Making the switch from Alpha
Reply #14 - Apr 20th, 2005, 4:27am
 
we go out of our way to confuse our users through a combination of strategically placed bugs and baffling syntax changes.

but you're so march 2004: splitInts and splitFloats went away in 69... now it's just split(), and you can use toInt() or toFloat() on it as you like. that's why it's missing from the alpha->beta transition, though i'll add it since we had called 69 experimental for so long.

rest assured, beta means the end of api changes till 1.0.. (unless we find something egregious, like if loadPixels() turns out to be a disaster)
Pages: 1 2