We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Turning Colored Rectangle
Page Index Toggle Pages: 1
Turning Colored Rectangle (Read 597 times)
Turning Colored Rectangle
Mar 10th, 2008, 7:14am
 
Just a turning colored rectangle.
I had hoped for nicer colors, but overlapping many rectangles is washing out colors.
Press right mouse key for randomizing.
Code:
// mouse left-click to save image
// mouse right-click to randomize parameters

String save_name = "pic";
int save_count=0;
//
int margin;
//
float rcol,gcol,bcol;
float ircol,igcol,ibcol;
color rgbcol,gbrcol,brgcol;
color irgbcol,igbrcol,ibrgcol;
float drcol,dgcol,dbcol;
boolean blackAndWhite;
//
boolean rectRing;
float strokeAlphaCore,strokeAlphaInner,strokeAlphaOuter;
float fillAlphaCore,fillAlphaInner,fillAlphaOuter;
int rMode,eMode;
int modCore,modInner,modOuter;
int countCore,countInner,countOuter;
//
float widthin,heightin;
float width2,height2;
float width2in,height2in;
float rwidth,rheight;
float rwidthin,rheightin;
float rwidthin2,rheightin2;
float rwidthin3,rheightin3;
//
float rot_cumul=0;
float rot_del=PI/64;

void setup(){
margin=250;
size (1000,1000);
background(0);
width2=width/2;
height2=height/2;
widthin=(width-2*margin);
heightin=(height-2*margin);
width2in=widthin/2;
height2in=heightin/2;
setDefaultParameters();
}

void draw(){
translate(width2,height2);
rotate(rot_cumul);
translate(-width2,-height2);
//
rwidth=random(width);
rheight=random(height);
rwidthin=random(widthin);
rheightin=random(heightin);
rwidthin2=rwidthin/2;
rheightin2=rheightin/2;
rwidthin3=rwidthin/3;
rheightin3=rheightin/3;
//
//
//draw center core
if (countCore==0) {
stroke(irgbcol,strokeAlphaCore);
fill(rgbcol,fillAlphaCore);
ellipse(width2,height2,rwidth,rheight);
}
//
//draw inner ring
if (countInner==0) {
stroke(igbrcol,strokeAlphaInner);
fill(gbrcol,fillAlphaInner);
rect(width2,height2,rwidthin2,rheightin2);
}
//
//draw outer ring
if (countOuter==0) {
stroke(brgcol,strokeAlphaOuter);
fill(brgcol,fillAlphaOuter);
if (rectRing) rect(width2+rwidthin3,height2+rheightin3,rwidthin3,rheightin3);
else ellipse(width2+rwidthin3,height2+rheightin3,rwidthin3,rheightin3);
}
//
rcol=(rcol+drcol);
gcol=(gcol+dgcol);
bcol=(bcol+dbcol);
ircol=255-rcol;
igcol=255-gcol;
ibcol=255-bcol;
if (rcol<0 || rcol>255) drcol*=-1;
if (gcol<0 || gcol>255) dgcol*=-1;
if (bcol<0 || bcol>255) dbcol*=-1;
if (blackAndWhite) {
rgbcol=color(rcol,rcol,rcol);
gbrcol=color(gcol,gcol,gcol);
brgcol=color(bcol,bcol,bcol);
irgbcol=color(ircol,ircol,ircol);
igbrcol=color(igcol,igcol,igcol);
ibrgcol=color(ibcol,ibcol,ibcol);
}
else {
rgbcol=color(rcol,gcol,bcol);
gbrcol=color(gcol,bcol,rcol);
brgcol=color(bcol,rcol,gcol);
irgbcol=color(ircol,igcol,ibcol);
igbrcol=color(igcol,ibcol,ircol);
ibrgcol=color(ibcol,ircol,igcol);
}
//
countCore=(++countCore)%modCore;
countInner=(++countInner)%modInner;
//
rot_cumul+=rot_del;
}//draw()

void setDefaultParameters(){
modCore=10;
modInner=3;
modOuter=1;
rcol=0;
gcol=64;
bcol=128;
drcol=0.2;
dgcol=0.5;
dbcol=0.9;
blackAndWhite=false;
strokeAlphaCore=3;
fillAlphaCore=1;
strokeAlphaInner=9;
fillAlphaInner=4;
strokeAlphaOuter=7;
fillAlphaOuter=3;
rectRing=true;
rMode=CORNER;
rectMode(rMode);
eMode=CENTER;
ellipseMode(eMode);
}//setDefaultParameters()

void setRandomParameters(){
modCore=(int)random(1,15);
modInner=(int)random(1,10);
modOuter=(int)random(1,5);
rcol=random(255);
gcol=random(255);
bcol=random(255);
drcol=random(0.1,1.3);
dgcol=random(0.1,1.3);
dbcol=random(0.1,1.3);
blackAndWhite=(random(1)<0.15);
strokeAlphaCore=random(1,16);
fillAlphaCore=random(1,12);
strokeAlphaInner=random(1,135);
fillAlphaInner=random(1,90);
strokeAlphaOuter=random(1,156);
fillAlphaOuter=random(1,104);
if (random(1)<0.85) rMode=CORNER;
else rMode=CENTER;
rectMode(rMode);
if (random(1)<0.85) eMode=CENTER;
else eMode=CORNER;
ellipseMode(eMode);
}//setRandomParameters()

void mousePressed() {
boolean mouseLeft=(mouseButton==LEFT);
if (mouseLeft) {
String save_time=nf(year()%1000,2)+nf(month(),2)+nf(day(),2)+nf(hour(),2)+nf(minute(),2)+nf(second(),2);
save_count++;
save (save_name+"_"+save_time+".png");
}
else {
setRandomParameters();
}
}//mousePressed()
Page Index Toggle Pages: 1