Flag waving simulation
in
Programming Questions
•
2 years ago
Hi there,
I have a pattern of rectangles, ordered in my screen as a grid.
I need to make each column of this grid escalates sequentially for a waving flag effect.
Each column has assigned a start frame, I need to know how to set the "initial frame" to achieve the effect of flag waving.
Any idea?
THANKS!
Code:
int hRects;
int vRects;
int totalRects;
int currentFrame = 0;
CustomRect[] rects;
void setup() {
frameRate(25);
size(800,600);
// Setup Rects
hRects = width / 30;
vRects = height / 30;
totalRects = hRects * vRects;
rects = new CustomRect[totalRects];
// Init Rects
addRects();
}
void draw() {
background(0);
// Exec rects ------------------------------
for (int i = 0; i < rects.length; i++ ) {
CustomRect rect = rects[i];
rect.drawBg(currentFrame);
}
currentFrame++;
}
void addRects(){
int hStep = width/hRects;
int vStep = height/vRects;
int xCounter = 0;
int yCounter = 0;
int xPos = hStep/2;
int yPos = vStep/2;
int initialFrame = 0;
// Add rects
for (int i = 0; i < totalRects; i++ ) {
CustomRect rect = new CustomRect();
rect.setName("RECT_" + i);
rect.init(xPos, yPos);
rects[i] = rect;
rect.setInitialFrame( ??? );// <---- i need to know how value pass here!!!
if(xCounter == hRects-1){
xPos = vStep/2;
yPos = yPos + vStep;
xCounter = 0;
yCounter++;
} else {
xPos = xPos + hStep;
xCounter++;
}
}
}
1