From 9c582e785ec8f8a42c79890b2bcf209cf35effba Mon Sep 17 00:00:00 2001 From: jmoenig Date: Sat, 19 Jun 2021 11:31:44 +0200 Subject: [PATCH] added color extension primitives --- HISTORY.md | 3 +++ snap.html | 2 +- src/extensions.js | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 0b5e37fb..43d290a6 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,9 @@ * **Notable Fixes:** * fixed occasional invisible error messages +### 2021-06-19 +* extensions: added color extension primitives + ### 2021-06-18 * extensions: added text extension primitives * updated strings library diff --git a/snap.html b/snap.html index a9e48dcc..cf2860d9 100755 --- a/snap.html +++ b/snap.html @@ -19,7 +19,7 @@ - + diff --git a/src/extensions.js b/src/extensions.js index bd03f1eb..bf00a41f 100644 --- a/src/extensions.js +++ b/src/extensions.js @@ -28,9 +28,10 @@ // Global settings ///////////////////////////////////////////////////// /*global modules, List, StageMorph, Costume, SpeechSynthesisUtterance, Sound, -IDE_Morph, CamSnapshotDialogMorph, SoundRecorderDialogMorph, isSnapObject, nop*/ +IDE_Morph, CamSnapshotDialogMorph, SoundRecorderDialogMorph, isSnapObject, nop, +Color, contains*/ -modules.extensions = '2021-June-18'; +modules.extensions = '2021-June-19'; // Global stuff @@ -580,10 +581,43 @@ SnapExtensions.primitives.set( ); */ -// Brian's colors (sigh, clr_): +// Colors (clr_): + +SnapExtensions.primitives.set( + 'clr_rgba(r, g, b, a)', + function (r, g, b, a) { + return new Color(r, g, b, a); + } +); + +SnapExtensions.primitives.set( + 'clr_channel(clr, rgba)', + function (clr, rgba) { + if (contains(['r', 'g', 'b', 'a'], rgba)) { + return clr[rgba]; + } + throw new Error('unknown rgba color channel "' + rgba + '"'); + } +); + +SnapExtensions.primitives.set( + 'clr_hsv(h, s, v)', + function (h, s, v) { + var c = new Color(); + c.set_hsv(h, s, v); + return c; + } +); + +SnapExtensions.primitives.set( + 'clr_setpen(clr)', + function (clr) { + this.setColor(clr); + } +); SnapExtensions.menus.set( - 'clr_numbers', + 'clr_numbers', // Brian's browns and oranges, sigh... function () { var menuName = this.parent.inputs()[0].evaluate(), // first slot output,