-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg_ConcentricSquares.pde
55 lines (46 loc) · 1.21 KB
/
bg_ConcentricSquares.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class ConcentricSquares extends Background
{
color stripeColors[] = new color[8];
float animation;
void begin()
{
super.begin();
// pick our colors
int colorIndex = (int)random(0, backgroundColorCount);
for( int i = 0; i < stripeColors.length; ++i )
{
stripeColors[i] = getBackgroundColor( colorIndex );
colorIndex += (int)random(1,3);
colorIndex %= backgroundColorCount;
}
}
void update( final float dt )
{
super.update( dt );
animation = (animation + dt*0.25f) % 1;
}
void render()
{
float bigDim = bg.width + 200;
float stripeHeight = (bigDim / stripeColors.length );
bg.rectMode( CENTER );
bg.noStroke();
bg.pushMatrix();
bg.translate( bg.width/2, bg.height/2, 0 );
for( int i = 0; i < stripeColors.length; ++i )
{
color c = transformColor( stripeColors[i] );
bg.fill( c );
float dim = stripeHeight + i*stripeHeight + bigDim*animation;
if ( dim > bigDim + stripeHeight )
{
dim -= bigDim;
}
bg.pushMatrix();
bg.translate( 0, 0, dim * -0.1f );
bg.rect( 0, 0, dim, dim );
bg.popMatrix();
}
bg.popMatrix();
}
}