A Simple Task? (Pixels by brightness)
in
Programming Questions
•
11 months ago
Ha! This seemed simple enough in theory but as a absolute beginner to programming this is turning out to be rather difficult.
I'm trying rearrange the pixels of an image based on color with a few things in mind.
1) Preserve the x position of the pixel
2) Push the y position of the pixel based on it's color value
(red pixels stay where they are but as they approach blue they go down)
I started off with this simple script and was hoping to just modify it but as a newbie- I'm lost!
How can I accomplish what I'm after? What should I look into?
Thanks!
I'm trying rearrange the pixels of an image based on color with a few things in mind.
1) Preserve the x position of the pixel
2) Push the y position of the pixel based on it's color value
(red pixels stay where they are but as they approach blue they go down)
I started off with this simple script and was hoping to just modify it but as a newbie- I'm lost!
How can I accomplish what I'm after? What should I look into?
- PImage img;
- void setup() {
- size(640, 480);
- img = loadImage("Gradient_teapot.jpg");
- }
- void draw() {
- size(640, 480);
- background(0);
- loadPixels();
- for (int y = 0; y<height; y+=1 ) {
- for (int x = 0; x<width; x+=1) {
- int loc = x + y*img.width;
- float r = red (img.pixels[loc]);
- float b = blue (img.pixels[loc]);
- pushMatrix();
- translate(x,y);
- stroke(r,b);
- if (r > 1 && r < 255) {
- line(0,0,0,0);
- }
- if (b > 1 && b < 255) {
- line(0,240,0,0);
- }
- popMatrix();
- }
- }
- println("done");
- noLoop();
- }
Thanks!
1