p5 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src → dist}/accessibility/color_namer.js +48 -3
- package/{src → dist}/accessibility/describe.js +2 -2
- package/{src → dist}/accessibility/gridOutput.js +2 -2
- package/dist/accessibility/index.js +60 -0
- package/{src → dist}/accessibility/outputs.js +2 -2
- package/{src → dist}/accessibility/textOutput.js +2 -2
- package/dist/app.js +120 -0
- package/{src → dist}/color/color_conversion.js +48 -10
- package/{src → dist}/color/color_spaces/hsb.js +3 -1
- package/dist/color/creating_reading.js +3 -0
- package/dist/color/index.js +13 -0
- package/dist/color/p5.Color.culori.js +1 -0
- package/dist/color/p5.Color.js +3 -0
- package/{src → dist}/color/setting.js +9 -6
- package/{src/core/constants.js → dist/constants-C-g_eAdC.js} +266 -130
- package/{src → dist}/core/States.js +3 -1
- package/dist/core/constants.js +1 -0
- package/{src → dist}/core/environment.js +7 -6
- package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
- package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
- package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
- package/dist/core/friendly_errors/index.js +23 -0
- package/dist/core/friendly_errors/param_validator.js +5455 -0
- package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
- package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
- package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
- package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
- package/{src → dist}/core/helpers.js +9 -6
- package/dist/core/init.js +105 -0
- package/dist/core/internationalization.js +302 -0
- package/dist/core/legacy.js +73 -0
- package/dist/core/main.js +44 -0
- package/dist/core/noop.js +3 -0
- package/dist/core/p5.Graphics.js +40 -0
- package/dist/core/p5.Renderer.js +11 -0
- package/dist/core/p5.Renderer2D.js +44 -0
- package/dist/core/reference.js +1 -0
- package/dist/core/rendering.js +40 -0
- package/{src → dist}/core/structure.js +3 -3
- package/{src → dist}/core/transform.js +2 -2
- package/{src/color/creating_reading.js → dist/creating_reading-D4AAKRbx.js} +841 -13
- package/{src → dist}/data/index.js +3 -1
- package/{src → dist}/data/local_storage.js +2 -8
- package/{src → dist}/dom/dom.js +11 -5
- package/dist/dom/index.js +18 -0
- package/{src → dist}/dom/p5.Element.js +14 -12
- package/{src → dist}/dom/p5.File.js +4 -4
- package/{src → dist}/dom/p5.MediaElement.js +10 -4
- package/{src → dist}/events/acceleration.js +2 -2
- package/{src → dist}/events/index.js +3 -1
- package/{src → dist}/events/keyboard.js +14 -11
- package/{src → dist}/events/pointer.js +16 -17
- package/dist/image/const.js +9 -0
- package/{src → dist}/image/filterRenderer2D.js +57 -37
- package/{src → dist}/image/filters.js +1 -3
- package/dist/image/image.js +40 -0
- package/dist/image/index.js +51 -0
- package/dist/image/loading_displaying.js +40 -0
- package/dist/image/p5.Image.js +11 -0
- package/{src → dist}/image/pixels.js +4 -3
- package/{src → dist}/io/csv.js +72 -70
- package/dist/io/files.js +40 -0
- package/dist/io/index.js +51 -0
- package/{src → dist}/io/p5.Table.js +6 -6
- package/{src → dist}/io/p5.TableRow.js +3 -4
- package/{src → dist}/io/p5.XML.js +2 -5
- package/{src → dist}/io/utilities.js +1 -1
- package/{src/core/p5.Renderer2D.js → dist/main-s72KWcUy.js} +735 -57
- package/{src → dist}/math/Matrices/Matrix.js +10 -8
- package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
- package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
- package/{src → dist}/math/calculation.js +2 -2
- package/{src → dist}/math/index.js +6 -3
- package/{src → dist}/math/math.js +2 -2
- package/{src → dist}/math/noise.js +2 -2
- package/{src → dist}/math/p5.Matrix.js +7 -4
- package/{src → dist}/math/p5.Vector.js +6 -6
- package/{src → dist}/math/random.js +2 -2
- package/{src → dist}/math/trigonometry.js +16 -15
- package/{src/image/p5.Image.js → dist/p5.Renderer-CwAYZOC2.js} +390 -19
- package/dist/rendering--aAe5aq3.js +24925 -0
- package/{src → dist}/shape/2d_primitives.js +18 -17
- package/{src → dist}/shape/attributes.js +18 -17
- package/{src → dist}/shape/curves.js +2 -2
- package/{src → dist}/shape/custom_shapes.js +44 -64
- package/{src → dist}/shape/index.js +10 -2
- package/{src → dist}/shape/vertex.js +2 -3
- package/dist/type/index.js +25 -0
- package/{src → dist}/type/lib/Typr.js +76 -94
- package/{src → dist}/type/p5.Font.js +37 -61
- package/{src → dist}/type/textCore.js +34 -57
- package/{src → dist}/type/unicodeRanges.js +3 -1
- package/{src → dist}/utilities/conversion.js +2 -2
- package/{src → dist}/utilities/index.js +3 -1
- package/{src → dist}/utilities/time_date.js +6 -7
- package/{src → dist}/utilities/utility_functions.js +2 -2
- package/dist/webgl/3d_primitives.js +40 -0
- package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
- package/{src → dist}/webgl/GeometryBuilder.js +12 -8
- package/{src → dist}/webgl/ShaderGenerator.js +79 -82
- package/{src → dist}/webgl/ShapeBuilder.js +26 -23
- package/dist/webgl/index.js +76 -0
- package/{src → dist}/webgl/interaction.js +7 -6
- package/dist/webgl/light.js +40 -0
- package/{src → dist}/webgl/loading.js +45 -12
- package/dist/webgl/material.js +40 -0
- package/dist/webgl/p5.Camera.js +40 -0
- package/{src → dist}/webgl/p5.DataArray.js +3 -5
- package/dist/webgl/p5.Framebuffer.js +40 -0
- package/{src → dist}/webgl/p5.Geometry.js +12 -15
- package/{src → dist}/webgl/p5.Quat.js +5 -4
- package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
- package/dist/webgl/p5.RendererGL.js +40 -0
- package/dist/webgl/p5.Shader.js +40 -0
- package/dist/webgl/p5.Texture.js +40 -0
- package/{src → dist}/webgl/text.js +51 -9
- package/lib/p5.esm.js +102 -48
- package/lib/p5.js +102 -48
- package/lib/p5.min.js +1 -1
- package/package.json +17 -16
- package/translations/dev.js +6 -6
- package/translations/index.js +1 -1
- package/src/README.md +0 -27
- package/src/accessibility/index.js +0 -13
- package/src/app.js +0 -61
- package/src/color/index.js +0 -9
- package/src/color/p5.Color.culori.js +0 -66
- package/src/color/p5.Color.js +0 -851
- package/src/core/README.md +0 -91
- package/src/core/friendly_errors/index.js +0 -13
- package/src/core/friendly_errors/param_validator.js +0 -561
- package/src/core/init.js +0 -58
- package/src/core/internationalization.js +0 -195
- package/src/core/legacy.js +0 -29
- package/src/core/main.js +0 -689
- package/src/core/noop.js +0 -1
- package/src/core/p5.Graphics.js +0 -696
- package/src/core/p5.Renderer.js +0 -408
- package/src/core/reference.js +0 -2060
- package/src/core/rendering.js +0 -697
- package/src/dom/index.js +0 -11
- package/src/image/const.js +0 -6
- package/src/image/image.js +0 -731
- package/src/image/index.js +0 -15
- package/src/image/loading_displaying.js +0 -1431
- package/src/io/files.js +0 -2210
- package/src/io/index.js +0 -11
- package/src/math/README.md +0 -40
- package/src/type/index.js +0 -9
- package/src/webgl/3d_primitives.js +0 -2741
- package/src/webgl/index.js +0 -37
- package/src/webgl/light.js +0 -1851
- package/src/webgl/material.js +0 -3854
- package/src/webgl/p5.Camera.js +0 -4010
- package/src/webgl/p5.Framebuffer.js +0 -1865
- package/src/webgl/p5.RendererGL.js +0 -2867
- package/src/webgl/p5.Shader.js +0 -1505
- package/src/webgl/p5.Texture.js +0 -541
- package/src/webgl/shaders/basic.frag +0 -6
- package/src/webgl/shaders/filters/base.frag +0 -22
- package/src/webgl/shaders/filters/base.vert +0 -19
- package/src/webgl/shaders/filters/blur.frag +0 -60
- package/src/webgl/shaders/filters/default.vert +0 -18
- package/src/webgl/shaders/filters/dilate.frag +0 -39
- package/src/webgl/shaders/filters/erode.frag +0 -39
- package/src/webgl/shaders/filters/gray.frag +0 -16
- package/src/webgl/shaders/filters/invert.frag +0 -15
- package/src/webgl/shaders/filters/opaque.frag +0 -12
- package/src/webgl/shaders/filters/posterize.frag +0 -29
- package/src/webgl/shaders/filters/threshold.frag +0 -23
- package/src/webgl/shaders/font.frag +0 -216
- package/src/webgl/shaders/font.vert +0 -44
- package/src/webgl/shaders/imageLight.vert +0 -33
- package/src/webgl/shaders/imageLightDiffused.frag +0 -82
- package/src/webgl/shaders/imageLightSpecular.frag +0 -134
- package/src/webgl/shaders/light.vert +0 -37
- package/src/webgl/shaders/light_texture.frag +0 -26
- package/src/webgl/shaders/lighting.glsl +0 -227
- package/src/webgl/shaders/line.frag +0 -74
- package/src/webgl/shaders/line.vert +0 -294
- package/src/webgl/shaders/normal.frag +0 -6
- package/src/webgl/shaders/normal.vert +0 -72
- package/src/webgl/shaders/phong.frag +0 -84
- package/src/webgl/shaders/phong.vert +0 -87
- package/src/webgl/shaders/point.frag +0 -29
- package/src/webgl/shaders/point.vert +0 -19
- package/src/webgl/shaders/sphereMapping.frag +0 -26
- package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
package/src/webgl/light.js
DELETED
|
@@ -1,1851 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module 3D
|
|
3
|
-
* @submodule Lights
|
|
4
|
-
* @for p5
|
|
5
|
-
* @requires core
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { RendererGL } from './p5.RendererGL';
|
|
9
|
-
import { Vector } from '../math/p5.Vector';
|
|
10
|
-
import { Color } from '../color/p5.Color';
|
|
11
|
-
|
|
12
|
-
function light(p5, fn){
|
|
13
|
-
/**
|
|
14
|
-
* Creates a light that shines from all directions.
|
|
15
|
-
*
|
|
16
|
-
* Ambient light does not come from one direction. Instead, 3D shapes are
|
|
17
|
-
* lit evenly from all sides. Ambient lights are almost always used in
|
|
18
|
-
* combination with other types of lights.
|
|
19
|
-
*
|
|
20
|
-
* There are three ways to call `ambientLight()` with optional parameters to
|
|
21
|
-
* set the light’s color.
|
|
22
|
-
*
|
|
23
|
-
* The first way to call `ambientLight()` has two parameters, `gray` and
|
|
24
|
-
* `alpha`. `alpha` is optional. Grayscale and alpha values between 0 and 255
|
|
25
|
-
* can be passed to set the ambient light’s color, as in `ambientLight(50)` or
|
|
26
|
-
* `ambientLight(50, 30)`.
|
|
27
|
-
*
|
|
28
|
-
* The second way to call `ambientLight()` has one parameter, color. A
|
|
29
|
-
* <a href="#/p5.Color">p5.Color</a> object, an array of color values, or a
|
|
30
|
-
* CSS color string, as in `ambientLight('magenta')`, can be passed to set the
|
|
31
|
-
* ambient light’s color.
|
|
32
|
-
*
|
|
33
|
-
* The third way to call `ambientLight()` has four parameters, `v1`, `v2`,
|
|
34
|
-
* `v3`, and `alpha`. `alpha` is optional. RGBA, HSBA, or HSLA values can be
|
|
35
|
-
* passed to set the ambient light’s colors, as in `ambientLight(255, 0, 0)`
|
|
36
|
-
* or `ambientLight(255, 0, 0, 30)`. Color values will be interpreted using
|
|
37
|
-
* the current <a href="#/p5/colorMode">colorMode()</a>.
|
|
38
|
-
*
|
|
39
|
-
* @method ambientLight
|
|
40
|
-
* @param {Number} v1 red or hue value in the current
|
|
41
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
42
|
-
* @param {Number} v2 green or saturation value in the current
|
|
43
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
44
|
-
* @param {Number} v3 blue, brightness, or lightness value in the current
|
|
45
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
46
|
-
* @param {Number} [alpha] alpha (transparency) value in the current
|
|
47
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
48
|
-
* @chainable
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* <div>
|
|
52
|
-
* <code>
|
|
53
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
54
|
-
* // Double-click the canvas to turn on the light.
|
|
55
|
-
*
|
|
56
|
-
* let isLit = false;
|
|
57
|
-
*
|
|
58
|
-
* function setup() {
|
|
59
|
-
* createCanvas(100, 100, WEBGL);
|
|
60
|
-
*
|
|
61
|
-
* describe('A sphere drawn against a gray background. The sphere appears to change color when the user double-clicks.');
|
|
62
|
-
* }
|
|
63
|
-
*
|
|
64
|
-
* function draw() {
|
|
65
|
-
* background(200);
|
|
66
|
-
*
|
|
67
|
-
* // Enable orbiting with the mouse.
|
|
68
|
-
* orbitControl();
|
|
69
|
-
*
|
|
70
|
-
* // Control the light.
|
|
71
|
-
* if (isLit === true) {
|
|
72
|
-
* // Use a grayscale value of 80.
|
|
73
|
-
* ambientLight(80);
|
|
74
|
-
* }
|
|
75
|
-
*
|
|
76
|
-
* // Draw the sphere.
|
|
77
|
-
* sphere(30);
|
|
78
|
-
* }
|
|
79
|
-
*
|
|
80
|
-
* // Turn on the ambient light when the user double-clicks.
|
|
81
|
-
* function doubleClicked() {
|
|
82
|
-
* isLit = true;
|
|
83
|
-
* }
|
|
84
|
-
* </code>
|
|
85
|
-
* </div>
|
|
86
|
-
*
|
|
87
|
-
* <div>
|
|
88
|
-
* <code>
|
|
89
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
90
|
-
*
|
|
91
|
-
* function setup() {
|
|
92
|
-
* createCanvas(100, 100, WEBGL);
|
|
93
|
-
*
|
|
94
|
-
* describe('A faded magenta sphere drawn against a gray background.');
|
|
95
|
-
* }
|
|
96
|
-
*
|
|
97
|
-
* function draw() {
|
|
98
|
-
* background(200);
|
|
99
|
-
*
|
|
100
|
-
* // Enable orbiting with the mouse.
|
|
101
|
-
* orbitControl();
|
|
102
|
-
*
|
|
103
|
-
* // Turn on the lights.
|
|
104
|
-
* // Use a p5.Color object.
|
|
105
|
-
* let c = color('orchid');
|
|
106
|
-
* ambientLight(c);
|
|
107
|
-
*
|
|
108
|
-
* // Draw the sphere.
|
|
109
|
-
* sphere();
|
|
110
|
-
* }
|
|
111
|
-
* </code>
|
|
112
|
-
* </div>
|
|
113
|
-
*
|
|
114
|
-
* <div>
|
|
115
|
-
* <code>
|
|
116
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
117
|
-
*
|
|
118
|
-
* function setup() {
|
|
119
|
-
* createCanvas(100, 100, WEBGL);
|
|
120
|
-
*
|
|
121
|
-
* describe('A faded magenta sphere drawn against a gray background.');
|
|
122
|
-
* }
|
|
123
|
-
*
|
|
124
|
-
* function draw() {
|
|
125
|
-
* background(200);
|
|
126
|
-
*
|
|
127
|
-
* // Enable orbiting with the mouse.
|
|
128
|
-
* orbitControl();
|
|
129
|
-
*
|
|
130
|
-
* // Turn on the lights.
|
|
131
|
-
* // Use a CSS color string.
|
|
132
|
-
* ambientLight('#DA70D6');
|
|
133
|
-
*
|
|
134
|
-
* // Draw the sphere.
|
|
135
|
-
* sphere(30);
|
|
136
|
-
* }
|
|
137
|
-
* </code>
|
|
138
|
-
* </div>
|
|
139
|
-
*
|
|
140
|
-
* <div>
|
|
141
|
-
* <code>
|
|
142
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
143
|
-
*
|
|
144
|
-
* function setup() {
|
|
145
|
-
* createCanvas(100, 100, WEBGL);
|
|
146
|
-
*
|
|
147
|
-
* describe('A faded magenta sphere drawn against a gray background.');
|
|
148
|
-
* }
|
|
149
|
-
*
|
|
150
|
-
* function draw() {
|
|
151
|
-
* background(200);
|
|
152
|
-
*
|
|
153
|
-
* // Enable orbiting with the mouse.
|
|
154
|
-
* orbitControl();
|
|
155
|
-
*
|
|
156
|
-
* // Turn on the lights.
|
|
157
|
-
* // Use RGB values
|
|
158
|
-
* ambientLight(218, 112, 214);
|
|
159
|
-
*
|
|
160
|
-
* // Draw the sphere.
|
|
161
|
-
* sphere(30);
|
|
162
|
-
* }
|
|
163
|
-
* </code>
|
|
164
|
-
* </div>
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @method ambientLight
|
|
169
|
-
* @param {Number} gray grayscale value between 0 and 255.
|
|
170
|
-
* @param {Number} [alpha]
|
|
171
|
-
* @chainable
|
|
172
|
-
*/
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @method ambientLight
|
|
176
|
-
* @param {String} value color as a CSS string.
|
|
177
|
-
* @chainable
|
|
178
|
-
*/
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @method ambientLight
|
|
182
|
-
* @param {Number[]} values color as an array of RGBA, HSBA, or HSLA
|
|
183
|
-
* values.
|
|
184
|
-
* @chainable
|
|
185
|
-
*/
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @method ambientLight
|
|
189
|
-
* @param {p5.Color} color color as a <a href="#/p5.Color">p5.Color</a> object.
|
|
190
|
-
* @chainable
|
|
191
|
-
*/
|
|
192
|
-
fn.ambientLight = function (v1, v2, v3, a) {
|
|
193
|
-
this._assert3d('ambientLight');
|
|
194
|
-
// p5._validateParameters('ambientLight', arguments);
|
|
195
|
-
|
|
196
|
-
this._renderer.ambientLight(...arguments);
|
|
197
|
-
|
|
198
|
-
return this;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Sets the specular color for lights.
|
|
203
|
-
*
|
|
204
|
-
* `specularColor()` affects lights that bounce off a surface in a preferred
|
|
205
|
-
* direction. These lights include
|
|
206
|
-
* <a href="#/p5/directionalLight">directionalLight()</a>,
|
|
207
|
-
* <a href="#/p5/pointLight">pointLight()</a>, and
|
|
208
|
-
* <a href="#/p5/spotLight">spotLight()</a>. The function helps to create
|
|
209
|
-
* highlights on <a href="#/p5.Geometry">p5.Geometry</a> objects that are
|
|
210
|
-
* styled with <a href="#/p5/specularMaterial">specularMaterial()</a>. If a
|
|
211
|
-
* geometry does not use
|
|
212
|
-
* <a href="#/p5/specularMaterial">specularMaterial()</a>, then
|
|
213
|
-
* `specularColor()` will have no effect.
|
|
214
|
-
*
|
|
215
|
-
* Note: `specularColor()` doesn’t affect lights that bounce in all
|
|
216
|
-
* directions, including <a href="#/p5/ambientLight">ambientLight()</a> and
|
|
217
|
-
* <a href="#/p5/imageLight">imageLight()</a>.
|
|
218
|
-
*
|
|
219
|
-
* There are three ways to call `specularColor()` with optional parameters to
|
|
220
|
-
* set the specular highlight color.
|
|
221
|
-
*
|
|
222
|
-
* The first way to call `specularColor()` has two optional parameters, `gray`
|
|
223
|
-
* and `alpha`. Grayscale and alpha values between 0 and 255, as in
|
|
224
|
-
* `specularColor(50)` or `specularColor(50, 80)`, can be passed to set the
|
|
225
|
-
* specular highlight color.
|
|
226
|
-
*
|
|
227
|
-
* The second way to call `specularColor()` has one optional parameter,
|
|
228
|
-
* `color`. A <a href="#/p5.Color">p5.Color</a> object, an array of color
|
|
229
|
-
* values, or a CSS color string can be passed to set the specular highlight
|
|
230
|
-
* color.
|
|
231
|
-
*
|
|
232
|
-
* The third way to call `specularColor()` has four optional parameters, `v1`,
|
|
233
|
-
* `v2`, `v3`, and `alpha`. RGBA, HSBA, or HSLA values, as in
|
|
234
|
-
* `specularColor(255, 0, 0, 80)`, can be passed to set the specular highlight
|
|
235
|
-
* color. Color values will be interpreted using the current
|
|
236
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
237
|
-
*
|
|
238
|
-
* @method specularColor
|
|
239
|
-
* @param {Number} v1 red or hue value in the current
|
|
240
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
241
|
-
* @param {Number} v2 green or saturation value in the current
|
|
242
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
243
|
-
* @param {Number} v3 blue, brightness, or lightness value in the current
|
|
244
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
245
|
-
* @chainable
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* <div>
|
|
249
|
-
* <code>
|
|
250
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
251
|
-
*
|
|
252
|
-
* function setup() {
|
|
253
|
-
* createCanvas(100, 100, WEBGL);
|
|
254
|
-
*
|
|
255
|
-
* describe('A white sphere drawn on a gray background.');
|
|
256
|
-
* }
|
|
257
|
-
*
|
|
258
|
-
* function draw() {
|
|
259
|
-
* background(200);
|
|
260
|
-
*
|
|
261
|
-
* // Enable orbiting with the mouse.
|
|
262
|
-
* orbitControl();
|
|
263
|
-
*
|
|
264
|
-
* // No specular color.
|
|
265
|
-
* // Draw the sphere.
|
|
266
|
-
* sphere(30);
|
|
267
|
-
* }
|
|
268
|
-
* </code>
|
|
269
|
-
* </div>
|
|
270
|
-
*
|
|
271
|
-
* <div>
|
|
272
|
-
* <code>
|
|
273
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
274
|
-
* // Double-click the canvas to add a point light.
|
|
275
|
-
*
|
|
276
|
-
* let isLit = false;
|
|
277
|
-
*
|
|
278
|
-
* function setup() {
|
|
279
|
-
* createCanvas(100, 100, WEBGL);
|
|
280
|
-
*
|
|
281
|
-
* describe('A sphere drawn on a gray background. A spotlight starts shining when the user double-clicks.');
|
|
282
|
-
* }
|
|
283
|
-
*
|
|
284
|
-
* function draw() {
|
|
285
|
-
* background(200);
|
|
286
|
-
*
|
|
287
|
-
* // Enable orbiting with the mouse.
|
|
288
|
-
* orbitControl();
|
|
289
|
-
*
|
|
290
|
-
* // Style the sphere.
|
|
291
|
-
* noStroke();
|
|
292
|
-
* specularColor(100);
|
|
293
|
-
* specularMaterial(255, 255, 255);
|
|
294
|
-
*
|
|
295
|
-
* // Control the light.
|
|
296
|
-
* if (isLit === true) {
|
|
297
|
-
* // Add a white point light from the top-right.
|
|
298
|
-
* pointLight(255, 255, 255, 30, -20, 40);
|
|
299
|
-
* }
|
|
300
|
-
*
|
|
301
|
-
* // Draw the sphere.
|
|
302
|
-
* sphere(30);
|
|
303
|
-
* }
|
|
304
|
-
*
|
|
305
|
-
* // Turn on the point light when the user double-clicks.
|
|
306
|
-
* function doubleClicked() {
|
|
307
|
-
* isLit = true;
|
|
308
|
-
* }
|
|
309
|
-
* </code>
|
|
310
|
-
* </div>
|
|
311
|
-
*
|
|
312
|
-
* <div>
|
|
313
|
-
* <code>
|
|
314
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
315
|
-
*
|
|
316
|
-
* function setup() {
|
|
317
|
-
* createCanvas(100, 100, WEBGL);
|
|
318
|
-
*
|
|
319
|
-
* describe('A black sphere drawn on a gray background. An area on the surface of the sphere is highlighted in blue.');
|
|
320
|
-
* }
|
|
321
|
-
*
|
|
322
|
-
* function draw() {
|
|
323
|
-
* background(200);
|
|
324
|
-
*
|
|
325
|
-
* // Enable orbiting with the mouse.
|
|
326
|
-
* orbitControl();
|
|
327
|
-
*
|
|
328
|
-
* // Add a specular highlight.
|
|
329
|
-
* // Use a p5.Color object.
|
|
330
|
-
* let c = color('dodgerblue');
|
|
331
|
-
* specularColor(c);
|
|
332
|
-
*
|
|
333
|
-
* // Add a white point light from the top-right.
|
|
334
|
-
* pointLight(255, 255, 255, 30, -20, 40);
|
|
335
|
-
*
|
|
336
|
-
* // Style the sphere.
|
|
337
|
-
* noStroke();
|
|
338
|
-
*
|
|
339
|
-
* // Add a white specular material.
|
|
340
|
-
* specularMaterial(255, 255, 255);
|
|
341
|
-
*
|
|
342
|
-
* // Draw the sphere.
|
|
343
|
-
* sphere(30);
|
|
344
|
-
* }
|
|
345
|
-
* </code>
|
|
346
|
-
* </div>
|
|
347
|
-
*
|
|
348
|
-
* <div>
|
|
349
|
-
* <code>
|
|
350
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
351
|
-
*
|
|
352
|
-
* function setup() {
|
|
353
|
-
* createCanvas(100, 100, WEBGL);
|
|
354
|
-
*
|
|
355
|
-
* describe('A black sphere drawn on a gray background. An area on the surface of the sphere is highlighted in blue.');
|
|
356
|
-
* }
|
|
357
|
-
*
|
|
358
|
-
* function draw() {
|
|
359
|
-
* background(200);
|
|
360
|
-
*
|
|
361
|
-
* // Enable orbiting with the mouse.
|
|
362
|
-
* orbitControl();
|
|
363
|
-
*
|
|
364
|
-
* // Add a specular highlight.
|
|
365
|
-
* // Use a CSS color string.
|
|
366
|
-
* specularColor('#1E90FF');
|
|
367
|
-
*
|
|
368
|
-
* // Add a white point light from the top-right.
|
|
369
|
-
* pointLight(255, 255, 255, 30, -20, 40);
|
|
370
|
-
*
|
|
371
|
-
* // Style the sphere.
|
|
372
|
-
* noStroke();
|
|
373
|
-
*
|
|
374
|
-
* // Add a white specular material.
|
|
375
|
-
* specularMaterial(255, 255, 255);
|
|
376
|
-
*
|
|
377
|
-
* // Draw the sphere.
|
|
378
|
-
* sphere(30);
|
|
379
|
-
* }
|
|
380
|
-
* </code>
|
|
381
|
-
* </div>
|
|
382
|
-
*
|
|
383
|
-
* <div>
|
|
384
|
-
* <code>
|
|
385
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
386
|
-
*
|
|
387
|
-
* function setup() {
|
|
388
|
-
* createCanvas(100, 100, WEBGL);
|
|
389
|
-
*
|
|
390
|
-
* describe('A black sphere drawn on a gray background. An area on the surface of the sphere is highlighted in blue.');
|
|
391
|
-
* }
|
|
392
|
-
*
|
|
393
|
-
* function draw() {
|
|
394
|
-
* background(200);
|
|
395
|
-
*
|
|
396
|
-
* // Enable orbiting with the mouse.
|
|
397
|
-
* orbitControl();
|
|
398
|
-
*
|
|
399
|
-
* // Add a specular highlight.
|
|
400
|
-
* // Use RGB values.
|
|
401
|
-
* specularColor(30, 144, 255);
|
|
402
|
-
*
|
|
403
|
-
* // Add a white point light from the top-right.
|
|
404
|
-
* pointLight(255, 255, 255, 30, -20, 40);
|
|
405
|
-
*
|
|
406
|
-
* // Style the sphere.
|
|
407
|
-
* noStroke();
|
|
408
|
-
*
|
|
409
|
-
* // Add a white specular material.
|
|
410
|
-
* specularMaterial(255, 255, 255);
|
|
411
|
-
*
|
|
412
|
-
* // Draw the sphere.
|
|
413
|
-
* sphere(30);
|
|
414
|
-
* }
|
|
415
|
-
* </code>
|
|
416
|
-
* </div>
|
|
417
|
-
*/
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* @method specularColor
|
|
421
|
-
* @param {Number} gray grayscale value between 0 and 255.
|
|
422
|
-
* @chainable
|
|
423
|
-
*/
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* @method specularColor
|
|
427
|
-
* @param {String} value color as a CSS string.
|
|
428
|
-
* @chainable
|
|
429
|
-
*/
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* @method specularColor
|
|
433
|
-
* @param {Number[]} values color as an array of RGBA, HSBA, or HSLA
|
|
434
|
-
* values.
|
|
435
|
-
* @chainable
|
|
436
|
-
*/
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* @method specularColor
|
|
440
|
-
* @param {p5.Color} color color as a <a href="#/p5.Color">p5.Color</a> object.
|
|
441
|
-
* @chainable
|
|
442
|
-
*/
|
|
443
|
-
fn.specularColor = function (v1, v2, v3) {
|
|
444
|
-
this._assert3d('specularColor');
|
|
445
|
-
// p5._validateParameters('specularColor', arguments);
|
|
446
|
-
|
|
447
|
-
this._renderer.specularColor(...arguments);
|
|
448
|
-
|
|
449
|
-
return this;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Creates a light that shines in one direction.
|
|
454
|
-
*
|
|
455
|
-
* Directional lights don’t shine from a specific point. They’re like a sun
|
|
456
|
-
* that shines from somewhere offscreen. The light’s direction is set using
|
|
457
|
-
* three `(x, y, z)` values between -1 and 1. For example, setting a light’s
|
|
458
|
-
* direction as `(1, 0, 0)` will light <a href="#/p5.Geometry">p5.Geometry</a>
|
|
459
|
-
* objects from the left since the light faces directly to the right. A
|
|
460
|
-
* maximum of 5 directional lights can be active at once.
|
|
461
|
-
*
|
|
462
|
-
* There are four ways to call `directionalLight()` with parameters to set the
|
|
463
|
-
* light’s color and direction.
|
|
464
|
-
*
|
|
465
|
-
* The first way to call `directionalLight()` has six parameters. The first
|
|
466
|
-
* three parameters, `v1`, `v2`, and `v3`, set the light’s color using the
|
|
467
|
-
* current <a href="#/p5/colorMode">colorMode()</a>. The last three
|
|
468
|
-
* parameters, `x`, `y`, and `z`, set the light’s direction. For example,
|
|
469
|
-
* `directionalLight(255, 0, 0, 1, 0, 0)` creates a red `(255, 0, 0)` light
|
|
470
|
-
* that shines to the right `(1, 0, 0)`.
|
|
471
|
-
*
|
|
472
|
-
* The second way to call `directionalLight()` has four parameters. The first
|
|
473
|
-
* three parameters, `v1`, `v2`, and `v3`, set the light’s color using the
|
|
474
|
-
* current <a href="#/p5/colorMode">colorMode()</a>. The last parameter,
|
|
475
|
-
* `direction` sets the light’s direction using a
|
|
476
|
-
* <a href="#/p5.Geometry">p5.Geometry</a> object. For example,
|
|
477
|
-
* `directionalLight(255, 0, 0, lightDir)` creates a red `(255, 0, 0)` light
|
|
478
|
-
* that shines in the direction the `lightDir` vector points.
|
|
479
|
-
*
|
|
480
|
-
* The third way to call `directionalLight()` has four parameters. The first
|
|
481
|
-
* parameter, `color`, sets the light’s color using a
|
|
482
|
-
* <a href="#/p5.Color">p5.Color</a> object or an array of color values. The
|
|
483
|
-
* last three parameters, `x`, `y`, and `z`, set the light’s direction. For
|
|
484
|
-
* example, `directionalLight(myColor, 1, 0, 0)` creates a light that shines
|
|
485
|
-
* to the right `(1, 0, 0)` with the color value of `myColor`.
|
|
486
|
-
*
|
|
487
|
-
* The fourth way to call `directionalLight()` has two parameters. The first
|
|
488
|
-
* parameter, `color`, sets the light’s color using a
|
|
489
|
-
* <a href="#/p5.Color">p5.Color</a> object or an array of color values. The
|
|
490
|
-
* second parameter, `direction`, sets the light’s direction using a
|
|
491
|
-
* <a href="#/p5.Color">p5.Color</a> object. For example,
|
|
492
|
-
* `directionalLight(myColor, lightDir)` creates a light that shines in the
|
|
493
|
-
* direction the `lightDir` vector points with the color value of `myColor`.
|
|
494
|
-
*
|
|
495
|
-
* @method directionalLight
|
|
496
|
-
* @param {Number} v1 red or hue value in the current
|
|
497
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
498
|
-
* @param {Number} v2 green or saturation value in the current
|
|
499
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
500
|
-
* @param {Number} v3 blue, brightness, or lightness value in the current
|
|
501
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
502
|
-
* @param {Number} x x-component of the light's direction between -1 and 1.
|
|
503
|
-
* @param {Number} y y-component of the light's direction between -1 and 1.
|
|
504
|
-
* @param {Number} z z-component of the light's direction between -1 and 1.
|
|
505
|
-
* @chainable
|
|
506
|
-
*
|
|
507
|
-
* @example
|
|
508
|
-
* <div>
|
|
509
|
-
* <code>
|
|
510
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
511
|
-
* // Double-click to turn on the directional light.
|
|
512
|
-
*
|
|
513
|
-
* let isLit = false;
|
|
514
|
-
*
|
|
515
|
-
* function setup() {
|
|
516
|
-
* createCanvas(100, 100, WEBGL);
|
|
517
|
-
*
|
|
518
|
-
* describe('A sphere drawn on a gray background. A red light starts shining from above when the user double-clicks.');
|
|
519
|
-
* }
|
|
520
|
-
*
|
|
521
|
-
* function draw() {
|
|
522
|
-
* background(200);
|
|
523
|
-
*
|
|
524
|
-
* // Enable orbiting with the mouse.
|
|
525
|
-
* orbitControl();
|
|
526
|
-
*
|
|
527
|
-
* // Control the light.
|
|
528
|
-
* if (isLit === true) {
|
|
529
|
-
* // Add a red directional light from above.
|
|
530
|
-
* // Use RGB values and XYZ directions.
|
|
531
|
-
* directionalLight(255, 0, 0, 0, 1, 0);
|
|
532
|
-
* }
|
|
533
|
-
*
|
|
534
|
-
* // Style the sphere.
|
|
535
|
-
* noStroke();
|
|
536
|
-
*
|
|
537
|
-
* // Draw the sphere.
|
|
538
|
-
* sphere(30);
|
|
539
|
-
* }
|
|
540
|
-
* </code>
|
|
541
|
-
* </div>
|
|
542
|
-
*
|
|
543
|
-
* <div>
|
|
544
|
-
* <code>
|
|
545
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
546
|
-
*
|
|
547
|
-
* function setup() {
|
|
548
|
-
* createCanvas(100, 100, WEBGL);
|
|
549
|
-
*
|
|
550
|
-
* describe('A sphere drawn on a gray background. The top of the sphere appears bright red. The color gets darker toward the bottom.');
|
|
551
|
-
* }
|
|
552
|
-
*
|
|
553
|
-
* function draw() {
|
|
554
|
-
* background(200);
|
|
555
|
-
*
|
|
556
|
-
* // Enable orbiting with the mouse.
|
|
557
|
-
* orbitControl();
|
|
558
|
-
*
|
|
559
|
-
* // Add a red directional light from above.
|
|
560
|
-
* // Use a p5.Color object and XYZ directions.
|
|
561
|
-
* let c = color(255, 0, 0);
|
|
562
|
-
* directionalLight(c, 0, 1, 0);
|
|
563
|
-
*
|
|
564
|
-
* // Style the sphere.
|
|
565
|
-
* noStroke();
|
|
566
|
-
*
|
|
567
|
-
* // Draw the sphere.
|
|
568
|
-
* sphere(30);
|
|
569
|
-
* }
|
|
570
|
-
* </code>
|
|
571
|
-
* </div>
|
|
572
|
-
*
|
|
573
|
-
* <div>
|
|
574
|
-
* <code>
|
|
575
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
576
|
-
*
|
|
577
|
-
* function setup() {
|
|
578
|
-
* createCanvas(100, 100, WEBGL);
|
|
579
|
-
*
|
|
580
|
-
* describe('A sphere drawn on a gray background. The top of the sphere appears bright red. The color gets darker toward the bottom.');
|
|
581
|
-
* }
|
|
582
|
-
*
|
|
583
|
-
* function draw() {
|
|
584
|
-
* background(200);
|
|
585
|
-
*
|
|
586
|
-
* // Enable orbiting with the mouse.
|
|
587
|
-
* orbitControl();
|
|
588
|
-
*
|
|
589
|
-
* // Add a red directional light from above.
|
|
590
|
-
* // Use a p5.Color object and a p5.Vector object.
|
|
591
|
-
* let c = color(255, 0, 0);
|
|
592
|
-
* let lightDir = createVector(0, 1, 0);
|
|
593
|
-
* directionalLight(c, lightDir);
|
|
594
|
-
*
|
|
595
|
-
* // Style the sphere.
|
|
596
|
-
* noStroke();
|
|
597
|
-
*
|
|
598
|
-
* // Draw the sphere.
|
|
599
|
-
* sphere(30);
|
|
600
|
-
* }
|
|
601
|
-
* </code>
|
|
602
|
-
* </div>
|
|
603
|
-
*/
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* @method directionalLight
|
|
607
|
-
* @param {Number} v1
|
|
608
|
-
* @param {Number} v2
|
|
609
|
-
* @param {Number} v3
|
|
610
|
-
* @param {p5.Vector} direction direction of the light as a
|
|
611
|
-
* <a href="#/p5.Vector">p5.Vector</a> object.
|
|
612
|
-
* @chainable
|
|
613
|
-
*/
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* @method directionalLight
|
|
617
|
-
* @param {p5.Color|Number[]|String} color color as a <a href="#/p5.Color">p5.Color</a> object,
|
|
618
|
-
* an array of color values, or as a CSS string.
|
|
619
|
-
* @param {Number} x
|
|
620
|
-
* @param {Number} y
|
|
621
|
-
* @param {Number} z
|
|
622
|
-
* @chainable
|
|
623
|
-
*/
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
* @method directionalLight
|
|
627
|
-
* @param {p5.Color|Number[]|String} color
|
|
628
|
-
* @param {p5.Vector} direction
|
|
629
|
-
* @chainable
|
|
630
|
-
*/
|
|
631
|
-
fn.directionalLight = function (v1, v2, v3, x, y, z) {
|
|
632
|
-
this._assert3d('directionalLight');
|
|
633
|
-
// p5._validateParameters('directionalLight', arguments);
|
|
634
|
-
|
|
635
|
-
//@TODO: check parameters number
|
|
636
|
-
this._renderer.directionalLight(...arguments);
|
|
637
|
-
|
|
638
|
-
return this;
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
/**
|
|
642
|
-
* Creates a light that shines from a point in all directions.
|
|
643
|
-
*
|
|
644
|
-
* Point lights are like light bulbs that shine in all directions. They can be
|
|
645
|
-
* placed at different positions to achieve different lighting effects. A
|
|
646
|
-
* maximum of 5 point lights can be active at once.
|
|
647
|
-
*
|
|
648
|
-
* There are four ways to call `pointLight()` with parameters to set the
|
|
649
|
-
* light’s color and position.
|
|
650
|
-
*
|
|
651
|
-
* The first way to call `pointLight()` has six parameters. The first three
|
|
652
|
-
* parameters, `v1`, `v2`, and `v3`, set the light’s color using the current
|
|
653
|
-
* <a href="#/p5/colorMode">colorMode()</a>. The last three parameters, `x`,
|
|
654
|
-
* `y`, and `z`, set the light’s position. For example,
|
|
655
|
-
* `pointLight(255, 0, 0, 50, 0, 0)` creates a red `(255, 0, 0)` light that
|
|
656
|
-
* shines from the coordinates `(50, 0, 0)`.
|
|
657
|
-
*
|
|
658
|
-
* The second way to call `pointLight()` has four parameters. The first three
|
|
659
|
-
* parameters, `v1`, `v2`, and `v3`, set the light’s color using the current
|
|
660
|
-
* <a href="#/p5/colorMode">colorMode()</a>. The last parameter, position sets
|
|
661
|
-
* the light’s position using a <a href="#/p5.Vector">p5.Vector</a> object.
|
|
662
|
-
* For example, `pointLight(255, 0, 0, lightPos)` creates a red `(255, 0, 0)`
|
|
663
|
-
* light that shines from the position set by the `lightPos` vector.
|
|
664
|
-
*
|
|
665
|
-
* The third way to call `pointLight()` has four parameters. The first
|
|
666
|
-
* parameter, `color`, sets the light’s color using a
|
|
667
|
-
* <a href="#/p5.Color">p5.Color</a> object or an array of color values. The
|
|
668
|
-
* last three parameters, `x`, `y`, and `z`, set the light’s position. For
|
|
669
|
-
* example, `directionalLight(myColor, 50, 0, 0)` creates a light that shines
|
|
670
|
-
* from the coordinates `(50, 0, 0)` with the color value of `myColor`.
|
|
671
|
-
*
|
|
672
|
-
* The fourth way to call `pointLight()` has two parameters. The first
|
|
673
|
-
* parameter, `color`, sets the light’s color using a
|
|
674
|
-
* <a href="#/p5.Color">p5.Color</a> object or an array of color values. The
|
|
675
|
-
* second parameter, `position`, sets the light’s position using a
|
|
676
|
-
* <a href="#/p5.Vector">p5.Vector</a> object. For example,
|
|
677
|
-
* `directionalLight(myColor, lightPos)` creates a light that shines from the
|
|
678
|
-
* position set by the `lightPos` vector with the color value of `myColor`.
|
|
679
|
-
*
|
|
680
|
-
* @method pointLight
|
|
681
|
-
* @param {Number} v1 red or hue value in the current
|
|
682
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
683
|
-
* @param {Number} v2 green or saturation value in the current
|
|
684
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
685
|
-
* @param {Number} v3 blue, brightness, or lightness value in the current
|
|
686
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
687
|
-
* @param {Number} x x-coordinate of the light.
|
|
688
|
-
* @param {Number} y y-coordinate of the light.
|
|
689
|
-
* @param {Number} z z-coordinate of the light.
|
|
690
|
-
* @chainable
|
|
691
|
-
*
|
|
692
|
-
* @example
|
|
693
|
-
*
|
|
694
|
-
* <div>
|
|
695
|
-
* <code>
|
|
696
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
697
|
-
* // Double-click to turn on the point light.
|
|
698
|
-
*
|
|
699
|
-
* let isLit = false;
|
|
700
|
-
*
|
|
701
|
-
* function setup() {
|
|
702
|
-
* createCanvas(100, 100, WEBGL);
|
|
703
|
-
*
|
|
704
|
-
* describe('A sphere drawn on a gray background. A red light starts shining from above when the user double-clicks.');
|
|
705
|
-
* }
|
|
706
|
-
*
|
|
707
|
-
* function draw() {
|
|
708
|
-
* background(200);
|
|
709
|
-
*
|
|
710
|
-
* // Enable orbiting with the mouse.
|
|
711
|
-
* orbitControl();
|
|
712
|
-
*
|
|
713
|
-
* // Control the light.
|
|
714
|
-
* if (isLit === true) {
|
|
715
|
-
* // Add a red point light from above.
|
|
716
|
-
* // Use RGB values and XYZ coordinates.
|
|
717
|
-
* pointLight(255, 0, 0, 0, -150, 0);
|
|
718
|
-
* }
|
|
719
|
-
*
|
|
720
|
-
* // Style the sphere.
|
|
721
|
-
* noStroke();
|
|
722
|
-
*
|
|
723
|
-
* // Draw the sphere.
|
|
724
|
-
* sphere(30);
|
|
725
|
-
* }
|
|
726
|
-
*
|
|
727
|
-
* // Turn on the point light when the user double-clicks.
|
|
728
|
-
* function doubleClicked() {
|
|
729
|
-
* isLit = true;
|
|
730
|
-
* }
|
|
731
|
-
* </code>
|
|
732
|
-
* </div>
|
|
733
|
-
*
|
|
734
|
-
* <div>
|
|
735
|
-
* <code>
|
|
736
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
737
|
-
*
|
|
738
|
-
* function setup() {
|
|
739
|
-
* createCanvas(100, 100, WEBGL);
|
|
740
|
-
*
|
|
741
|
-
* describe('A sphere drawn on a gray background. The top of the sphere appears bright red. The color gets darker toward the bottom.');
|
|
742
|
-
* }
|
|
743
|
-
*
|
|
744
|
-
* function draw() {
|
|
745
|
-
* background(200);
|
|
746
|
-
*
|
|
747
|
-
* // Enable orbiting with the mouse.
|
|
748
|
-
* orbitControl();
|
|
749
|
-
*
|
|
750
|
-
* // Add a red point light from above.
|
|
751
|
-
* // Use a p5.Color object and XYZ directions.
|
|
752
|
-
* let c = color(255, 0, 0);
|
|
753
|
-
* pointLight(c, 0, -150, 0);
|
|
754
|
-
*
|
|
755
|
-
* // Style the sphere.
|
|
756
|
-
* noStroke();
|
|
757
|
-
*
|
|
758
|
-
* // Draw the sphere.
|
|
759
|
-
* sphere(30);
|
|
760
|
-
* }
|
|
761
|
-
* </code>
|
|
762
|
-
* </div>
|
|
763
|
-
*
|
|
764
|
-
* <div>
|
|
765
|
-
* <code>
|
|
766
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
767
|
-
*
|
|
768
|
-
* function setup() {
|
|
769
|
-
* createCanvas(100, 100, WEBGL);
|
|
770
|
-
*
|
|
771
|
-
* describe('A sphere drawn on a gray background. The top of the sphere appears bright red. The color gets darker toward the bottom.');
|
|
772
|
-
* }
|
|
773
|
-
*
|
|
774
|
-
* function draw() {
|
|
775
|
-
* background(200);
|
|
776
|
-
*
|
|
777
|
-
* // Enable orbiting with the mouse.
|
|
778
|
-
* orbitControl();
|
|
779
|
-
*
|
|
780
|
-
* // Add a red point light from above.
|
|
781
|
-
* // Use a p5.Color object and a p5.Vector object.
|
|
782
|
-
* let c = color(255, 0, 0);
|
|
783
|
-
* let lightPos = createVector(0, -150, 0);
|
|
784
|
-
* pointLight(c, lightPos);
|
|
785
|
-
*
|
|
786
|
-
* // Style the sphere.
|
|
787
|
-
* noStroke();
|
|
788
|
-
*
|
|
789
|
-
* // Draw the sphere.
|
|
790
|
-
* sphere(30);
|
|
791
|
-
* }
|
|
792
|
-
* </code>
|
|
793
|
-
* </div>
|
|
794
|
-
*
|
|
795
|
-
* <div>
|
|
796
|
-
* <code>
|
|
797
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
798
|
-
*
|
|
799
|
-
* function setup() {
|
|
800
|
-
* createCanvas(100, 100, WEBGL);
|
|
801
|
-
*
|
|
802
|
-
* describe('Four spheres arranged in a square and drawn on a gray background. The spheres appear bright red toward the center of the square. The color gets darker toward the corners of the square.');
|
|
803
|
-
* }
|
|
804
|
-
*
|
|
805
|
-
* function draw() {
|
|
806
|
-
* background(200);
|
|
807
|
-
*
|
|
808
|
-
* // Enable orbiting with the mouse.
|
|
809
|
-
* orbitControl();
|
|
810
|
-
*
|
|
811
|
-
* // Add a red point light that points to the center of the scene.
|
|
812
|
-
* // Use a p5.Color object and a p5.Vector object.
|
|
813
|
-
* let c = color(255, 0, 0);
|
|
814
|
-
* let lightPos = createVector(0, 0, 65);
|
|
815
|
-
* pointLight(c, lightPos);
|
|
816
|
-
*
|
|
817
|
-
* // Style the spheres.
|
|
818
|
-
* noStroke();
|
|
819
|
-
*
|
|
820
|
-
* // Draw a sphere up and to the left.
|
|
821
|
-
* push();
|
|
822
|
-
* translate(-25, -25, 25);
|
|
823
|
-
* sphere(10);
|
|
824
|
-
* pop();
|
|
825
|
-
*
|
|
826
|
-
* // Draw a box up and to the right.
|
|
827
|
-
* push();
|
|
828
|
-
* translate(25, -25, 25);
|
|
829
|
-
* sphere(10);
|
|
830
|
-
* pop();
|
|
831
|
-
*
|
|
832
|
-
* // Draw a sphere down and to the left.
|
|
833
|
-
* push();
|
|
834
|
-
* translate(-25, 25, 25);
|
|
835
|
-
* sphere(10);
|
|
836
|
-
* pop();
|
|
837
|
-
*
|
|
838
|
-
* // Draw a box down and to the right.
|
|
839
|
-
* push();
|
|
840
|
-
* translate(25, 25, 25);
|
|
841
|
-
* sphere(10);
|
|
842
|
-
* pop();
|
|
843
|
-
* }
|
|
844
|
-
* </code>
|
|
845
|
-
* </div>
|
|
846
|
-
*/
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* @method pointLight
|
|
850
|
-
* @param {Number} v1
|
|
851
|
-
* @param {Number} v2
|
|
852
|
-
* @param {Number} v3
|
|
853
|
-
* @param {p5.Vector} position position of the light as a
|
|
854
|
-
* <a href="#/p5.Vector">p5.Vector</a> object.
|
|
855
|
-
* @chainable
|
|
856
|
-
*/
|
|
857
|
-
|
|
858
|
-
/**
|
|
859
|
-
* @method pointLight
|
|
860
|
-
* @param {p5.Color|Number[]|String} color color as a <a href="#/p5.Color">p5.Color</a> object,
|
|
861
|
-
* an array of color values, or a CSS string.
|
|
862
|
-
* @param {Number} x
|
|
863
|
-
* @param {Number} y
|
|
864
|
-
* @param {Number} z
|
|
865
|
-
* @chainable
|
|
866
|
-
*/
|
|
867
|
-
|
|
868
|
-
/**
|
|
869
|
-
* @method pointLight
|
|
870
|
-
* @param {p5.Color|Number[]|String} color
|
|
871
|
-
* @param {p5.Vector} position
|
|
872
|
-
* @chainable
|
|
873
|
-
*/
|
|
874
|
-
fn.pointLight = function (v1, v2, v3, x, y, z) {
|
|
875
|
-
this._assert3d('pointLight');
|
|
876
|
-
// p5._validateParameters('pointLight', arguments);
|
|
877
|
-
|
|
878
|
-
//@TODO: check parameters number
|
|
879
|
-
this._renderer.pointLight(...arguments);
|
|
880
|
-
|
|
881
|
-
return this;
|
|
882
|
-
};
|
|
883
|
-
|
|
884
|
-
/**
|
|
885
|
-
* Creates an ambient light from an image.
|
|
886
|
-
*
|
|
887
|
-
* `imageLight()` simulates a light shining from all directions. The effect is
|
|
888
|
-
* like placing the sketch at the center of a giant sphere that uses the image
|
|
889
|
-
* as its texture. The image's diffuse light will be affected by
|
|
890
|
-
* <a href="#/p5/fill">fill()</a> and the specular reflections will be
|
|
891
|
-
* affected by <a href="#/p5/specularMaterial">specularMaterial()</a> and
|
|
892
|
-
* <a href="#/p5/shininess">shininess()</a>.
|
|
893
|
-
*
|
|
894
|
-
* The parameter, `img`, is the <a href="#/p5.Image">p5.Image</a> object to
|
|
895
|
-
* use as the light source.
|
|
896
|
-
*
|
|
897
|
-
* @method imageLight
|
|
898
|
-
* @param {p5.image} img image to use as the light source.
|
|
899
|
-
*
|
|
900
|
-
* @example
|
|
901
|
-
* <div class="notest">
|
|
902
|
-
* <code>
|
|
903
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
904
|
-
*
|
|
905
|
-
* let img;
|
|
906
|
-
*
|
|
907
|
-
* async function setup() {
|
|
908
|
-
* // Load an image and create a p5.Image object.
|
|
909
|
-
* img = await loadImage('assets/outdoor_spheremap.jpg');
|
|
910
|
-
*
|
|
911
|
-
* createCanvas(100, 100, WEBGL);
|
|
912
|
-
*
|
|
913
|
-
* describe('A sphere floating above a landscape. The surface of the sphere reflects the landscape.');
|
|
914
|
-
* }
|
|
915
|
-
*
|
|
916
|
-
* function draw() {
|
|
917
|
-
* // Enable orbiting with the mouse.
|
|
918
|
-
* orbitControl();
|
|
919
|
-
*
|
|
920
|
-
* // Draw the image as a panorama (360˚ background).
|
|
921
|
-
* panorama(img);
|
|
922
|
-
*
|
|
923
|
-
* // Add a soft ambient light.
|
|
924
|
-
* ambientLight(50);
|
|
925
|
-
*
|
|
926
|
-
* // Add light from the image.
|
|
927
|
-
* imageLight(img);
|
|
928
|
-
*
|
|
929
|
-
* // Style the sphere.
|
|
930
|
-
* specularMaterial(20);
|
|
931
|
-
* shininess(100);
|
|
932
|
-
* noStroke();
|
|
933
|
-
*
|
|
934
|
-
* // Draw the sphere.
|
|
935
|
-
* sphere(30);
|
|
936
|
-
* }
|
|
937
|
-
* </code>
|
|
938
|
-
* </div>
|
|
939
|
-
*/
|
|
940
|
-
fn.imageLight = function (img) {
|
|
941
|
-
this._renderer.imageLight(img);
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
/**
|
|
945
|
-
* Creates an immersive 3D background.
|
|
946
|
-
*
|
|
947
|
-
* `panorama()` transforms images containing 360˚ content, such as maps or
|
|
948
|
-
* HDRIs, into immersive 3D backgrounds that surround a sketch. Exploring the
|
|
949
|
-
* space requires changing the camera's perspective with functions such as
|
|
950
|
-
* <a href="#/p5/orbitControl">orbitControl()</a> or
|
|
951
|
-
* <a href="#/p5/camera">camera()</a>.
|
|
952
|
-
*
|
|
953
|
-
* @method panorama
|
|
954
|
-
* @param {p5.Image} img 360˚ image to use as the background.
|
|
955
|
-
*
|
|
956
|
-
* @example
|
|
957
|
-
* <div class="notest">
|
|
958
|
-
* <code>
|
|
959
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
960
|
-
*
|
|
961
|
-
* let img;
|
|
962
|
-
*
|
|
963
|
-
* async function setup() {
|
|
964
|
-
* // Load an image and create a p5.Image object.
|
|
965
|
-
* img = await loadImage('assets/outdoor_spheremap.jpg');
|
|
966
|
-
*
|
|
967
|
-
* createCanvas(100, 100, WEBGL);
|
|
968
|
-
*
|
|
969
|
-
* describe('A sphere floating above a landscape. The surface of the sphere reflects the landscape. The full landscape is viewable in 3D as the user drags the mouse.');
|
|
970
|
-
* }
|
|
971
|
-
*
|
|
972
|
-
* function draw() {
|
|
973
|
-
* // Add the panorama.
|
|
974
|
-
* panorama(img);
|
|
975
|
-
*
|
|
976
|
-
* // Enable orbiting with the mouse.
|
|
977
|
-
* orbitControl();
|
|
978
|
-
*
|
|
979
|
-
* // Use the image as a light source.
|
|
980
|
-
* imageLight(img);
|
|
981
|
-
*
|
|
982
|
-
* // Style the sphere.
|
|
983
|
-
* noStroke();
|
|
984
|
-
* specularMaterial(50);
|
|
985
|
-
* shininess(200);
|
|
986
|
-
* metalness(100);
|
|
987
|
-
*
|
|
988
|
-
* // Draw the sphere.
|
|
989
|
-
* sphere(30);
|
|
990
|
-
* }
|
|
991
|
-
* </code>
|
|
992
|
-
* </div>
|
|
993
|
-
*/
|
|
994
|
-
fn.panorama = function (img) {
|
|
995
|
-
this.filter(this._renderer._getSphereMapping(img));
|
|
996
|
-
};
|
|
997
|
-
|
|
998
|
-
/**
|
|
999
|
-
* Places an ambient and directional light in the scene.
|
|
1000
|
-
* The lights are set to ambientLight(128, 128, 128) and
|
|
1001
|
-
* directionalLight(128, 128, 128, 0, 0, -1).
|
|
1002
|
-
*
|
|
1003
|
-
* Note: lights need to be called (whether directly or indirectly)
|
|
1004
|
-
* within draw() to remain persistent in a looping program.
|
|
1005
|
-
* Placing them in setup() will cause them to only have an effect
|
|
1006
|
-
* the first time through the loop.
|
|
1007
|
-
*
|
|
1008
|
-
* @method lights
|
|
1009
|
-
* @chainable
|
|
1010
|
-
*
|
|
1011
|
-
* @example
|
|
1012
|
-
* <div>
|
|
1013
|
-
* <code>
|
|
1014
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
1015
|
-
* // Double-click to turn on the lights.
|
|
1016
|
-
*
|
|
1017
|
-
* let isLit = false;
|
|
1018
|
-
*
|
|
1019
|
-
* function setup() {
|
|
1020
|
-
* createCanvas(100, 100, WEBGL);
|
|
1021
|
-
*
|
|
1022
|
-
* describe('A white box drawn against a gray background. The quality of the light changes when the user double-clicks.');
|
|
1023
|
-
* }
|
|
1024
|
-
*
|
|
1025
|
-
* function draw() {
|
|
1026
|
-
* background(50);
|
|
1027
|
-
*
|
|
1028
|
-
* // Enable orbiting with the mouse.
|
|
1029
|
-
* orbitControl();
|
|
1030
|
-
*
|
|
1031
|
-
* // Control the lights.
|
|
1032
|
-
* if (isLit === true) {
|
|
1033
|
-
* lights();
|
|
1034
|
-
* }
|
|
1035
|
-
*
|
|
1036
|
-
* // Draw the box.
|
|
1037
|
-
* box();
|
|
1038
|
-
* }
|
|
1039
|
-
*
|
|
1040
|
-
* // Turn on the lights when the user double-clicks.
|
|
1041
|
-
* function doubleClicked() {
|
|
1042
|
-
* isLit = true;
|
|
1043
|
-
* }
|
|
1044
|
-
* </code>
|
|
1045
|
-
* </div>
|
|
1046
|
-
*
|
|
1047
|
-
* <div>
|
|
1048
|
-
* <code>
|
|
1049
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
1050
|
-
*
|
|
1051
|
-
* function setup() {
|
|
1052
|
-
* createCanvas(100, 100, WEBGL);
|
|
1053
|
-
*
|
|
1054
|
-
* describe('A white box drawn against a gray background.');
|
|
1055
|
-
* }
|
|
1056
|
-
*
|
|
1057
|
-
* function draw() {
|
|
1058
|
-
* background(50);
|
|
1059
|
-
*
|
|
1060
|
-
* // Enable orbiting with the mouse.
|
|
1061
|
-
* orbitControl();
|
|
1062
|
-
*
|
|
1063
|
-
* // Turn on the lights.
|
|
1064
|
-
* ambientLight(128, 128, 128);
|
|
1065
|
-
* directionalLight(128, 128, 128, 0, 0, -1);
|
|
1066
|
-
*
|
|
1067
|
-
* // Draw the box.
|
|
1068
|
-
* box();
|
|
1069
|
-
* }
|
|
1070
|
-
* </code>
|
|
1071
|
-
* </div>
|
|
1072
|
-
*/
|
|
1073
|
-
fn.lights = function () {
|
|
1074
|
-
this._assert3d('lights');
|
|
1075
|
-
// Both specify gray by default.
|
|
1076
|
-
this._renderer.lights();
|
|
1077
|
-
return this;
|
|
1078
|
-
};
|
|
1079
|
-
|
|
1080
|
-
/**
|
|
1081
|
-
* Sets the falloff rate for <a href="#/p5/pointLight">pointLight()</a>
|
|
1082
|
-
* and <a href="#/p5/spotLight">spotLight()</a>.
|
|
1083
|
-
*
|
|
1084
|
-
* A light’s falloff describes the intensity of its beam at a distance. For
|
|
1085
|
-
* example, a lantern has a slow falloff, a flashlight has a medium falloff,
|
|
1086
|
-
* and a laser pointer has a sharp falloff.
|
|
1087
|
-
*
|
|
1088
|
-
* `lightFalloff()` has three parameters, `constant`, `linear`, and
|
|
1089
|
-
* `quadratic`. They’re numbers used to calculate falloff at a distance, `d`,
|
|
1090
|
-
* as follows:
|
|
1091
|
-
*
|
|
1092
|
-
* `falloff = 1 / (constant + d * linear + (d * d) * quadratic)`
|
|
1093
|
-
*
|
|
1094
|
-
* Note: `constant`, `linear`, and `quadratic` should always be set to values
|
|
1095
|
-
* greater than 0.
|
|
1096
|
-
*
|
|
1097
|
-
* @method lightFalloff
|
|
1098
|
-
* @param {Number} constant constant value for calculating falloff.
|
|
1099
|
-
* @param {Number} linear linear value for calculating falloff.
|
|
1100
|
-
* @param {Number} quadratic quadratic value for calculating falloff.
|
|
1101
|
-
* @chainable
|
|
1102
|
-
*
|
|
1103
|
-
* @example
|
|
1104
|
-
* <div>
|
|
1105
|
-
* <code>
|
|
1106
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
1107
|
-
* // Double-click to change the falloff rate.
|
|
1108
|
-
*
|
|
1109
|
-
* let useFalloff = false;
|
|
1110
|
-
*
|
|
1111
|
-
* function setup() {
|
|
1112
|
-
* createCanvas(100, 100, WEBGL);
|
|
1113
|
-
*
|
|
1114
|
-
* describe('A sphere drawn against a gray background. The intensity of the light changes when the user double-clicks.');
|
|
1115
|
-
* }
|
|
1116
|
-
*
|
|
1117
|
-
* function draw() {
|
|
1118
|
-
* background(50);
|
|
1119
|
-
*
|
|
1120
|
-
* // Enable orbiting with the mouse.
|
|
1121
|
-
* orbitControl();
|
|
1122
|
-
*
|
|
1123
|
-
* // Set the light falloff.
|
|
1124
|
-
* if (useFalloff === true) {
|
|
1125
|
-
* lightFalloff(2, 0, 0);
|
|
1126
|
-
* }
|
|
1127
|
-
*
|
|
1128
|
-
* // Add a white point light from the front.
|
|
1129
|
-
* pointLight(255, 255, 255, 0, 0, 100);
|
|
1130
|
-
*
|
|
1131
|
-
* // Style the sphere.
|
|
1132
|
-
* noStroke();
|
|
1133
|
-
*
|
|
1134
|
-
* // Draw the sphere.
|
|
1135
|
-
* sphere(30);
|
|
1136
|
-
* }
|
|
1137
|
-
*
|
|
1138
|
-
* // Change the falloff value when the user double-clicks.
|
|
1139
|
-
* function doubleClicked() {
|
|
1140
|
-
* useFalloff = true;
|
|
1141
|
-
* }
|
|
1142
|
-
* </code>
|
|
1143
|
-
* </div>
|
|
1144
|
-
*/
|
|
1145
|
-
fn.lightFalloff = function (
|
|
1146
|
-
constantAttenuation,
|
|
1147
|
-
linearAttenuation,
|
|
1148
|
-
quadraticAttenuation
|
|
1149
|
-
) {
|
|
1150
|
-
this._assert3d('lightFalloff');
|
|
1151
|
-
// p5._validateParameters('lightFalloff', arguments);
|
|
1152
|
-
|
|
1153
|
-
this._renderer.lightFalloff(
|
|
1154
|
-
constantAttenuation,
|
|
1155
|
-
linearAttenuation,
|
|
1156
|
-
quadraticAttenuation
|
|
1157
|
-
);
|
|
1158
|
-
|
|
1159
|
-
return this;
|
|
1160
|
-
};
|
|
1161
|
-
|
|
1162
|
-
/**
|
|
1163
|
-
* Creates a light that shines from a point in one direction.
|
|
1164
|
-
*
|
|
1165
|
-
* Spot lights are like flashlights that shine in one direction creating a
|
|
1166
|
-
* cone of light. The shape of the cone can be controlled using the angle and
|
|
1167
|
-
* concentration parameters. A maximum of 5 spot lights can be active at once.
|
|
1168
|
-
*
|
|
1169
|
-
* There are eight ways to call `spotLight()` with parameters to set the
|
|
1170
|
-
* light’s color, position, direction. For example,
|
|
1171
|
-
* `spotLight(255, 0, 0, 0, 0, 0, 1, 0, 0)` creates a red `(255, 0, 0)` light
|
|
1172
|
-
* at the origin `(0, 0, 0)` that points to the right `(1, 0, 0)`.
|
|
1173
|
-
*
|
|
1174
|
-
* The `angle` parameter is optional. It sets the radius of the light cone.
|
|
1175
|
-
* For example, `spotLight(255, 0, 0, 0, 0, 0, 1, 0, 0, PI / 16)` creates a
|
|
1176
|
-
* red `(255, 0, 0)` light at the origin `(0, 0, 0)` that points to the right
|
|
1177
|
-
* `(1, 0, 0)` with an angle of `PI / 16` radians. By default, `angle` is
|
|
1178
|
-
* `PI / 3` radians.
|
|
1179
|
-
*
|
|
1180
|
-
* The `concentration` parameter is also optional. It focuses the light
|
|
1181
|
-
* towards the center of the light cone. For example,
|
|
1182
|
-
* `spotLight(255, 0, 0, 0, 0, 0, 1, 0, 0, PI / 16, 50)` creates a red
|
|
1183
|
-
* `(255, 0, 0)` light at the origin `(0, 0, 0)` that points to the right
|
|
1184
|
-
* `(1, 0, 0)` with an angle of `PI / 16` radians at concentration of 50. By
|
|
1185
|
-
* default, `concentration` is 100.
|
|
1186
|
-
*
|
|
1187
|
-
* @method spotLight
|
|
1188
|
-
* @param {Number} v1 red or hue value in the current
|
|
1189
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
1190
|
-
* @param {Number} v2 green or saturation value in the current
|
|
1191
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
1192
|
-
* @param {Number} v3 blue, brightness, or lightness value in the current
|
|
1193
|
-
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
1194
|
-
* @param {Number} x x-coordinate of the light.
|
|
1195
|
-
* @param {Number} y y-coordinate of the light.
|
|
1196
|
-
* @param {Number} z z-coordinate of the light.
|
|
1197
|
-
* @param {Number} rx x-component of light direction between -1 and 1.
|
|
1198
|
-
* @param {Number} ry y-component of light direction between -1 and 1.
|
|
1199
|
-
* @param {Number} rz z-component of light direction between -1 and 1.
|
|
1200
|
-
* @param {Number} [angle] angle of the light cone. Defaults to `PI / 3`.
|
|
1201
|
-
* @param {Number} [concentration] concentration of the light. Defaults to 100.
|
|
1202
|
-
* @chainable
|
|
1203
|
-
*
|
|
1204
|
-
* @example
|
|
1205
|
-
* <div>
|
|
1206
|
-
* <code>
|
|
1207
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
1208
|
-
* // Double-click to adjust the spotlight.
|
|
1209
|
-
*
|
|
1210
|
-
* let isLit = false;
|
|
1211
|
-
*
|
|
1212
|
-
* function setup() {
|
|
1213
|
-
* createCanvas(100, 100, WEBGL);
|
|
1214
|
-
*
|
|
1215
|
-
* describe('A white sphere drawn on a gray background. A red spotlight starts shining when the user double-clicks.');
|
|
1216
|
-
* }
|
|
1217
|
-
*
|
|
1218
|
-
* function draw() {
|
|
1219
|
-
* background(50);
|
|
1220
|
-
*
|
|
1221
|
-
* // Enable orbiting with the mouse.
|
|
1222
|
-
* orbitControl();
|
|
1223
|
-
*
|
|
1224
|
-
* // Turn on the lights.
|
|
1225
|
-
* lights();
|
|
1226
|
-
*
|
|
1227
|
-
* // Control the spotlight.
|
|
1228
|
-
* if (isLit === true) {
|
|
1229
|
-
* // Add a red spot light that shines into the screen.
|
|
1230
|
-
* // Set its angle to PI / 32 radians.
|
|
1231
|
-
* spotLight(255, 0, 0, 0, 0, 100, 0, 0, -1, PI / 32);
|
|
1232
|
-
* }
|
|
1233
|
-
*
|
|
1234
|
-
* // Draw the sphere.
|
|
1235
|
-
* sphere(30);
|
|
1236
|
-
* }
|
|
1237
|
-
*
|
|
1238
|
-
* // Turn on the spotlight when the user double-clicks.
|
|
1239
|
-
* function doubleClicked() {
|
|
1240
|
-
* isLit = true;
|
|
1241
|
-
* }
|
|
1242
|
-
* </code>
|
|
1243
|
-
* </div>
|
|
1244
|
-
*
|
|
1245
|
-
* <div>
|
|
1246
|
-
* <code>
|
|
1247
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
1248
|
-
* // Double-click to adjust the spotlight.
|
|
1249
|
-
*
|
|
1250
|
-
* let isLit = false;
|
|
1251
|
-
*
|
|
1252
|
-
* function setup() {
|
|
1253
|
-
* createCanvas(100, 100, WEBGL);
|
|
1254
|
-
*
|
|
1255
|
-
* describe('A white sphere drawn on a gray background. A red spotlight starts shining when the user double-clicks.');
|
|
1256
|
-
* }
|
|
1257
|
-
*
|
|
1258
|
-
* function draw() {
|
|
1259
|
-
* background(50);
|
|
1260
|
-
*
|
|
1261
|
-
* // Enable orbiting with the mouse.
|
|
1262
|
-
* orbitControl();
|
|
1263
|
-
*
|
|
1264
|
-
* // Turn on the lights.
|
|
1265
|
-
* lights();
|
|
1266
|
-
*
|
|
1267
|
-
* // Control the spotlight.
|
|
1268
|
-
* if (isLit === true) {
|
|
1269
|
-
* // Add a red spot light that shines into the screen.
|
|
1270
|
-
* // Set its angle to PI / 3 radians (default).
|
|
1271
|
-
* // Set its concentration to 1000.
|
|
1272
|
-
* let c = color(255, 0, 0);
|
|
1273
|
-
* let position = createVector(0, 0, 100);
|
|
1274
|
-
* let direction = createVector(0, 0, -1);
|
|
1275
|
-
* spotLight(c, position, direction, PI / 3, 1000);
|
|
1276
|
-
* }
|
|
1277
|
-
*
|
|
1278
|
-
* // Draw the sphere.
|
|
1279
|
-
* sphere(30);
|
|
1280
|
-
* }
|
|
1281
|
-
*
|
|
1282
|
-
* // Turn on the spotlight when the user double-clicks.
|
|
1283
|
-
* function doubleClicked() {
|
|
1284
|
-
* isLit = true;
|
|
1285
|
-
* }
|
|
1286
|
-
* </code>
|
|
1287
|
-
* </div>
|
|
1288
|
-
*/
|
|
1289
|
-
/**
|
|
1290
|
-
* @method spotLight
|
|
1291
|
-
* @param {p5.Color|Number[]|String} color color as a <a href="#/p5.Color">p5.Color</a> object,
|
|
1292
|
-
* an array of color values, or a CSS string.
|
|
1293
|
-
* @param {p5.Vector} position position of the light as a <a href="#/p5.Vector">p5.Vector</a> object.
|
|
1294
|
-
* @param {p5.Vector} direction direction of light as a <a href="#/p5.Vector">p5.Vector</a> object.
|
|
1295
|
-
* @param {Number} [angle]
|
|
1296
|
-
* @param {Number} [concentration]
|
|
1297
|
-
*/
|
|
1298
|
-
/**
|
|
1299
|
-
* @method spotLight
|
|
1300
|
-
* @param {Number} v1
|
|
1301
|
-
* @param {Number} v2
|
|
1302
|
-
* @param {Number} v3
|
|
1303
|
-
* @param {p5.Vector} position
|
|
1304
|
-
* @param {p5.Vector} direction
|
|
1305
|
-
* @param {Number} [angle]
|
|
1306
|
-
* @param {Number} [concentration]
|
|
1307
|
-
*/
|
|
1308
|
-
/**
|
|
1309
|
-
* @method spotLight
|
|
1310
|
-
* @param {p5.Color|Number[]|String} color
|
|
1311
|
-
* @param {Number} x
|
|
1312
|
-
* @param {Number} y
|
|
1313
|
-
* @param {Number} z
|
|
1314
|
-
* @param {p5.Vector} direction
|
|
1315
|
-
* @param {Number} [angle]
|
|
1316
|
-
* @param {Number} [concentration]
|
|
1317
|
-
*/
|
|
1318
|
-
/**
|
|
1319
|
-
* @method spotLight
|
|
1320
|
-
* @param {p5.Color|Number[]|String} color
|
|
1321
|
-
* @param {p5.Vector} position
|
|
1322
|
-
* @param {Number} rx
|
|
1323
|
-
* @param {Number} ry
|
|
1324
|
-
* @param {Number} rz
|
|
1325
|
-
* @param {Number} [angle]
|
|
1326
|
-
* @param {Number} [concentration]
|
|
1327
|
-
*/
|
|
1328
|
-
/**
|
|
1329
|
-
* @method spotLight
|
|
1330
|
-
* @param {Number} v1
|
|
1331
|
-
* @param {Number} v2
|
|
1332
|
-
* @param {Number} v3
|
|
1333
|
-
* @param {Number} x
|
|
1334
|
-
* @param {Number} y
|
|
1335
|
-
* @param {Number} z
|
|
1336
|
-
* @param {p5.Vector} direction
|
|
1337
|
-
* @param {Number} [angle]
|
|
1338
|
-
* @param {Number} [concentration]
|
|
1339
|
-
*/
|
|
1340
|
-
/**
|
|
1341
|
-
* @method spotLight
|
|
1342
|
-
* @param {Number} v1
|
|
1343
|
-
* @param {Number} v2
|
|
1344
|
-
* @param {Number} v3
|
|
1345
|
-
* @param {p5.Vector} position
|
|
1346
|
-
* @param {Number} rx
|
|
1347
|
-
* @param {Number} ry
|
|
1348
|
-
* @param {Number} rz
|
|
1349
|
-
* @param {Number} [angle]
|
|
1350
|
-
* @param {Number} [concentration]
|
|
1351
|
-
*/
|
|
1352
|
-
/**
|
|
1353
|
-
* @method spotLight
|
|
1354
|
-
* @param {p5.Color|Number[]|String} color
|
|
1355
|
-
* @param {Number} x
|
|
1356
|
-
* @param {Number} y
|
|
1357
|
-
* @param {Number} z
|
|
1358
|
-
* @param {Number} rx
|
|
1359
|
-
* @param {Number} ry
|
|
1360
|
-
* @param {Number} rz
|
|
1361
|
-
* @param {Number} [angle]
|
|
1362
|
-
* @param {Number} [concentration]
|
|
1363
|
-
*/
|
|
1364
|
-
fn.spotLight = function (
|
|
1365
|
-
v1,
|
|
1366
|
-
v2,
|
|
1367
|
-
v3,
|
|
1368
|
-
x,
|
|
1369
|
-
y,
|
|
1370
|
-
z,
|
|
1371
|
-
nx,
|
|
1372
|
-
ny,
|
|
1373
|
-
nz,
|
|
1374
|
-
angle,
|
|
1375
|
-
concentration
|
|
1376
|
-
) {
|
|
1377
|
-
this._assert3d('spotLight');
|
|
1378
|
-
// p5._validateParameters('spotLight', arguments);
|
|
1379
|
-
|
|
1380
|
-
this._renderer.spotLight(...arguments);
|
|
1381
|
-
|
|
1382
|
-
return this;
|
|
1383
|
-
};
|
|
1384
|
-
|
|
1385
|
-
/**
|
|
1386
|
-
* Removes all lights from the sketch.
|
|
1387
|
-
*
|
|
1388
|
-
* Calling `noLights()` removes any lights created with
|
|
1389
|
-
* <a href="#/p5/lights">lights()</a>,
|
|
1390
|
-
* <a href="#/p5/ambientLight">ambientLight()</a>,
|
|
1391
|
-
* <a href="#/p5/directionalLight">directionalLight()</a>,
|
|
1392
|
-
* <a href="#/p5/pointLight">pointLight()</a>, or
|
|
1393
|
-
* <a href="#/p5/spotLight">spotLight()</a>. These functions may be called
|
|
1394
|
-
* after `noLights()` to create a new lighting scheme.
|
|
1395
|
-
*
|
|
1396
|
-
* @method noLights
|
|
1397
|
-
* @chainable
|
|
1398
|
-
*
|
|
1399
|
-
* @example
|
|
1400
|
-
* <div>
|
|
1401
|
-
* <code>
|
|
1402
|
-
* // Click and drag the mouse to view the scene from different angles.
|
|
1403
|
-
*
|
|
1404
|
-
* function setup() {
|
|
1405
|
-
* createCanvas(100, 100, WEBGL);
|
|
1406
|
-
*
|
|
1407
|
-
* describe('Two spheres drawn against a gray background. The top sphere is white and the bottom sphere is red.');
|
|
1408
|
-
* }
|
|
1409
|
-
*
|
|
1410
|
-
* function draw() {
|
|
1411
|
-
* background(50);
|
|
1412
|
-
*
|
|
1413
|
-
* // Enable orbiting with the mouse.
|
|
1414
|
-
* orbitControl();
|
|
1415
|
-
*
|
|
1416
|
-
* // Turn on the lights.
|
|
1417
|
-
* lights();
|
|
1418
|
-
*
|
|
1419
|
-
* // Style the spheres.
|
|
1420
|
-
* noStroke();
|
|
1421
|
-
*
|
|
1422
|
-
* // Draw the top sphere.
|
|
1423
|
-
* push();
|
|
1424
|
-
* translate(0, -25, 0);
|
|
1425
|
-
* sphere(20);
|
|
1426
|
-
* pop();
|
|
1427
|
-
*
|
|
1428
|
-
* // Turn off the lights.
|
|
1429
|
-
* noLights();
|
|
1430
|
-
*
|
|
1431
|
-
* // Add a red directional light that points into the screen.
|
|
1432
|
-
* directionalLight(255, 0, 0, 0, 0, -1);
|
|
1433
|
-
*
|
|
1434
|
-
* // Draw the bottom sphere.
|
|
1435
|
-
* push();
|
|
1436
|
-
* translate(0, 25, 0);
|
|
1437
|
-
* sphere(20);
|
|
1438
|
-
* pop();
|
|
1439
|
-
* }
|
|
1440
|
-
* </code>
|
|
1441
|
-
* </div>
|
|
1442
|
-
*/
|
|
1443
|
-
fn.noLights = function (...args) {
|
|
1444
|
-
this._assert3d('noLights');
|
|
1445
|
-
// p5._validateParameters('noLights', args);
|
|
1446
|
-
|
|
1447
|
-
this._renderer.noLights();
|
|
1448
|
-
|
|
1449
|
-
return this;
|
|
1450
|
-
};
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
RendererGL.prototype.ambientLight = function(v1, v2, v3, a) {
|
|
1454
|
-
const color = this._pInst.color(...arguments);
|
|
1455
|
-
|
|
1456
|
-
this.states.setValue('ambientLightColors', [...this.states.ambientLightColors]);
|
|
1457
|
-
this.states.ambientLightColors.push(
|
|
1458
|
-
color._array[0],
|
|
1459
|
-
color._array[1],
|
|
1460
|
-
color._array[2]
|
|
1461
|
-
);
|
|
1462
|
-
|
|
1463
|
-
this.states.setValue('enableLighting', true);
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
RendererGL.prototype.specularColor = function(v1, v2, v3) {
|
|
1467
|
-
const color = this._pInst.color(...arguments);
|
|
1468
|
-
|
|
1469
|
-
this.states.setValue('specularColors', [
|
|
1470
|
-
color._array[0],
|
|
1471
|
-
color._array[1],
|
|
1472
|
-
color._array[2]
|
|
1473
|
-
]);
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
RendererGL.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
|
|
1477
|
-
let color;
|
|
1478
|
-
if (v1 instanceof Color) {
|
|
1479
|
-
color = v1;
|
|
1480
|
-
} else {
|
|
1481
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
let _x, _y, _z;
|
|
1485
|
-
const v = arguments[arguments.length - 1];
|
|
1486
|
-
if (typeof v === 'number') {
|
|
1487
|
-
_x = arguments[arguments.length - 3];
|
|
1488
|
-
_y = arguments[arguments.length - 2];
|
|
1489
|
-
_z = arguments[arguments.length - 1];
|
|
1490
|
-
} else {
|
|
1491
|
-
_x = v.x;
|
|
1492
|
-
_y = v.y;
|
|
1493
|
-
_z = v.z;
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
// normalize direction
|
|
1497
|
-
const l = Math.sqrt(_x * _x + _y * _y + _z * _z);
|
|
1498
|
-
this.states.setValue('directionalLightDirections', [...this.states.directionalLightDirections]);
|
|
1499
|
-
this.states.directionalLightDirections.push(_x / l, _y / l, _z / l);
|
|
1500
|
-
|
|
1501
|
-
this.states.setValue('directionalLightDiffuseColors', [...this.states.directionalLightDiffuseColors]);
|
|
1502
|
-
this.states.directionalLightDiffuseColors.push(
|
|
1503
|
-
color._array[0],
|
|
1504
|
-
color._array[1],
|
|
1505
|
-
color._array[2]
|
|
1506
|
-
);
|
|
1507
|
-
|
|
1508
|
-
this.states.setValue('directionalLightSpecularColors', [...this.states.directionalLightSpecularColors]);
|
|
1509
|
-
Array.prototype.push.apply(
|
|
1510
|
-
this.states.directionalLightSpecularColors,
|
|
1511
|
-
this.states.specularColors
|
|
1512
|
-
);
|
|
1513
|
-
|
|
1514
|
-
this.states.setValue('enableLighting', true);
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
|
-
RendererGL.prototype.pointLight = function(v1, v2, v3, x, y, z) {
|
|
1518
|
-
let color;
|
|
1519
|
-
if (v1 instanceof Color) {
|
|
1520
|
-
color = v1;
|
|
1521
|
-
} else {
|
|
1522
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
let _x, _y, _z;
|
|
1526
|
-
const v = arguments[arguments.length - 1];
|
|
1527
|
-
if (typeof v === 'number') {
|
|
1528
|
-
_x = arguments[arguments.length - 3];
|
|
1529
|
-
_y = arguments[arguments.length - 2];
|
|
1530
|
-
_z = arguments[arguments.length - 1];
|
|
1531
|
-
} else {
|
|
1532
|
-
_x = v.x;
|
|
1533
|
-
_y = v.y;
|
|
1534
|
-
_z = v.z;
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
this.states.setValue('pointLightPositions', [...this.states.pointLightPositions]);
|
|
1538
|
-
this.states.pointLightPositions.push(_x, _y, _z);
|
|
1539
|
-
|
|
1540
|
-
this.states.setValue('pointLightDiffuseColors', [...this.states.pointLightDiffuseColors]);
|
|
1541
|
-
this.states.pointLightDiffuseColors.push(
|
|
1542
|
-
color._array[0],
|
|
1543
|
-
color._array[1],
|
|
1544
|
-
color._array[2]
|
|
1545
|
-
);
|
|
1546
|
-
|
|
1547
|
-
this.states.setValue('pointLightSpecularColors', [...this.states.pointLightSpecularColors]);
|
|
1548
|
-
Array.prototype.push.apply(
|
|
1549
|
-
this.states.pointLightSpecularColors,
|
|
1550
|
-
this.states.specularColors
|
|
1551
|
-
);
|
|
1552
|
-
|
|
1553
|
-
this.states.setValue('enableLighting', true);
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
RendererGL.prototype.imageLight = function(img) {
|
|
1557
|
-
// activeImageLight property is checked by _setFillUniforms
|
|
1558
|
-
// for sending uniforms to the fillshader
|
|
1559
|
-
this.states.setValue('activeImageLight', img);
|
|
1560
|
-
this.states.setValue('enableLighting', true);
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
RendererGL.prototype.lights = function() {
|
|
1564
|
-
const grayColor = this._pInst.color('rgb(128,128,128)');
|
|
1565
|
-
this.ambientLight(grayColor);
|
|
1566
|
-
this.directionalLight(grayColor, 0, 0, -1);
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
RendererGL.prototype.lightFalloff = function(
|
|
1570
|
-
constantAttenuation,
|
|
1571
|
-
linearAttenuation,
|
|
1572
|
-
quadraticAttenuation
|
|
1573
|
-
) {
|
|
1574
|
-
if (constantAttenuation < 0) {
|
|
1575
|
-
constantAttenuation = 0;
|
|
1576
|
-
console.warn(
|
|
1577
|
-
'Value of constant argument in lightFalloff() should be never be negative. Set to 0.'
|
|
1578
|
-
);
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
if (linearAttenuation < 0) {
|
|
1582
|
-
linearAttenuation = 0;
|
|
1583
|
-
console.warn(
|
|
1584
|
-
'Value of linear argument in lightFalloff() should be never be negative. Set to 0.'
|
|
1585
|
-
);
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
if (quadraticAttenuation < 0) {
|
|
1589
|
-
quadraticAttenuation = 0;
|
|
1590
|
-
console.warn(
|
|
1591
|
-
'Value of quadratic argument in lightFalloff() should be never be negative. Set to 0.'
|
|
1592
|
-
);
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
if (
|
|
1596
|
-
constantAttenuation === 0 &&
|
|
1597
|
-
(linearAttenuation === 0 && quadraticAttenuation === 0)
|
|
1598
|
-
) {
|
|
1599
|
-
constantAttenuation = 1;
|
|
1600
|
-
console.warn(
|
|
1601
|
-
'Either one of the three arguments in lightFalloff() should be greater than zero. Set constant argument to 1.'
|
|
1602
|
-
);
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
this.states.setValue('constantAttenuation', constantAttenuation);
|
|
1606
|
-
this.states.setValue('linearAttenuation', linearAttenuation);
|
|
1607
|
-
this.states.setValue('quadraticAttenuation', quadraticAttenuation);
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
RendererGL.prototype.spotLight = function(
|
|
1611
|
-
v1,
|
|
1612
|
-
v2,
|
|
1613
|
-
v3,
|
|
1614
|
-
x,
|
|
1615
|
-
y,
|
|
1616
|
-
z,
|
|
1617
|
-
nx,
|
|
1618
|
-
ny,
|
|
1619
|
-
nz,
|
|
1620
|
-
angle,
|
|
1621
|
-
concentration
|
|
1622
|
-
) {
|
|
1623
|
-
let color, position, direction;
|
|
1624
|
-
const length = arguments.length;
|
|
1625
|
-
|
|
1626
|
-
switch (length) {
|
|
1627
|
-
case 11:
|
|
1628
|
-
case 10:
|
|
1629
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1630
|
-
position = new Vector(x, y, z);
|
|
1631
|
-
direction = new Vector(nx, ny, nz);
|
|
1632
|
-
break;
|
|
1633
|
-
|
|
1634
|
-
case 9:
|
|
1635
|
-
if (v1 instanceof Color) {
|
|
1636
|
-
color = v1;
|
|
1637
|
-
position = new Vector(v2, v3, x);
|
|
1638
|
-
direction = new Vector(y, z, nx);
|
|
1639
|
-
angle = ny;
|
|
1640
|
-
concentration = nz;
|
|
1641
|
-
} else if (x instanceof Vector) {
|
|
1642
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1643
|
-
position = x;
|
|
1644
|
-
direction = new Vector(y, z, nx);
|
|
1645
|
-
angle = ny;
|
|
1646
|
-
concentration = nz;
|
|
1647
|
-
} else if (nx instanceof Vector) {
|
|
1648
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1649
|
-
position = new Vector(x, y, z);
|
|
1650
|
-
direction = nx;
|
|
1651
|
-
angle = ny;
|
|
1652
|
-
concentration = nz;
|
|
1653
|
-
} else {
|
|
1654
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1655
|
-
position = new Vector(x, y, z);
|
|
1656
|
-
direction = new Vector(nx, ny, nz);
|
|
1657
|
-
}
|
|
1658
|
-
break;
|
|
1659
|
-
|
|
1660
|
-
case 8:
|
|
1661
|
-
if (v1 instanceof Color) {
|
|
1662
|
-
color = v1;
|
|
1663
|
-
position = new Vector(v2, v3, x);
|
|
1664
|
-
direction = new Vector(y, z, nx);
|
|
1665
|
-
angle = ny;
|
|
1666
|
-
} else if (x instanceof Vector) {
|
|
1667
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1668
|
-
position = x;
|
|
1669
|
-
direction = new Vector(y, z, nx);
|
|
1670
|
-
angle = ny;
|
|
1671
|
-
} else {
|
|
1672
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1673
|
-
position = new Vector(x, y, z);
|
|
1674
|
-
direction = nx;
|
|
1675
|
-
angle = ny;
|
|
1676
|
-
}
|
|
1677
|
-
break;
|
|
1678
|
-
|
|
1679
|
-
case 7:
|
|
1680
|
-
if (v1 instanceof Color && v2 instanceof Vector) {
|
|
1681
|
-
color = v1;
|
|
1682
|
-
position = v2;
|
|
1683
|
-
direction = new Vector(v3, x, y);
|
|
1684
|
-
angle = z;
|
|
1685
|
-
concentration = nx;
|
|
1686
|
-
} else if (v1 instanceof Color && y instanceof Vector) {
|
|
1687
|
-
color = v1;
|
|
1688
|
-
position = new Vector(v2, v3, x);
|
|
1689
|
-
direction = y;
|
|
1690
|
-
angle = z;
|
|
1691
|
-
concentration = nx;
|
|
1692
|
-
} else if (x instanceof Vector && y instanceof Vector) {
|
|
1693
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1694
|
-
position = x;
|
|
1695
|
-
direction = y;
|
|
1696
|
-
angle = z;
|
|
1697
|
-
concentration = nx;
|
|
1698
|
-
} else if (v1 instanceof Color) {
|
|
1699
|
-
color = v1;
|
|
1700
|
-
position = new Vector(v2, v3, x);
|
|
1701
|
-
direction = new Vector(y, z, nx);
|
|
1702
|
-
} else if (x instanceof Vector) {
|
|
1703
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1704
|
-
position = x;
|
|
1705
|
-
direction = new Vector(y, z, nx);
|
|
1706
|
-
} else {
|
|
1707
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1708
|
-
position = new Vector(x, y, z);
|
|
1709
|
-
direction = nx;
|
|
1710
|
-
}
|
|
1711
|
-
break;
|
|
1712
|
-
|
|
1713
|
-
case 6:
|
|
1714
|
-
if (x instanceof Vector && y instanceof Vector) {
|
|
1715
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1716
|
-
position = x;
|
|
1717
|
-
direction = y;
|
|
1718
|
-
angle = z;
|
|
1719
|
-
} else if (v1 instanceof Color && y instanceof Vector) {
|
|
1720
|
-
color = v1;
|
|
1721
|
-
position = new Vector(v2, v3, x);
|
|
1722
|
-
direction = y;
|
|
1723
|
-
angle = z;
|
|
1724
|
-
} else if (v1 instanceof Color && v2 instanceof Vector) {
|
|
1725
|
-
color = v1;
|
|
1726
|
-
position = v2;
|
|
1727
|
-
direction = new Vector(v3, x, y);
|
|
1728
|
-
angle = z;
|
|
1729
|
-
}
|
|
1730
|
-
break;
|
|
1731
|
-
|
|
1732
|
-
case 5:
|
|
1733
|
-
if (
|
|
1734
|
-
v1 instanceof Color &&
|
|
1735
|
-
v2 instanceof Vector &&
|
|
1736
|
-
v3 instanceof Vector
|
|
1737
|
-
) {
|
|
1738
|
-
color = v1;
|
|
1739
|
-
position = v2;
|
|
1740
|
-
direction = v3;
|
|
1741
|
-
angle = x;
|
|
1742
|
-
concentration = y;
|
|
1743
|
-
} else if (x instanceof Vector && y instanceof Vector) {
|
|
1744
|
-
color = this._pInst.color(v1, v2, v3);
|
|
1745
|
-
position = x;
|
|
1746
|
-
direction = y;
|
|
1747
|
-
} else if (v1 instanceof Color && y instanceof Vector) {
|
|
1748
|
-
color = v1;
|
|
1749
|
-
position = new Vector(v2, v3, x);
|
|
1750
|
-
direction = y;
|
|
1751
|
-
} else if (v1 instanceof Color && v2 instanceof Vector) {
|
|
1752
|
-
color = v1;
|
|
1753
|
-
position = v2;
|
|
1754
|
-
direction = new Vector(v3, x, y);
|
|
1755
|
-
}
|
|
1756
|
-
break;
|
|
1757
|
-
|
|
1758
|
-
case 4:
|
|
1759
|
-
color = v1;
|
|
1760
|
-
position = v2;
|
|
1761
|
-
direction = v3;
|
|
1762
|
-
angle = x;
|
|
1763
|
-
break;
|
|
1764
|
-
|
|
1765
|
-
case 3:
|
|
1766
|
-
color = v1;
|
|
1767
|
-
position = v2;
|
|
1768
|
-
direction = v3;
|
|
1769
|
-
break;
|
|
1770
|
-
|
|
1771
|
-
default:
|
|
1772
|
-
console.warn(
|
|
1773
|
-
`Sorry, input for spotlight() is not in prescribed format. Too ${
|
|
1774
|
-
length < 3 ? 'few' : 'many'
|
|
1775
|
-
} arguments were provided`
|
|
1776
|
-
);
|
|
1777
|
-
return;
|
|
1778
|
-
}
|
|
1779
|
-
this.states.setValue('spotLightDiffuseColors', [
|
|
1780
|
-
color._array[0],
|
|
1781
|
-
color._array[1],
|
|
1782
|
-
color._array[2]
|
|
1783
|
-
]);
|
|
1784
|
-
|
|
1785
|
-
this.states.setValue('spotLightSpecularColors', [
|
|
1786
|
-
...this.states.specularColors
|
|
1787
|
-
]);
|
|
1788
|
-
|
|
1789
|
-
this.states.setValue('spotLightPositions', [position.x, position.y, position.z]);
|
|
1790
|
-
direction.normalize();
|
|
1791
|
-
this.states.setValue('spotLightDirections', [
|
|
1792
|
-
direction.x,
|
|
1793
|
-
direction.y,
|
|
1794
|
-
direction.z
|
|
1795
|
-
]);
|
|
1796
|
-
|
|
1797
|
-
if (angle === undefined) {
|
|
1798
|
-
angle = Math.PI / 3;
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
if (concentration !== undefined && concentration < 1) {
|
|
1802
|
-
concentration = 1;
|
|
1803
|
-
console.warn(
|
|
1804
|
-
'Value of concentration needs to be greater than 1. Setting it to 1'
|
|
1805
|
-
);
|
|
1806
|
-
} else if (concentration === undefined) {
|
|
1807
|
-
concentration = 100;
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
angle = this._pInst._toRadians(angle);
|
|
1811
|
-
this.states.setValue('spotLightAngle', [Math.cos(angle)]);
|
|
1812
|
-
this.states.setValue('spotLightConc', [concentration]);
|
|
1813
|
-
|
|
1814
|
-
this.states.setValue('enableLighting', true);
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
|
-
RendererGL.prototype.noLights = function() {
|
|
1818
|
-
this.states.setValue('activeImageLight', null);
|
|
1819
|
-
this.states.setValue('enableLighting', false);
|
|
1820
|
-
|
|
1821
|
-
this.states.setValue('ambientLightColors', []);
|
|
1822
|
-
this.states.setValue('specularColors', [1, 1, 1]);
|
|
1823
|
-
|
|
1824
|
-
this.states.setValue('directionalLightDirections', []);
|
|
1825
|
-
this.states.setValue('directionalLightDiffuseColors', []);
|
|
1826
|
-
this.states.setValue('directionalLightSpecularColors', []);
|
|
1827
|
-
|
|
1828
|
-
this.states.setValue('pointLightPositions', []);
|
|
1829
|
-
this.states.setValue('pointLightDiffuseColors', []);
|
|
1830
|
-
this.states.setValue('pointLightSpecularColors', []);
|
|
1831
|
-
|
|
1832
|
-
this.states.setValue('spotLightPositions', []);
|
|
1833
|
-
this.states.setValue('spotLightDirections', []);
|
|
1834
|
-
this.states.setValue('spotLightDiffuseColors', []);
|
|
1835
|
-
this.states.setValue('spotLightSpecularColors', []);
|
|
1836
|
-
this.states.setValue('spotLightAngle', []);
|
|
1837
|
-
this.states.setValue('spotLightConc', []);
|
|
1838
|
-
|
|
1839
|
-
this.states.setValue('constantAttenuation', 1);
|
|
1840
|
-
this.states.setValue('linearAttenuation', 0);
|
|
1841
|
-
this.states.setValue('quadraticAttenuation', 0);
|
|
1842
|
-
this.states.setValue('_useShininess', 1);
|
|
1843
|
-
this.states.setValue('_useMetalness', 0);
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
export default light;
|
|
1848
|
-
|
|
1849
|
-
if(typeof p5 !== 'undefined'){
|
|
1850
|
-
light(p5, p5.prototype);
|
|
1851
|
-
}
|