Sound based on Vertex
in
Programming Questions
•
5 months ago
Hellow you all,
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?
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*/
- void drawPositions() {
- strokeWeight(3);
- stroke(255, 0, 0);
- noFill();
- beginShape();
- for (int x=0; x<width; x++) {
- int y = positions[x];
- if (y>-1) {
- vertex(x, y);
- }
- }
- endShape();
- }
- void draw() {
- // Display the image
- image(test_image,0,0);
- findPositions();
- drawPositions();
- // Draw scan bar (doesn't work)
- stroke(0,0,255);
- line(scan_bar, 0, scan_bar, height);
- scan_bar = scan_bar + 1.0;
- if (scan_bar > width) {
- scan_bar = 0;
- }
- }
1