Skip to content

Commit

Permalink
1.9.24
Browse files Browse the repository at this point in the history
  • Loading branch information
quinton-ashley committed May 30, 2024
1 parent f992a60 commit 34c9471
Show file tree
Hide file tree
Showing 20 changed files with 2,914 additions and 84 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Thanks in large part to @LingDong-'s design, q5 is well organized, concise, and

Features added by @quinton-ashley:

- `image.trim()`: removes transparent pixels from the edges of an image.
- `opacity(globalAlpha)`: set the opacity multiplier for anything subsequently drawn to the canvas in a range between 0 (transparent) and 1 (opaque).
- `textCache(enabled)`: Text image caching is enabled by default. Rotated text is only rendered once, and then cached as an image. This can result in ridiculously high 90x performance boosts for text-heavy sketches. Users don't need to change their code, the `text` function can be used as normal, q5 takes care of everything behind the scenes.
- `createImage`, `loadImage`, and `createGraphics`: as a last parameter to these functions, `opt` (options) object, users can specify canvas context attributes for an image or graphic. `opt.alpha` is set to true by default.
Expand Down
79 changes: 9 additions & 70 deletions home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,37 +150,15 @@ <h2 id="more-freedom-🔥">More freedom 🔥</h2>
<div id="reel10">
<md id="md10-0">
<h2 id="why-switch-from-p5-⚖️">Why switch from p5? ⚖️</h2>
<p>In October 2023, Processing's co-founder, Ben Fry, <a href="https://x.com/ben_fry/status/1709400641456501020"
target="_blank">publicly criticized</a> The Processing Foundation for squandering <a
href="https://medium.com/processing-foundation/processing-foundation-funding-update-94cddb25a3d9"
target="_blank">millions of dollars</a> and resigned. 🚪</p>
<p>So where is all that donor money going? 💸</p>
<p>Many of the proposed <a href="https://github.com/processing/p5.js/issues/6678" target="_blank">"2.0"
updates</a> to p5.js are years overdue. The p5 web editor has <a
href="https://medium.com/processing-foundation/hello-p5-js-web-editor-b90b902b74cf" target="_blank">hardly
changed since it released in 2018</a>. Even the legendary Dan Shiffman has been waiting on a <a
href="https://github.com/processing/p5.js-web-editor/issues/208#issuecomment-263898359"
target="_blank">feature request for 7 years and counting</a>. So what hope does anyone else have at getting
their suggestions implemented? 📅</p>
<p>Volunteers are doing most of the real work on p5 and the p5 ecosystem, yet it still takes months for paid staff
to simply approve and publish crucial updates. Even the most popular third party p5 library, <a
href="https://p5play.org" target="_blank">p5play</a>, hasn't been offered a cent from the foundation. 😔</p>
<p>Why can't staff focus on p5? Perhaps because even the foundation's executives are too busy <a
href="https://www.linkedin.com/in/edsaber/" target="_blank">taking paychecks from other full-time jobs</a>.
🕵️</p>
<p>When confronted about any of this on Discord or GitHub, the p5 team ignores or bans posts by upset users,
citing "verbal violence" and playing the victim. It seems they'd prefer to take their $80k-$160k salaries in
peace. 🎂</p>
<p><a href="https://processingfoundation.org/" target="_blank">The Processing Foundation website</a> is filled
with aspirational platitudes but their actions speak louder than words. Many people in the community feel like
their trust in the foundation has been betrayed. 🤥</p>
</md>
<md id="md10-1">
<h2 id="q5-is-the-future-⌚️">q5 is the future ⌚️</h2>
<p>The q5 team aims to right these wrongs by being financially transparent, quick with useful updates, and
receptive to all feedback (especially criticism). 📝</p>
<p>We're inspired to carry on the legacy of Processing and truly champion the original creators' goals. Creative
coders deserve better, let's make it happen together! 🤝</p>
<p>In October 2023, The Processing Foundation's co-founder, Ben Fry, resigned and publicly criticized management
for <a href="https://x.com/ben_fry/status/1709400641456501020" target="_blank">squandering millions of dollars
in donations</a>.</p>
<p>Despite taking exorbitant salaries, the foundation's executives are too busy <a
href="https://www.linkedin.com/in/edsaber/" target="_blank">working other full-time jobs</a> to focus on p5.
Volunteers still do most of the real work, yet it takes several months for paid staff to simply approve and
publish crucial updates. 🕵️</p>
<p>Creative coders deserve better, let's make it happen together! q5 will be run as a worker co-op. All
contributors will be fairly compensated for their work. 🤝</p>
</md>
</div>
<div id="reel6">
Expand Down Expand Up @@ -292,45 +270,6 @@ <h2 id="webgpu-support-🚀">WebGPU support 🚀</h2>










































</body>

</html>
4 changes: 2 additions & 2 deletions home/mie.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class MiniEditor {
else mini.className += ' vert';
mini.id = 'mie-' + this.id;
mini.style = script.style.cssText;
if (!script.style.cssText.includes('width')) {
mini.style.width = props.width || 'fit-content';
if (!script.style.cssText.includes('width') && props.width) {
mini.style.width = props.width;
}
script.after(mini);
this.elem = mini;
Expand Down
18 changes: 8 additions & 10 deletions lang/en/home/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ We're already working on a next-gen version of q5 that uses [WebGPU](https://dev

## Why switch from p5? ⚖️

In October 2023, Processing's co-founder, Ben Fry, [publicly criticized](https://x.com/ben_fry/status/1709400641456501020) The Processing Foundation for squandering [millions of dollars](https://medium.com/processing-foundation/processing-foundation-funding-update-94cddb25a3d9) and resigned. 🚪
In October 2023, The Processing Foundation's co-founder, Ben Fry, resigned and publicly criticized management for [squandering millions of dollars in donations](https://x.com/ben_fry/status/1709400641456501020).

Despite taking exorbitant salaries, the foundation's executives are too busy [working other full-time jobs](https://www.linkedin.com/in/edsaber/) to focus on p5. Volunteers still do most of the real work, yet it takes several months for paid staff to simply approve and publish crucial updates. 🕵️

Creative coders deserve better, let's make it happen together! q5 will be run as a worker co-op. All contributors will be fairly compensated for their work. 🤝

# 10-1

So where is all that donor money going? 💸

Expand All @@ -79,12 +85,4 @@ Why can't staff focus on p5? Perhaps because even the foundation's executives ar

When confronted about any of this on Discord or GitHub, the p5 team ignores or bans posts by upset users, citing "verbal violence" and playing the victim. It seems they'd prefer to take their $80k-$160k salaries in peace. 🎂

[The Processing Foundation website](https://processingfoundation.org/) is filled with aspirational platitudes but their actions speak louder than words. Many people in the community feel like their trust in the foundation has been betrayed. 🤥

# 10-1

## q5 is the future ⌚️

The q5 team aims to right these wrongs by being financially transparent, quick with useful updates, and receptive to all feedback (especially criticism). 📝

We're inspired to carry on the legacy of Processing and truly champion the original creators' goals. Creative coders deserve better, let's make it happen together! 🤝
[The Processing Foundation website](https://processingfoundation.org/) is filled with aspirational platitudes but their actions speak louder than words. Many people in the community feel like their trust in the foundation has been betrayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "quinton-ashley",
"name": "q5",
"version": "1.9.23",
"version": "1.9.24",
"description": "The unofficial sequel to p5.js",
"main": "q5-server.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion q5-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ Q5._createNodeJSCanvas = function () {
});
};

module.exports = Q5;
global.p5 ??= Q5;
module.exports = global.Q5 = Q5;
215 changes: 215 additions & 0 deletions src/q5-2d-canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
Q5.modules.q2d_canvas = ($) => {
let ctx = $.ctx;

let _OffscreenCanvas =
window.OffscreenCanvas ||
function () {
return document.createElement('canvas');
};

if (Q5._nodejs) {
if (Q5._createNodeJSCanvas) {
$.canvas = Q5._createNodeJSCanvas(100, 100);
}
} else if (scope == 'image' || scope == 'graphics') {
$.canvas = new _OffscreenCanvas(100, 100);
}
if (!$.canvas) {
if (typeof document == 'object') {
$.canvas = document.createElement('canvas');
$.canvas.id = 'defaultCanvas' + Q5._instanceCount++;
$.canvas.classList.add('p5Canvas', 'q5Canvas');
} else {
$.noCanvas();
}
}

$.canvas.width = $.width = 100;
$.canvas.height = $.height = 100;

if ($.canvas && scope != 'graphics' && scope != 'image') {
$._setupDone = false;
$._resize = () => {
if ($.frameCount > 1) $._shouldResize = true;
};
if (parent && typeof parent == 'string') {
parent = document.getElementById(parent);
}
$.canvas.parent = (el) => {
if (typeof el == 'string') el = document.getElementById(el);
el.append($.canvas);

if (typeof ResizeObserver == 'function') {
if ($._ro) $._ro.disconnect();
$._ro = new ResizeObserver($._resize);
$._ro.observe(parent);
} else if (!$.frameCount) {
window.addEventListener('resize', $._resize);
}
};
function appendCanvas() {
parent ??= document.getElementsByTagName('main')[0];
if (!parent) {
parent = document.createElement('main');
document.body.append(parent);
}
$.canvas.parent(parent);
}
if (document.body) appendCanvas();
else document.addEventListener('DOMContentLoaded', appendCanvas);
}

$.createCanvas = function (width, height, renderer, options) {
if (renderer == 'webgl') throw Error(`webgl renderer is not supported in q5, use '2d'`);
if (typeof renderer == 'object') options = renderer;
$.width = $.canvas.width = width || window.innerWidth;
$.height = $.canvas.height = height || window.innerHeight;
$.canvas.renderer = '2d';
let opt = Object.assign({}, Q5.canvasOptions);
if (options) Object.assign(opt, options);

ctx = $.ctx = $.drawingContext = $.canvas.getContext('2d', opt);
Object.assign($.canvas, opt);
if ($._colorMode == 'rgb') $.colorMode('rgb');
defaultStyle();
ctx.save();
if (scope != 'image') {
let pd = $.displayDensity();
if (scope == 'graphics') pd = this._pixelDensity;
$.pixelDensity(Math.ceil(pd));
} else this._pixelDensity = 1;
return $.canvas;
};
$._createCanvas = $.createCanvas;

if (scope == 'image') return;

function cloneCtx() {
let c = {};
for (let prop in ctx) {
if (typeof ctx[prop] != 'function') c[prop] = ctx[prop];
}
delete c.canvas;
return c;
}

function _resizeCanvas(w, h) {
w ??= window.innerWidth;
h ??= window.innerHeight;
$.width = w;
$.height = h;
let c = cloneCtx();
$.canvas.width = Math.ceil(w * $._pixelDensity);
$.canvas.height = Math.ceil(h * $._pixelDensity);
if (!$.canvas.fullscreen && $.canvas.style) {
$.canvas.style.width = w + 'px';
$.canvas.style.height = h + 'px';
}
for (let prop in c) $.ctx[prop] = c[prop];
ctx.scale($._pixelDensity, $._pixelDensity);
}

$.resizeCanvas = (w, h) => {
if (w == $.width && h == $.height) return;
_resizeCanvas(w, h);
};

$.createGraphics = function (w, h, opt) {
let g = new Q5('graphics');
opt ??= {};
opt.alpha ??= true;
g._createCanvas.call($, w, h, opt);
return g;
};

$._pixelDensity = 1;
$.displayDensity = () => window.devicePixelRatio;
$.pixelDensity = (v) => {
if (!v || v == $._pixelDensity) return $._pixelDensity;
$._pixelDensity = v;
_resizeCanvas($.width, $.height);
return v;
};

$.fullscreen = (v) => {
if (v === undefined) return document.fullscreenElement;
if (v) document.body.requestFullscreen();
else document.body.exitFullscreen();
};

// DRAWING MATRIX

$.translate = (x, y) => ctx.translate(x, y);
$.rotate = (r) => {
if ($._angleMode == 'degrees') r = $.radians(r);
ctx.rotate(r);
};
$.scale = (x, y) => {
y ??= x;
ctx.scale(x, y);
};
$.opacity = (a) => (ctx.globalAlpha = a);
$.applyMatrix = (a, b, c, d, e, f) => ctx.transform(a, b, c, d, e, f);
$.shearX = (ang) => ctx.transform(1, 0, $.tan(ang), 1, 0, 0);
$.shearY = (ang) => ctx.transform(1, $.tan(ang), 0, 1, 0, 0);
$.resetMatrix = () => {
ctx.resetTransform();
ctx.scale($._pixelDensity, $._pixelDensity);
};

$._styleNames = [
'_doStroke',
'_doFill',
'_strokeSet',
'_fillSet',
'_tint',
'_imageMode',
'_rectMode',
'_ellipseMode',
'_textFont',
'_textLeading',
'_leadingSet',
'_textSize',
'_textAlign',
'_textBaseline',
'_textStyle',
'_textWrap'
];
$._styles = [];

$.push = $.pushMatrix = () => {
ctx.save();
let styles = {};
for (let s of $._styleNames) styles[s] = $[s];
$._styles.push(styles);
};
$.pop = $.popMatrix = () => {
ctx.restore();
let styles = $._styles.pop();
for (let s of $._styleNames) $[s] = styles[s];
};

$.createCapture = (x) => {
var vid = document.createElement('video');
vid.playsinline = 'playsinline';
vid.autoplay = 'autoplay';
navigator.mediaDevices.getUserMedia(x).then((stream) => {
vid.srcObject = stream;
});
vid.style.position = 'absolute';
vid.style.opacity = 0.00001;
vid.style.zIndex = -1000;
document.body.append(vid);
return vid;
};
};

Q5.canvasOptions = {
alpha: false,
desynchronized: false,
colorSpace: 'display-p3'
};

if (!window.matchMedia || !matchMedia('(dynamic-range: high) and (color-gamut: p3)').matches) {
Q5.canvasOptions.colorSpace = 'srgb';
} else Q5.supportsHDR = true;
Loading

0 comments on commit 34c9471

Please sign in to comment.