Skip to content

Commit 87ed8c5

Browse files
committed
heavily simplified brightness example
1 parent 9349888 commit 87ed8c5

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

content/examples/Basics/Color/Brightness/Brightness.pde

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@
44
*
55
* Brightness is the relative lightness or darkness of a color.
66
* Move the cursor vertically over each bar to alter its brightness.
7+
*
8+
* Updated 28 February 2010.
79
*/
810

911
int barWidth = 5;
10-
int[] brightness;
12+
int lastBar = -1;
1113

12-
void setup()
13-
{
14+
void setup() {
1415
size(200, 200);
15-
colorMode(HSB, 360, height, height);
16-
brightness = new int[width/barWidth];
16+
colorMode(HSB, 360, 100, height);
17+
noStroke();
18+
background(0);
1719
}
1820

19-
void draw()
20-
{
21-
int j = 0;
22-
for (int i = 0; i <= (width-barWidth); i += barWidth) {
23-
noStroke();
24-
if ((mouseX > i) && (mouseX < i+barWidth)) {
25-
brightness[j] = mouseY;
26-
}
27-
fill(i, height, brightness[j]);
28-
rect(i, 0, barWidth, height);
29-
j++;
21+
void draw() {
22+
int whichBar = mouseX / barWidth;
23+
if (whichBar != lastBar) {
24+
int barX = whichBar * barWidth;
25+
fill(barX, 100, mouseY);
26+
rect(barX, 0, barWidth, height);
27+
lastBar = whichBar;
3028
}
3129
}

0 commit comments

Comments
 (0)