I’m new to Processing and, in short, I’d like the Z axis of an object to keep ‘growing’ and ‘shrinking’ but I don’t know the best way to do this.
I thought maybe having two alternating timers might work, but that seems like several unnecessary steps after I spotted this post about growing and shrinking a 2D circle.
However, I can’t quite figure out if this idea can be moved over into 3D, since I have a z variable that uses fixed min and max values.
I also like frameCount/2 being used a variable/as a modifier at the end of the ‘float z’ line, as it adds a nice ‘explode’ effect but as far as I understand it, frameCount can’t be “reversed”, can it?
Here’s my code that currently rasterizes an image and rotates it on the Y axis; I’ll add the specific image at the bottom in case this helps with testing…!
PImage img;
void setup() {
size(900,900, P3D);
img = loadImage("SKULL FRONT.png");
img.resize(900,0);
}
void draw() {
background(#000000);
fill(#FFFFFF);
noStroke();
sphereDetail(1);
float tiles = 100;
float tileSize = width/tiles;
push();
translate(width/2, height/2);
rotateY(radians(frameCount /2));
for (int x = 0; x < tiles; x++) {
for(int y = 0; y < tiles; y++) {
color c = img.get(int(x*tileSize), int(y*tileSize));
float b = map(brightness(c),0,255,0,1);
float z = map(b,0,1,-300, 300);
push();
translate(x*tileSize - width/2, y*tileSize - height/2, z);
sphere(tileSize*b*0.8);
pop();
}
}
pop();
}
I’m experimenting with generative art in Processing so I get the use of sin, and I have some understanding that % is modulo, and this can help keep values neatly constrained - is that an okay way of looking at it?
I’ve never seen TAU before, though - looking at the ref for this, am I right in thinking it’s also for keeping something (in this case, sin) constrained but to a set ratio? Trying to get my head around it haha
frameCount%360 will count from 0 to 359 and repeat.
TAU = TWO_PI which is in radians.
TAU/360 divides TAU into 360 parts (in radians) which is equal to 1 degree.
Or you could have used 0.01745329251 but the fraction provides clarity on the angle increment.
sin() requires radians:
Example here (they are using degrees and converting to radians):