-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg.pde
93 lines (72 loc) · 1.64 KB
/
bg.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
PImage backgroundPalette;
GLGraphicsOffScreen bg;
Background backgrounds[] = new Background[]
{
null,
new LoadingStripes(),
new DiagonalStripes(),
new DoubleHorizon(),
new ConcentricSquares(),
new ConcentricHexagons(),
new SpinningTriangles()
};
Background activeBackground = null;
void setupBackground()
{
backgroundPalette = loadImage( "background_palette.jpg" );
if ( activeBackground != null )
{
activeBackground.begin();
}
}
void setActiveBackground( int bindx )
{
activeBackground = backgrounds[bindx];
if ( activeBackground != null )
{
activeBackground.begin();
}
}
int backgroundColorCount = 10;
color getBackgroundColor( int index )
{
int pixel = index * (backgroundPalette.width / backgroundColorCount) + 2;
return backgroundPalette.get( pixel, 5 );
}
void updateBackground( final float dt )
{
if ( activeBackground != null )
{
activeBackground.update( dt );
}
}
void renderBackground( GLGraphicsOffScreen surface )
{
if ( activeBackground != null )
{
bg = surface;
bg.pushMatrix();
bg.translate( -bg.width/2, -bg.height/2, -200 );
colorMode( HSB, 360, 100, 100 );
bg.colorMode( HSB, 360, 100, 100 );
activeBackground.render();
bg.popMatrix();
}
}
abstract class Background
{
float hueOffset;
void begin() {}
void update( final float dt )
{
hueOffset = (hueOffset + 360*dt) % 360;
}
color transformColor( color in )
{
float h = (hue(in) + hueOffset) % 360;
float s = saturation(in);
float b = brightness(in) * 0.5f;
return color( h, s, b );
}
abstract void render();
}