|
Author |
Topic: ... over my head? (Read 878 times) |
|
mKoser
|
Re: ... over my head?
« Reply #15 on: Jan 28th, 2004, 10:45am » |
|
Quote: say, if c is an integer with a bit packed color value inside, r: c & 0xff g: (c & 0xff00) >> 8 b: (c & 0xff0000) >> 16 |
| very handy indeed!... but, how do you do the reverse action? if you've got an RGB colour, how do you pack that into an integer of that format? (sorry - a bit of topic here!) + mikkel
|
mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
|
|
|
toxi_ Guest
|
Re: ... over my head?
« Reply #16 on: Jan 28th, 2004, 1:13pm » |
|
mikkel, have a look at my longish post about bits & shifts over here
|
|
|
|
mKoser
|
Re: ... over my head?
« Reply #17 on: Jan 28th, 2004, 3:38pm » |
|
thank you toxi - this forum it getting REALLY difficult to remember/find what i once read... so, i guess it is time to start making my own little tech-note archive thanks for linking!
|
mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
|
|
|
Charles Hinshaw Guest
|
Re: ... over my head?
« Reply #18 on: Jan 28th, 2004, 10:47pm » |
|
two things... First, I did a touch of optimization to my earlier code -- and it runs MUCH faster, so in case somebody stumbles upon this thread in the future and is using things as a resource, the following is better, but it will likely still hang on an image that is TOO dark... It is really designed for working with black text on a white background. Code: // User Control Variables String imagename = "digidust2.jpg"; // Source Image int seconds = 4; // length of animation boolean recording = false; // record frames? //Global Variables particle p[]; int loopcount = 1; // ------------------------------------------------------ void setup() { size(640,480); smooth(); BImage startimage; startimage = loadImage(imagename); image(startimage, 0, 0); int x, y, col, grey; int i = 0; int pgen = 0; int[][] density = new int[width][height]; int particlesum = 0; for (y = 0; y < height; y++){ for (x = 0; x < width; x++){ col=pixels[i]; grey=100-int(((77*(col>>16&0xff) + 151*(col>>8&0xff) + 28*(col&0xff)) >> 8)/2.55); density[x][y] = grey; particlesum += grey; i++; } } p = new particle[particlesum]; for (x = 0; x < width; x++){ for (y = 0; y < height; y++){ if(density[x][y] != 0){ for(i = 0; i < density[x][y]; i++){ p[pgen] = new particle(x,y,pgen); pgen++; } } } } } // ------------------------------------------------------ void loop() { if (loopcount < (seconds*30)){ background(255); for(int i = 0; i < p.length; i++) { p[i].brownian(); p[i].paint(); } if (recording = true){ saveFrame(); } } loopcount++; } // ------------------------------------------------------ class particle { int x, y, id, index, col, grey; particle(int xloc, int yloc, int ident) { x = xloc; y = yloc; id = ident; } void paint() { index = ((y-1)*width)+x; col = pixels[index]; grey=int(((77*(col>>16&0xff) + 151*(col>>8&0xff) + 28*(col&0xff)) >> 8)-2.55); if (grey < 0){ grey = 0; } pixels[index] = grey<<16 | grey<<8 | grey; } void brownian() { x += random(-3,3); y += random(-3,3); } } |
| second, if you will take a look at my setup(), you will see two sets of for() loops which I would like to combine. The issue is that the first for() has to complete before I can know the length of my array. I looked at fry's example of the growing array in the reference section, but does this work with an array of objects? I couldn't get it to. If anybody knows how to integrate those sections by doing something like that, it is a technique that I could sure stand to learn. Cheers! Charles Hinshaw direction + repertoire [r]evolve, US http://www.everydayrevolution.com
|
|
|
|
|