Mathematical problem
in
Programming Questions
•
10 months ago
Hi,
i've some mathematics question, i'm trying to come up with a formula which is dynamic.
now i'm trying to insert n number of pictures with the same width, and same spacing in between them, i'm trying to make sure that the pictures are position in the center, which means if i have 4 pictures, i want the 1st picture to the last to be sort of as 1 picture and position in the center.
for example:
4 Pic
---(img)--(img)--(img)--(img)---
3 Pic
----(img)--(img)--(img)----
the picture will as a whole will always be at the center of the scree
ArrayList<Float> pos = new ArrayList<Float>();
float imgSize;
int numOfPic = 4;
PImage picture;
void setup() {
size(800, 500);
imgSize = width*0.15;
picture = loadImage( "picture.png" );
setPicPos();
}
void draw() {
//background(255);
for (int i = 0; i != numOfPic; i++) {
println(pos.get(i));
image(picture, pos.get(i), height*0.5, imgSize, imgSize);
}
}
void setPicPos() {
float spacing = imgSize * 2.5;
float totalLength = (imgSize*numOfPic) + ((spacing - imgSize)*numOfPic - 1);
float position = width - (totalLength/2);
for (int i = 0; i != numOfPic; i++) {
pos.add(position);
position += spacing;
}
}
hope you all could help :)
1