We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there,
I am very new to Processing. I have this image, and over it I am placing SVG's - who's width and height are based on the Greyscale value of the pixel underneath.
My problem - I am wanting the greyscale value to affect the rotation of the SVG; so the lower the Greyscale value the less rotated the SVG and the higher the value the more rotated. The problem is when I apply any sort of rotation within the code it rotates the whole grid! - How can I get each SVG to rotate within its each individual grid block?
Many thanks in advance,
Here is the code -
PShape myShape;
PImage img ;
void setup() {
size(900, 600);
img = loadImage("photo.png");
myShape = loadShape("module_1.svg");
noStroke();
}
void draw() {
background(255);
for (int gridX = 0; gridX< img.width; gridX++) {
for (int gridY = 0; gridY < img.height; gridY++) {
float tileWidth = width / (float)img.width ;
float tileHeight = height / (float)img.height ;
float posX = tileWidth*gridX ;
float posY = tileHeight*gridY ;
color c = img.pixels[gridY*img.width+gridX] ;
int greyscale = round(red(c)*0.222+green(c)*0.707+blue(c)*0.071) ;
pushMatrix();
float w1 = map(greyscale, 0, 255, 3, 0.1);
resetMatrix();
shape(myShape, posX, posY, w1, w1);
popMatrix();
}
}
}
Answers
not sure why the strange layout to the post
@VEL -- have you read the Processing Tutorial 2D Transformations? Look at the section "Rotating the Correct Way" for the basic concept. Does that help?
@jeremydouglass
Thanks for the reply, the documentation is very helpful , from what I understand I have added a 'translate' to set the start of the loop which makes the grid,then I have added another 'translate' pointing to the X and Y. However still no luck, I think it's missing something fundamental but don't know what , any thoughts?
here's the code -
an update...i've learned that I was using 'pushMatrix();' incorrectly. Here is an update with some progress but still not the desired result.
It would help testing and feedback if you can provide links to
pic.png
/module_1.svg
, or point to comparable files online.Or should the sketch work the same with any images of any size / type?
Followup:
For those interested in mapping shapes to a background image by a parameter, here is a working sketch based on the approach above.
Source images:
Color map
Pointer Hand Gesture SVG
Sketch:
Output:
@jeremydouglass - god bless man! thanks for taking the time to do this, think other new people like myself will find this helpful too.
Many thanks