n00b here, trying to learn this fantastic language but am having some trouble. I am taking this one step at a time but am missing something. My end idea is to have 100x100 pix rect’s fade in and fade out in random spots on a 1920x1080 screen. I just want to start with getting one at a time to display, stay for x seconds and then go away. I want the next rect to display y seconds after the previous so that several rects are on the screen at one time, but creating an endless loop of rects. Lets say at one time there are 50.
I started small with 100x100 screen and 20 rects. I have an array of x and y values to use and a for loop to display them all, but obviously all at once. I saw that there is a delay() function but I am pretty sure that this is not the way to go.
What should I look into to accomplish this? I have been reading Shiffmans learning processing book and am about half way through. Thanks in advance!!
L-
int stageW = 1000;
int stageH = 1000;
int squaresize = 100;
String pathDATA = "../../data/";
int numAssets = 200;
PVector[] xyz = new PVector[numAssets];
void settings() {
size(stageW, stageH, P3D);
}
void setup() {
background(0);
for (int i = 0; i < numAssets; i++) { //randomizing x and y for the numassets (does once)
PVector _pt = new PVector();
_pt.x = (int)random(stageW-100);
_pt.y = (int)random(stageH-100);
xyz[i] = _pt;
}
}
void draw() {
for (int i = 0; i < 20; i++){
square(xyz[i].x, xyz[i].y);
}
}
void square(float x, float y){
noStroke();
fill(0, 34, 68, 235);
pushMatrix();
translate(x, y, 0);
rect(0, 0, 100, 100);
popMatrix();
}
Thanks for the reply. Lowering the frame count is not really a long term solution for me tho, I have plans to keep this in HD for some color changes and hopefully opacity changes. I understand what you are saying about draw tho, so I am assuming I need to create an object or class for the squares I want to make, but to trigger them I need some sort of way to do this not all at once, so is there something I am missing that would do that without adjusting the frame rate?
you can use frameCount also (in the previous sketch I reduced the frameRate, now I check frameCount to slowly increase the numbers of rects shown in the for-loop)
(Don’t confuse frameCount and frameRate)
int stageW = 1000;
int stageH = 1000;
int squaresize = 100;
String pathDATA = "…/…/data/";
int numAssets = 200;
PVector[] xyz = new PVector[numAssets];
int upperBorder=0;
void settings() {
size(stageW, stageH, P3D);
}
void setup() {
background(0);
for (int i = 0; i < numAssets; i++) { //randomizing x and y for the numassets (does once)
PVector _pt = new PVector();
_pt.x = (int)random(stageW-100);
_pt.y = (int)random(stageH-100);
xyz[i] = _pt;
}
}
void draw() {
background(0);
for (int i = 0; i < min(upperBorder, numAssets); i++) {
square(xyz[i].x, xyz[i].y);
}//for
if (frameCount%29==0) {
upperBorder++;
}
}
void square(float x, float y) {
noStroke();
fill(0, 34, 68, 235);
pushMatrix();
translate(x, y, 0);
rect(0, 0, 100, 100);
popMatrix();
}