added HSL color conversion support to Morphic

and updated Morphic documentation
pull/89/head
jmoenig 2019-01-01 15:25:50 +01:00
rodzic 1ba15afba7
commit 0bb72fbbdb
2 zmienionych plików z 137 dodań i 64 usunięć

Wyświetl plik

@ -8,7 +8,7 @@
written by Jens Mönig
jens@moenig.org
Copyright (C) 2018 by Jens Mönig
Copyright (C) 2019 by Jens Mönig
This file is part of Snap!.
@ -176,7 +176,7 @@
- Safari for Windows (deprecated)
- safari for Mac
- Safari for iOS (mobile)
- IE for Windows
- IE for Windows (partial support)
- Edge for Windows
- Opera for Windows
- Opera for Mac
@ -259,14 +259,16 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Morphic!</title>
<script type="text/javascript" src="morphic.js"></script>
<script type="text/javascript">
var world;
window.onload = function () {
world = new WorldMorph(
document.getElementById('world'));
world = new WorldMorph(document.getElementById('world'));
world.worldCanvas.focus();
world.isDevMode = true;
loop();
};
@ -276,15 +278,14 @@
}
</script>
</head>
<body>
<canvas id="world" tabindex="1" width="800" height="600">
<p>Your browser doesn't support canvas.</p>
</canvas>
<body style="margin: 0;">
<canvas id="world" tabindex="1" width="800" height="600"
style="position: absolute;" />
</body>
</html>
if you use ScrollFrames or otherwise plan to support mouse wheel
scrolling events, you might also add the following inline-CSS
scrolling events, make sure to add the following inline-CSS
attribute to the Canvas element:
style="position: absolute;"
@ -305,12 +306,14 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Morphic!</title>
<script type="text/javascript" src="morphic.js"></script>
<script type="text/javascript">
var world1, world2;
window.onload = function () {
disableRetinaSupport();
world1 = new WorldMorph(
document.getElementById('world1'), false);
world2 = new WorldMorph(
@ -327,13 +330,9 @@
</head>
<body>
<p>first world:</p>
<canvas id="world1" tabindex="1" width="600" height="400">
<p>Your browser doesn't support canvas.</p>
</canvas>
<canvas id="world1" tabindex="1" width="600" height="400" />
<p>second world:</p>
<canvas id="world2" tabindex="2" width="400" height="600">
<p>Your browser doesn't support canvas.</p>
</canvas>
<canvas id="world2" tabindex="2" width="400" height="600" />
</body>
</html>
@ -353,6 +352,7 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>touch me!</title>
<script type="text/javascript" src="morphic.js"></script>
<script type="text/javascript">
@ -363,8 +363,9 @@
worldCanvas = document.getElementById('world');
world = new WorldMorph(worldCanvas);
world.worldCanvas.focus();
world.isDevMode = false;
world.color = new Color();
world.setColor(new Color());
w = 100;
h = 100;
@ -393,10 +394,9 @@
}
</script>
</head>
<body bgcolor='black'>
<canvas id="world" width="800" height="600">
<p>Your browser doesn't support canvas.</p>
</canvas>
<body bgcolor='black' style="margin: 0;">
<canvas id="world" width="800" height="600"
style="position: absolute;" />
</body>
</html>
@ -1141,8 +1141,7 @@
editor for Windows, later switched to Apple's Dashcode and later
still to Apple's Xcode. I've also come to depend on both Douglas
Crockford's JSLint and later the JSHint project, as well as on
Mozilla's Firebug and Google's Chrome to get
it right.
Mozilla's Firebug and Google's Chrome to get it right.
IX. contributors
@ -1161,9 +1160,9 @@
// Global settings /////////////////////////////////////////////////////
/*global window, HTMLCanvasElement, FileReader, Audio, FileList*/
/*global window, HTMLCanvasElement, FileReader, Audio, FileList, Map*/
var morphicVersion = '2018-March-19';
var morphicVersion = '2019-January-01';
var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@ -2036,6 +2035,80 @@ Color.prototype.set_hsv = function (h, s, v) {
};
// Color conversion (hsl):
Color.prototype.hsl = function () {
// ignore alpha
var rr = this.r / 255,
gg = this.g / 255,
bb = this.b / 255,
max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb),
h,
s,
l = (max + min) / 2,
d;
if (max === min) { // achromatic
h = 0;
s = 0;
} else {
d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case rr:
h = (gg - bb) / d + (gg < bb ? 6 : 0);
break;
case gg:
h = (bb - rr) / d + 2;
break;
case bb:
h = (rr - gg) / d + 4;
break;
}
h /= 6;
}
return [h, s, l];
};
Color.prototype.set_hsl = function (h, s, l) {
// ignore alpha, h, s and l are to be within [0, 1]
var q, p;
function hue2rgb(p, q, t) {
if (t < 0) {
t += 1;
}
if (t > 1) {
t -= 1;
}
if (t < 1/6) {
return p + (q - p) * 6 * t;
}
if (t < 1/2) {
return q;
}
if (t < 2/3) {
return p + (q - p) * (2/3 - t) * 6;
}
return p;
}
if (s == 0) { // achromatic
this.r = l;
this.g = l;
this.b = l;
} else {
q = l < 0.5 ? l * (1 + s) : l + s - l * s;
p = 2 * l - q;
this.r = hue2rgb(p, q, h + 1/3);
this.g = hue2rgb(p, q, h);
this.b = hue2rgb(p, q, h - 1/3);
}
this.r *= 255;
this.g *= 255;
this.b *= 255;
};
// Color mixing:
Color.prototype.mixed = function (proportion, otherColor) {

Wyświetl plik

@ -1,30 +1,29 @@
morphic.js
morphic.js
a lively Web-GUI
inspired by Squeak
a lively Web-GUI
inspired by Squeak
written by Jens Mönig
jens@moenig.org
written by Jens Mönig
jens@moenig.org
Copyright (C) 2019 by Jens Mönig
Copyright (C) 2017 by Jens Mönig
this documentation last changed: January 1, 2019
this documentation last changed: September 01, 2017
This file is part of Snap!.
This file is part of Snap!.
Snap! is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Snap! is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
documentation contents
@ -86,6 +85,7 @@
ColorPaletteMorph
GrayPaletteMorph
ColorPickerMorph
DialMorph
FrameMorph
ScrollFrameMorph
ListMorph
@ -127,6 +127,7 @@
CursorMorph
BoxMorph
SpeechBubbleMorph
DialMorph
CircleBoxMorph
SliderButtonMorph
SliderMorph
@ -175,7 +176,7 @@
- Safari for Windows (deprecated)
- safari for Mac
- Safari for iOS (mobile)
- IE for Windows
- IE for Windows (partial support)
- Edge for Windows
- Opera for Windows
- Opera for Mac
@ -258,14 +259,16 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Morphic!</title>
<script type="text/javascript" src="morphic.js"></script>
<script type="text/javascript">
var world;
window.onload = function () {
world = new WorldMorph(
document.getElementById('world'));
world = new WorldMorph(document.getElementById('world'));
world.worldCanvas.focus();
world.isDevMode = true;
loop();
};
@ -275,15 +278,14 @@
}
</script>
</head>
<body>
<canvas id="world" tabindex="1" width="800" height="600">
<p>Your browser doesn't support canvas.</p>
</canvas>
<body style="margin: 0;">
<canvas id="world" tabindex="1" width="800" height="600"
style="position: absolute;" />
</body>
</html>
if you use ScrollFrames or otherwise plan to support mouse wheel
scrolling events, you might also add the following inline-CSS
scrolling events, make sure to add the following inline-CSS
attribute to the Canvas element:
style="position: absolute;"
@ -304,12 +306,14 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Morphic!</title>
<script type="text/javascript" src="morphic.js"></script>
<script type="text/javascript">
var world1, world2;
window.onload = function () {
disableRetinaSupport();
world1 = new WorldMorph(
document.getElementById('world1'), false);
world2 = new WorldMorph(
@ -326,13 +330,9 @@
</head>
<body>
<p>first world:</p>
<canvas id="world1" tabindex="1" width="600" height="400">
<p>Your browser doesn't support canvas.</p>
</canvas>
<canvas id="world1" tabindex="1" width="600" height="400" />
<p>second world:</p>
<canvas id="world2" tabindex="2" width="400" height="600">
<p>Your browser doesn't support canvas.</p>
</canvas>
<canvas id="world2" tabindex="2" width="400" height="600" />
</body>
</html>
@ -352,6 +352,7 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>touch me!</title>
<script type="text/javascript" src="morphic.js"></script>
<script type="text/javascript">
@ -362,8 +363,9 @@
worldCanvas = document.getElementById('world');
world = new WorldMorph(worldCanvas);
world.worldCanvas.focus();
world.isDevMode = false;
world.color = new Color();
world.setColor(new Color());
w = 100;
h = 100;
@ -392,10 +394,9 @@
}
</script>
</head>
<body bgcolor='black'>
<canvas id="world" width="800" height="600">
<p>Your browser doesn't support canvas.</p>
</canvas>
<body bgcolor='black' style="margin: 0;">
<canvas id="world" width="800" height="600"
style="position: absolute;" />
</body>
</html>
@ -1140,8 +1141,7 @@
editor for Windows, later switched to Apple's Dashcode and later
still to Apple's Xcode. I've also come to depend on both Douglas
Crockford's JSLint and later the JSHint project, as well as on
Mozilla's Firebug and Google's Chrome to get
it right.
Mozilla's Firebug and Google's Chrome to get it right.
IX. contributors