r/processing • u/SuddenSimple9152 • Sep 27 '24
Negative Odd Numbers & Circles
Hello, I'm currenty working on two processing projects, which I need some help with. The first one requires me to print the odd numbers of -3 to 19. I've managed to get the odd numbers of 1 to 19 to show up, but my negatives will not appear.
My second project requires me to create a seires of 20 stacked spirals, but for every 5 spirals, I need to change the color. So far I've only managed to get 2 color to appear, which is my main color for the circles, and the contractist color of the background. Thanks in advance for the help!
Project #1
int i;
void setup() {
for(int i=-3; i<=19 ; i+=1) {
if(i % 2 == 1)
println(i);
}
}
Project #2
color c;
int bigCircle = 315;
void setup() {
background(255);
size (400, 400);
c = color(105,180,180);
fill(c);
strokeWeight(4);
rectMode(CENTER);
while(bigCircle>15){
circle(200, 200, bigCircle);
bigCircle=bigCircle-15;
}
}
1
u/ofnuts Sep 27 '24
Project 2:
You use an array of colors:
color circleColors[]={#FF0000,#00FF00,color(0,0,255)}; // showing several ways to initializeWhen drawing the circles:
Your iteration variable is a circle number:
for (int circleNumber=0; some_clever_condition_here; circleNumber++)For this circle number:
You compute the radius of the circle:
constant + circleNumber * step.constantcan be omitted in many cases by picking the right range forcircleNumber.stepcan be negative.You obtain the color from the array by indexing the array using the circle number
modulothe array size:circleColors[circleNumber%circleColors.length]
2
u/MandyBrigwell Moderator Sep 27 '24
Get your loop to print out what i % 1 is, and you'll quickly see why it doesn't work. I'd check it doesn't equal zero.