Skip to content

Commit 0afb3f3

Browse files
authored
Merge pull request #5314 from JetStarBlues/improveSpecularColorExample
Improve clarity of `specularColor()` example
2 parents e14868d + a2e8dfa commit 0afb3f3

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/webgl/light.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,27 +139,45 @@ p5.prototype.ambientLight = function(v1, v2, v3, a) {
139139
* @example
140140
* <div>
141141
* <code>
142+
* let setRedSpecularColor = true;
143+
*
142144
* function setup() {
143145
* createCanvas(100, 100, WEBGL);
144146
* noStroke();
145147
* }
146148
*
147149
* function draw() {
148150
* background(0);
149-
* shininess(20);
150-
* ambientLight(50);
151-
* specularColor(255, 0, 0);
152-
* pointLight(255, 0, 0, 0, -50, 50);
153-
* specularColor(0, 255, 0);
154-
* pointLight(0, 255, 0, 0, 50, 50);
155-
* specularMaterial(255);
156-
* sphere(40);
151+
*
152+
* ambientLight(60);
153+
*
154+
* // add a point light to showcase specular color
155+
* // -- use mouse location to position the light
156+
* let lightPosX = mouseX - width / 2;
157+
* let lightPosY = mouseY - height / 2;
158+
* // -- set the light's specular color
159+
* if (setRedSpecularColor) {
160+
* specularColor(255, 0, 0); // red specular highlight
161+
* }
162+
* // -- create the light
163+
* pointLight(200, 200, 200, lightPosX, lightPosY, 50); // white light
164+
*
165+
* // use specular material with high shininess
166+
* specularMaterial(150);
167+
* shininess(50);
168+
*
169+
* sphere(30, 64, 64);
170+
* }
171+
*
172+
* function mouseClicked() {
173+
* setRedSpecularColor = !setRedSpecularColor;
157174
* }
158175
* </code>
159176
* </div>
160177
*
161178
* @alt
162-
* different specular light sources from top and bottom of canvas
179+
* Sphere with specular highlight. Clicking the mouse toggles the
180+
* specular highlight color between red and the default white.
163181
*/
164182

165183
/**

0 commit comments

Comments
 (0)