I've done my research to solve this problem but without any success.
I want my rectangle to switch its fill randomly black or white, but all I
can see is a black rectangle.
Who has a suggestion?
float x;
float y;
color white =color(255);
color black =color(0);
color[] colors = { //random selects one of above colors
Some of you already helped me to produce this border detection. So far so great. The "but" is following ...
Now I want to create a simple melody based on the height of the red vertex.
For the first step I started to add something like a scan bar that moves to x-direction.
But it just appeared in the right corner and doesn't move.
Who can help or knows probably a better start to work out?
PImage test_image;
color black = color(0);
color white = color(255);
int[] positions;
float scan_bar;
void setup() {
size(600,450);
noLoop();
positions = new int[width];
test_image = loadImage("skyline.jpg");
scan_bar = width;
}
/* FIRST STEP
find the first black pixel from the top (y) for each column (x)*/
void findPositions() {
loadPixels();
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
if (y==0)
{ positions[x] = -1; }
int index = x + y * width;
color c = pixels[index];
if (c == black) {
positions[x] = y;
print (positions[x]);
print (" ");
break;
}
}
}
}
/* SECOND STEP
draw the found positions with a thick red stroke*/
I want to make a very easy sound programm but as a newbie there's nothing easy in its beginnings ;)
Idea_ The higher the mouse the higher the frequency. I tried following but I got this error message:
"the local variable freq may not have bee initialised".
relating to an older post I've got an new question.
How to express following with code language:
The first black pixel of an column will be saved
and after that the programm should go on scanning
the next column, saving a pixel position again and
so on and so in.
Thanks for any help.
*edit*
Would dist() probably help? My idea is that it
calculates the distance between the very first pixel
and the first black pixel. But I also don't know what's
this in code language.
for (int x = 0; x < source.width; x++) {
for (int y = 0; y < source.height; y++ ) {
int loc = x + y*source.width;
int black = 0;
int white = 255;
if (brightness (destination.pixels[loc]) == black) {
}
// save the position of the first black pixel in this column