We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to change the colours within a set of rotated rectangles using an array of set colours
I can get the colours to change as a strobe using fill(ccolor[(int)random(ccolor.length)]); but I would like each colour to be assigned to a rectangle and stay with it.
I've done lots of internet searching but can't find anything that helps me!
//VARIABLES
float sqsize=350;
float rangle;
color [] ccolor=``{color(190,75,90),color(240,160,100),color(250,210,80),color(145,180,70),color(80,180,90),color(170,125,185) };
//SETUP
void setup()
{
size(550,550);
smooth();
rectMode(CENTER);
}
//DRAW
void draw()
{
background(255);
translate(width/2,height/2);
float cmousex=float(mouseX);
rangle=(cmousex/width)*(PI/2);
println(mouseX);
println(rangle);
for (int i=0;i<200;i++)
{
rect(0,0,sqsize,sqsize);
fill(ccolor[i]);
rotate(rangle);
sqsize=sqsize*cos(rangle);
}
sqsize=350;
}
Answers
In line 28 you will run into an error, because it will get greater than the size of you color-array. You could use modulo
%
to pick the colors for example.fill( ccolor[ i % ccolor.length ] );
BTW: Your sketch looks nice.
You're gonna need a class to represent a rectangle and each of its properties:
https://Processing.org/tutorials/objects/
Thanks so much benja!