Skip to content

Commit 433fabc

Browse files
authored
Merge branch 'dev-2.0' into comma-included-in-loadFont
2 parents dc60363 + 165a9ed commit 433fabc

33 files changed

+2984
-2376
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
"editor.formatOnSave": false,
1111
"editor.codeActionsOnSave": {},
1212
"javascript.format.enable": false
13-
}
13+
}

lib/empty-example/sketch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ function setup() {
44

55
function draw() {
66
// put drawing code here
7-
}
7+
}

preview/global/sketch.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
p5.disableFriendlyErrors = true;
2-
3-
function windowResized() {
4-
resizeCanvas(windowWidth, windowHeight);
5-
}
6-
7-
let starShader;
8-
let starStrokeShader;
1+
let instancedShader;
2+
let instancedStrokeShader;
93
let stars;
10-
let originalFrameBuffer;
11-
let pixellizeShader;
4+
let originalImage;
5+
let pixelateShader;
126
let fresnelShader;
137
let bloomShader;
148

159
function fresnelShaderCallback() {
1610
const fresnelPower = uniformFloat(2);
1711
const fresnelBias = uniformFloat(-0.1);
1812
const fresnelScale = uniformFloat(2);
13+
1914
getCameraInputs((inputs) => {
2015
let n = normalize(inputs.normal);
2116
let v = normalize(-inputs.position);
@@ -29,18 +24,19 @@ function fresnelShaderCallback() {
2924

3025
function starShaderCallback() {
3126
const time = uniformFloat(() => millis());
32-
const skyRadius = uniformFloat(1000);
27+
const skyRadius = uniformFloat(250);
3328

3429
function rand2(st) {
3530
return fract(sin(dot(st, [12.9898, 78.233])) * 43758.5453123);
3631
}
3732

3833
function semiSphere() {
3934
let id = instanceID();
40-
let theta = rand2([id, 0.1234]) * TWO_PI;
41-
let phi = rand2([id, 3.321]) * PI+time/10000;
35+
let theta = rand2([id, 0.1234]) * TWO_PI + time / 100000;
36+
let phi = rand2([id, 3.321]) * PI + time / 50000;
37+
4238
let r = skyRadius;
43-
r *= 1.5 * sin(phi);
39+
r *= sin(phi);
4440
let x = r * sin(phi) * cos(theta);
4541
let y = r * 1.5 * cos(phi);
4642
let z = r * sin(phi) * sin(theta);
@@ -53,72 +49,80 @@ function starShaderCallback() {
5349
});
5450

5551
getObjectInputs((inputs) => {
56-
let scale = 1 + 0.1 * sin(time * 0.002 + instanceID());
57-
inputs.position *= scale;
52+
let size = 1 + 0.5 * sin(time * 0.002 + instanceID());
53+
inputs.position *= size;
5854
return inputs;
5955
});
6056
}
6157

62-
function pixellizeShaderCallback() {
63-
const pixelSize = uniformFloat(()=> width*.75);
64-
getColor((input, canvasContent) => {
65-
let coord = input.texCoord;
58+
function pixelateShaderCallback() {
59+
const pixelCountX = uniformFloat(()=> 280);
60+
61+
getColor((inputs, canvasContent) => {
62+
const aspectRatio = inputs.canvasSize.x / inputs.canvasSize.y;
63+
const pixelSize = [pixelCountX, pixelCountX / aspectRatio];
64+
65+
let coord = inputs.texCoord;
6666
coord = floor(coord * pixelSize) / pixelSize;
67-
let col = texture(canvasContent, coord);
68-
return col;
67+
68+
let col = getTexture(canvasContent, coord);
69+
return col//[coord, 0, 1];
6970
});
7071
}
7172

7273
function bloomShaderCallback() {
73-
const preBlur = uniformTexture(() => originalFrameBuffer);
74+
const preBlur = uniformTexture(() => originalImage);
75+
7476
getColor((input, canvasContent) => {
75-
const blurredCol = texture(canvasContent, input.texCoord);
76-
const originalCol = texture(preBlur, input.texCoord);
77-
const brightPass = max(originalCol, 0.3) * 1.5;
78-
const bloom = originalCol + blurredCol * brightPass;
79-
return bloom;
77+
const blurredCol = getTexture(canvasContent, input.texCoord);
78+
const originalCol = getTexture(preBlur, input.texCoord);
79+
80+
const intensity = max(originalCol, 0.1) * 12.2;
81+
const bloom = originalCol + blurredCol * intensity;
82+
return [bloom.rgb, 1];
8083
});
8184
}
8285

8386
async function setup(){
84-
createCanvas(windowWidth, windowHeight, WEBGL);
85-
stars = buildGeometry(() => sphere(30, 4, 2))
86-
originalFrameBuffer = createFramebuffer();
87+
createCanvas(800, 600, WEBGL);
88+
pixelDensity(1);
89+
stars = buildGeometry(() => sphere(8, 4, 2))
90+
originalImage = createFramebuffer();
8791

8892
starShader = baseMaterialShader().modify(starShaderCallback);
8993
starStrokeShader = baseStrokeShader().modify(starShaderCallback)
9094
fresnelShader = baseColorShader().modify(fresnelShaderCallback);
9195
bloomShader = baseFilterShader().modify(bloomShaderCallback);
92-
pixellizeShader = baseFilterShader().modify(pixellizeShaderCallback);
96+
pixelateShader = baseFilterShader().modify(pixelateShaderCallback);
9397
}
9498

9599
function draw(){
96-
originalFrameBuffer.begin();
100+
originalImage.begin();
97101
background(0);
98102
orbitControl();
99103

100104
push()
101-
strokeWeight(4)
105+
strokeWeight(2)
102106
stroke(255,0,0)
103107
rotateX(PI/2 + millis() * 0.0005);
104108
fill(255,100, 150)
105109
strokeShader(starStrokeShader)
106110
shader(starShader);
107-
model(stars, 2000);
111+
model(stars, 1000);
108112
pop()
109113

110114
push()
111115
shader(fresnelShader)
112116
noStroke()
113-
sphere(500);
117+
sphere(90);
118+
filter(pixelateShader);
114119
pop()
115-
filter(pixellizeShader);
116120

117-
originalFrameBuffer.end();
121+
originalImage.end();
118122

119123
imageMode(CENTER)
120-
image(originalFrameBuffer, 0, 0)
124+
image(originalImage, 0, 0)
121125

122-
filter(BLUR, 20)
126+
filter(BLUR, 15)
123127
filter(bloomShader);
124-
}
128+
}

src/color/creating_reading.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,25 @@ function creatingReading(p5, fn){
10431043
* </div>
10441044
*/
10451045
fn.hue = function(c) {
1046-
// p5._validateParameters('hue', arguments);
1047-
return this.color(c)._getHue();
1046+
let colorMode = HSL;
1047+
let i = 0;
1048+
1049+
if(
1050+
this._renderer.states.colorMode === HSB ||
1051+
this._renderer.states.colorMode === HSL
1052+
){
1053+
colorMode = this._renderer.states.colorMode;
1054+
}else if(
1055+
this._renderer.states.colorMode === LCH ||
1056+
this._renderer.states.colorMode === OKLCH
1057+
){
1058+
colorMode = this._renderer.states.colorMode;
1059+
i = 2;
1060+
}
1061+
1062+
return this.color(c)._getHue(
1063+
this._renderer.states.colorMaxes[colorMode][i]
1064+
);
10481065
};
10491066

10501067
/**
@@ -1220,8 +1237,10 @@ function creatingReading(p5, fn){
12201237
* </div>
12211238
*/
12221239
fn.saturation = function(c) {
1223-
// p5._validateParameters('saturation', arguments);
1224-
return this.color(c)._getSaturation();
1240+
const colorMode = (this._renderer.states.colorMode === HSB) ? HSB : HSL;
1241+
return this.color(c)._getSaturation(
1242+
this._renderer.states.colorMaxes[colorMode][1]
1243+
);
12251244
};
12261245

12271246
/**
@@ -1365,8 +1384,9 @@ function creatingReading(p5, fn){
13651384
* </div>
13661385
*/
13671386
fn.brightness = function(c) {
1368-
// p5._validateParameters('brightness', arguments);
1369-
return this.color(c)._getBrightness();
1387+
return this.color(c)._getBrightness(
1388+
this._renderer.states.colorMaxes.hsb[2]
1389+
);
13701390
};
13711391

13721392
/**
@@ -1510,8 +1530,9 @@ function creatingReading(p5, fn){
15101530
* </div>
15111531
*/
15121532
fn.lightness = function(c) {
1513-
// p5._validateParameters('lightness', arguments);
1514-
return this.color(c)._getLightness();
1533+
return this.color(c)._getLightness(
1534+
this._renderer.states.colorMaxes.hsl[2]
1535+
);
15151536
};
15161537

15171538
/**

src/color/p5.Color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,14 @@ class Color {
689689
return map(to(this._color, 'hsl').coords[1], colorjsMax[0], colorjsMax[1], max[0], max[1]);
690690
}
691691
}
692+
692693
/**
693694
* Brightness obtains the HSB brightness value from either a p5.Color object,
694695
* an array of color components, or a CSS color string.Depending on value,
695696
* when `colorMode()` is set to HSB, this function will return the
696697
* brightness value in the range. By default, this function will return
697698
* the HSB brightness within the range 0 - 100.
698699
*/
699-
700700
_getBrightness(max=[0, 100]) {
701701
if(!Array.isArray(max)){
702702
max = [0, max];

src/color/setting.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ function setting(p5, fn){
439439
* in RGB values. Calling `background(255, 204, 0)` sets the background a bright
440440
* yellow color.
441441
*
442+
* The version of `background()` with four parameters interprets them as RGBA,
443+
* HSBA, or HSLA colors, depending on the current
444+
* <a href="#/p5/colorMode">colorMode()</a>. The last parameter sets the alpha
445+
* (transparency) value.
446+
*
442447
* @method background
443448
* @param {p5.Color} color any value created by the <a href="#/p5/color">color()</a> function
444449
* @chainable
@@ -487,6 +492,19 @@ function setting(p5, fn){
487492
* function setup() {
488493
* createCanvas(100, 100);
489494
*
495+
* // R, G, B, and Alpha values.
496+
* background(255, 0, 0, 128);
497+
*
498+
* describe('A canvas with a semi-transparent red background.');
499+
* }
500+
* </code>
501+
* </div>
502+
*
503+
* <div>
504+
* <code>
505+
* function setup() {
506+
* createCanvas(100, 100);
507+
*
490508
* // Use HSB color.
491509
* colorMode(HSB);
492510
*
@@ -1213,6 +1231,10 @@ function setting(p5, fn){
12131231
* <a href="#/p5/colorMode">colorMode()</a>. The default color space is RGB,
12141232
* with each value in the range from 0 to 255.
12151233
*
1234+
* The version of `fill()` with four parameters interprets them as `RGBA`, `HSBA`,
1235+
* or `HSLA` colors, depending on the current <a href="#/p5/colorMode">colorMode()</a>. The last parameter
1236+
* sets the alpha (transparency) value.
1237+
*
12161238
* @method fill
12171239
* @param {Number} v1 red value if color mode is RGB or hue value if color mode is HSB.
12181240
* @param {Number} v2 green value if color mode is RGB or saturation value if color mode is HSB.
@@ -1257,6 +1279,22 @@ function setting(p5, fn){
12571279
* function setup() {
12581280
* createCanvas(100, 100);
12591281
*
1282+
* background(200);
1283+
*
1284+
* // R, G, B, and Alpha values.
1285+
* fill(255, 0, 0, 128);
1286+
* square(20, 20, 60);
1287+
*
1288+
* describe('A semi-transparent red square with a black outline.');
1289+
* }
1290+
* </code>
1291+
* </div>
1292+
*
1293+
* <div>
1294+
* <code>
1295+
* function setup() {
1296+
* createCanvas(100, 100);
1297+
*
12601298
* background(100);
12611299
*
12621300
* // Use HSB color.
@@ -1551,7 +1589,7 @@ function setting(p5, fn){
15511589
* Sets the color used to draw points, lines, and the outlines of shapes.
15521590
*
15531591
* Calling `stroke(255, 165, 0)` or `stroke('orange')` means all shapes drawn
1554-
* after calling `stroke()` will be filled with the color orange. The way
1592+
* after calling `stroke()` will be outlined with the color orange. The way
15551593
* these parameters are interpreted may be changed with the
15561594
* <a href="#/p5/colorMode">colorMode()</a> function.
15571595
*

src/core/friendly_errors/param_validator.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,10 @@ function validateParams(p5, fn, lifecycles) {
573573
lifecycles.presetup = function(){
574574
loadP5Constructors();
575575

576-
if(p5.disableParameterValidator !== true){
576+
if(
577+
p5.disableParameterValidator !== true &&
578+
p5.disableFriendlyErrors !== true
579+
){
577580
const excludes = ['validate'];
578581
for(const f in this){
579582
if(!excludes.includes(f) && !f.startsWith('_') && typeof this[f] === 'function'){

src/core/internationalization.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import i18next from 'i18next';
22
import LanguageDetector from 'i18next-browser-languagedetector';
33
import { default as fallbackResources, languages } from '../../translations';
4+
import { VERSION } from './constants';
45

56
if (typeof IS_MINIFIED === 'undefined') {
67
// internationalization is only for the unminified build
@@ -147,8 +148,12 @@ export const initialize = () => {
147148
},
148149
backend: {
149150
fallback: 'en',
150-
loadPath:
151-
'https://cdn.jsdelivr.net/npm/p5/translations/{{lng}}/{{ns}}.json'
151+
152+
// ensure that the FES internationalization strings are loaded
153+
// from the latest patch of the current minor version of p5.js
154+
loadPath: `https://cdn.jsdelivr.net/npm/p5@${
155+
VERSION.replace(/^(\d+\.\d+)\.\d+.*$/, '$1')
156+
}/translations/{{lng}}/{{ns}}.json`
152157
},
153158
partialBundledLanguages: true,
154159
resources: fallbackResources

0 commit comments

Comments
 (0)