Skip to content

Commit fe4d75f

Browse files
committed
Reworked Color Examples
1 parent 0ea25d7 commit fe4d75f

File tree

11 files changed

+26094
-129
lines changed

11 files changed

+26094
-129
lines changed

package-lock.json

Lines changed: 25970 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
/*
22
* @name Hue
3-
* @arialabel Vertical bars of color appear in a gradient pattern as the user drags their mouse across the screen
4-
* @description Hue is the color reflected from or transmitted through an
5-
* object and is typically referred to as the name of the color (red, blue,
6-
* yellow, etc.) Move the cursor vertically over each bar to alter its hue.
3+
* @arialabel Horizontal bars that step through different hues, controlled using a loop
4+
* @description Hue is that attribute of a color by the virtue of
5+
* which it is perceptible as red, green, blue etc. It is independent
6+
* of saturation(intensity) and brightness.
77
*/
8-
const barWidth = 20;
9-
let lastBar = -1;
10-
118
function setup() {
12-
createCanvas(720, 400);
13-
colorMode(HSB, height, height, height);
14-
noStroke();
15-
background(0);
9+
createCanvas(400, 400) ;
10+
colorMode(HSB);
1611
}
1712

1813
function draw() {
19-
let whichBar = mouseX / barWidth;
20-
if (whichBar !== lastBar) {
21-
let barX = whichBar * barWidth;
22-
fill(mouseY, height, height);
23-
rect(barX, 0, barWidth, height);
24-
lastBar = whichBar;
14+
background (220)
15+
noStroke();
16+
17+
for (let i = 0;i<12;i++){
18+
19+
//with each iteration of the loop
20+
//the hue steps down by 25
21+
22+
//fill(hue,saturation,brightness)
23+
fill (360-i*25,100,100) ;
24+
25+
rect (0,i*height/12,width,height/12) ;
2526
}
2627
}
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
/*
22
* @name Saturation
3-
* @arialabel Vertical bars of color appear in a gradient rainbow pattern as the user drags their mouse across the screen. The saturation of these bars change as the user’s mouse drags through
3+
* @arialabel Horizontal bars that step through saturation(high to low) of a color, controlled using a loop
44
* @description Saturation is the strength or purity of the color and
55
* represents the amount of gray in proportion to the hue. A "saturated"
66
* color is pure and an "unsaturated" color has a large percentage of gray.
7-
* Move the cursor vertically over each bar to alter its saturation.
87
*/
9-
const barWidth = 20;
10-
let lastBar = -1;
11-
128
function setup() {
13-
createCanvas(720, 400);
14-
colorMode(HSB, width, height, 100);
15-
noStroke();
9+
createCanvas(400, 400) ;
10+
colorMode(HSB);
1611
}
1712

1813
function draw() {
19-
let whichBar = mouseX / barWidth;
20-
if (whichBar !== lastBar) {
21-
let barX = whichBar * barWidth;
22-
fill(barX, mouseY, 66);
23-
rect(barX, 0, barWidth, height);
24-
lastBar = whichBar;
14+
background (220)
15+
noStroke();
16+
17+
for (let i = 0;i<6;i++){
18+
19+
//with each iteration of the loop
20+
//the saturation steps down by 20
21+
22+
//fill(hue,saturation,brightness)
23+
fill (28,100 - i*20,95) ;
24+
25+
rect (0,i*height/6,width,height/6) ;
2526
}
2627
}
Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,26 @@
11
/*
22
* @name Brightness
3-
* @arialabel A black and white photograph of an astronaut on the moon covered by black. The mouse acts as a light and a circular area of the photograph is illuminated where the mouse hovers
4-
* @description By Dan Shiffman. This program adjusts the brightness of a part
5-
* of the image by calculating the distance of each pixel to the mouse.
6-
* <p><em><span class="small"> To run this example locally, you will need
7-
* at least an image file and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">local server</a>.</span></em></p>
3+
* @arialabel Horizontal bars that step through brightness(high to low) of a color, controlled using a loop
4+
* @description Lightness is the amount of black or white that’s been mixed with a hue.
5+
* Adding white makes the color lighter and adding black makes it darker.
86
*/
9-
let img;
10-
11-
function preload() {
12-
img = loadImage('assets/moonwalk.jpg');
13-
}
14-
157
function setup() {
16-
createCanvas(720, 200);
17-
pixelDensity(1);
18-
img.loadPixels();
19-
loadPixels();
8+
createCanvas(400, 400) ;
9+
colorMode(HSB);
2010
}
2111

2212
function draw() {
23-
for (let x = 0; x < img.width; x++) {
24-
for (let y = 0; y < img.height; y++) {
25-
// Calculate the 1D location from a 2D grid
26-
let loc = (x + y * img.width) * 4;
27-
// Get the R,G,B values from image
28-
let r, g, b;
29-
r = img.pixels[loc];
30-
// Calculate an amount to change brightness based on proximity to the mouse
31-
let maxdist = 50;
32-
let d = dist(x, y, mouseX, mouseY);
33-
let adjustbrightness = (255 * (maxdist - d)) / maxdist;
34-
r += adjustbrightness;
35-
// Constrain RGB to make sure they are within 0-255 color range
36-
r = constrain(r, 0, 255);
37-
// Make a new color and set pixel in the window
38-
//color c = color(r, g, b);
39-
let pixloc = (y * width + x) * 4;
40-
pixels[pixloc] = r;
41-
pixels[pixloc + 1] = r;
42-
pixels[pixloc + 2] = r;
43-
pixels[pixloc + 3] = 255;
44-
}
13+
background (220)
14+
noStroke();
15+
16+
for (let i = 0;i<6;i++){
17+
18+
//with each iteration of the loop
19+
//the brightness steps down by 20
20+
21+
//fill(hue,saturation,brightness)
22+
fill (28,100,100-i*20) ;
23+
24+
rect (0,i*height/6,width,height/6) ;
4525
}
46-
updatePixels();
4726
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* @name Color Wheel
3+
* @arialabel 36 Circles in a circular arrangement cycling through different hues of the color wheel
4+
* @description A color wheel is an organization of color hues around a circle,
5+
* which shows the relationships between primary colors, secondary colors, tertiary colors etc.
6+
*/
7+
function setup() {
8+
createCanvas(400, 400) ;
9+
colorMode(HSB);
10+
11+
//setting angle mode to degrees
12+
//to aid in positioning of circles
13+
angleMode(DEGREES);
14+
}
15+
16+
function draw() {
17+
background (220)
18+
noStroke();
19+
20+
//loop steps through 36 times drawing
21+
//a circle with a separate hue each time
22+
23+
for (let i = 0;i<36;i++){
24+
25+
//determines position of circles
26+
x = 200 + 100*cos(i*10);
27+
y = 200 + 100*sin(i*10);
28+
29+
//i * 10 allows to cover the entire hue range
30+
//the first circle has a hue of 0*10 = 0
31+
// last circle has has a hue of 35*10 = 350
32+
// hue of 0 and 360 are identical
33+
34+
fill(i*10,100,100);
35+
circle(x,y,50);
36+
}
37+
}

src/data/examples/en/07_Color/07_Lerp_Color.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)