kopia lustrzana https://github.com/backface/turtlestitch
experimental tolerant color collision detection (in dev mode)
rodzic
3d6d95d949
commit
0e9e9a05a7
|
@ -2,12 +2,14 @@
|
|||
|
||||
## in development:
|
||||
* **New Features:**
|
||||
* experimental tolerant color collision detection (in dev mode)
|
||||
* **Notable Changes:**
|
||||
* **Notable Fixes:**
|
||||
* **Translation Updates:**
|
||||
|
||||
### 2019-07-08
|
||||
* new dev version
|
||||
* morphic, objects, threads: experimental tolerant color collision detection (in dev mode)
|
||||
|
||||
## v5.0.1
|
||||
* **Notable Changes:**
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Snap! Build Your Own Blocks 5.0.2 - dev -</title>
|
||||
<link rel="shortcut icon" href="src/favicon.ico">
|
||||
<script type="text/javascript" src="src/morphic.js?version=2019-07-02"></script>
|
||||
<script type="text/javascript" src="src/morphic.js?version=2019-07-08"></script>
|
||||
<script type="text/javascript" src="src/widgets.js?version=2019-06-27"></script>
|
||||
<script type="text/javascript" src="src/blocks.js?version=2019-07-03"></script>
|
||||
<script type="text/javascript" src="src/threads.js?version=2019-07-01"></script>
|
||||
<script type="text/javascript" src="src/objects.js?version=2019-06-27"></script>
|
||||
<script type="text/javascript" src="src/gui.js?version=2019-07-04"></script>
|
||||
<script type="text/javascript" src="src/threads.js?version=2019-07-08"></script>
|
||||
<script type="text/javascript" src="src/objects.js?version=2019-07-08"></script>
|
||||
<script type="text/javascript" src="src/gui.js?version=2019-07-08"></script>
|
||||
<script type="text/javascript" src="src/paint.js?version=2019-06-27"></script>
|
||||
<script type="text/javascript" src="src/lists.js?version=2019-07-01"></script>
|
||||
<script type="text/javascript" src="src/byob.js?version=2019-06-27"></script>
|
||||
|
|
|
@ -1162,7 +1162,7 @@
|
|||
|
||||
/*global window, HTMLCanvasElement, FileReader, Audio, FileList, Map*/
|
||||
|
||||
var morphicVersion = '2019-July-02';
|
||||
var morphicVersion = '2019-July-08';
|
||||
var modules = {}; // keep track of additional loaded modules
|
||||
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
|
||||
|
||||
|
@ -1955,6 +1955,24 @@ Color.prototype.eq = function (aColor, observeAlpha) {
|
|||
(observeAlpha ? this.a === aColor.a : true);
|
||||
};
|
||||
|
||||
Color.prototype.isCloseTo = function (aColor, observeAlpha, tolerance) {
|
||||
// experimental - answer whether a color is "close" to another one by
|
||||
// a given percentage. tolerance is the percentage by which each color
|
||||
// channel may diverge, alpha needs to be the exact same unless ignored
|
||||
var thres = 2.55 * (tolerance || 10);
|
||||
|
||||
function dist(a, b) {
|
||||
var diff = a - b;
|
||||
return diff < 0 ? 255 + diff : diff;
|
||||
}
|
||||
|
||||
return aColor &&
|
||||
dist(this.r, aColor.r) < thres &&
|
||||
dist(this.g, aColor.g) < thres &&
|
||||
dist(this.b, aColor.b) < thres &&
|
||||
(observeAlpha ? this.a === aColor.a : true);
|
||||
};
|
||||
|
||||
// Color conversion (hsv):
|
||||
|
||||
Color.prototype.hsv = function () {
|
||||
|
|
|
@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
|||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
|
||||
AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph, WorldMap*/
|
||||
|
||||
modules.objects = '2019-June-25';
|
||||
modules.objects = '2019-July-08';
|
||||
|
||||
var SpriteMorph;
|
||||
var StageMorph;
|
||||
|
@ -875,7 +875,24 @@ SpriteMorph.prototype.initBlocks = function () {
|
|||
dev: true,
|
||||
type: 'reporter',
|
||||
category: 'sensing',
|
||||
spec: 'filtered for %clr'
|
||||
spec: 'filter %clr tolerance %n %',
|
||||
defaults: [null, 15]
|
||||
},
|
||||
reportFuzzyTouchingColor: {
|
||||
dev: true,
|
||||
only: SpriteMorph,
|
||||
type: 'predicate',
|
||||
category: 'sensing',
|
||||
spec: 'touching %clr tolerance %n ?',
|
||||
defaults: [null, 15]
|
||||
},
|
||||
reportFuzzyColorIsTouchingColor: {
|
||||
dev: true,
|
||||
only: SpriteMorph,
|
||||
type: 'predicate',
|
||||
category: 'sensing',
|
||||
spec: 'color %clr is touching %clr tolerance %n ?',
|
||||
defaults: [null, null, 15]
|
||||
},
|
||||
reportAspect: {
|
||||
type: 'reporter',
|
||||
|
@ -1913,7 +1930,7 @@ SpriteMorph.prototype.rotationCenter = function () {
|
|||
return this.position().add(this.rotationOffset);
|
||||
};
|
||||
|
||||
SpriteMorph.prototype.colorFiltered = function (aColor) {
|
||||
SpriteMorph.prototype.colorFiltered = function (aColor, tolerance) {
|
||||
// answer a new Morph containing my image filtered by aColor
|
||||
// ignore transparency (alpha)
|
||||
var morph = new Morph(),
|
||||
|
@ -1940,7 +1957,9 @@ SpriteMorph.prototype.colorFiltered = function (aColor) {
|
|||
src.data[i + 1],
|
||||
src.data[i + 2]
|
||||
);
|
||||
if (clr.eq(aColor)) {
|
||||
if ((tolerance && clr.isCloseTo(aColor, false, tolerance)) ||
|
||||
clr.eq(aColor)
|
||||
) {
|
||||
dta.data[i] = src.data[i];
|
||||
dta.data[i + 1] = src.data[i + 1];
|
||||
dta.data[i + 2] = src.data[i + 2];
|
||||
|
@ -2407,6 +2426,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
|
|||
blocks.push(watcherToggle('reportThreadCount'));
|
||||
blocks.push(block('reportThreadCount'));
|
||||
blocks.push(block('colorFiltered'));
|
||||
blocks.push(block('reportFuzzyTouchingColor'));
|
||||
blocks.push(block('reportFuzzyColorIsTouchingColor'));
|
||||
blocks.push(block('reportStackSize'));
|
||||
blocks.push(block('reportFrameCount'));
|
||||
}
|
||||
|
@ -7352,7 +7373,11 @@ StageMorph.prototype.clearProjectionLayer = function () {
|
|||
this.changed();
|
||||
};
|
||||
|
||||
StageMorph.prototype.colorFiltered = function (aColor, excludedSprite) {
|
||||
StageMorph.prototype.colorFiltered = function (
|
||||
aColor,
|
||||
excludedSprite,
|
||||
tolerance
|
||||
) {
|
||||
// answer a new Morph containing my image filtered by aColor
|
||||
// ignore the excludedSprite, because its collision is checked
|
||||
// ignore transparency (alpha)
|
||||
|
@ -7381,7 +7406,9 @@ StageMorph.prototype.colorFiltered = function (aColor, excludedSprite) {
|
|||
src.data[i + 1],
|
||||
src.data[i + 2]
|
||||
);
|
||||
if (clr.eq(aColor)) {
|
||||
if ((tolerance && clr.isCloseTo(aColor, false, tolerance)) ||
|
||||
clr.eq(aColor)
|
||||
) {
|
||||
dta.data[i] = src.data[i];
|
||||
dta.data[i + 1] = src.data[i + 1];
|
||||
dta.data[i + 2] = src.data[i + 2];
|
||||
|
|
|
@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
|
|||
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color,
|
||||
TableFrameMorph, ColorSlotMorph, isSnapObject, Map, newCanvas, Symbol*/
|
||||
|
||||
modules.threads = '2019-July-01';
|
||||
modules.threads = '2019-July-08';
|
||||
|
||||
var ThreadManager;
|
||||
var Process;
|
||||
|
@ -3845,7 +3845,7 @@ Process.prototype.objectTouchingObject = function (thisObj, name) {
|
|||
);
|
||||
};
|
||||
|
||||
Process.prototype.reportTouchingColor = function (aColor) {
|
||||
Process.prototype.reportTouchingColor = function (aColor, tolerance) {
|
||||
// also check for any parts (subsprites)
|
||||
var thisObj = this.blockReceiver(),
|
||||
stage;
|
||||
|
@ -3853,36 +3853,15 @@ Process.prototype.reportTouchingColor = function (aColor) {
|
|||
if (thisObj) {
|
||||
stage = thisObj.parentThatIsA(StageMorph);
|
||||
if (stage) {
|
||||
if (thisObj.isTouching(stage.colorFiltered(aColor, thisObj))) {
|
||||
if (thisObj.isTouching(
|
||||
stage.colorFiltered(aColor, thisObj, tolerance))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return thisObj.parts.some(
|
||||
function (any) {
|
||||
return any.isTouching(stage.colorFiltered(aColor, any));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Process.prototype.reportColorIsTouchingColor = function (color1, color2) {
|
||||
// also check for any parts (subsprites)
|
||||
var thisObj = this.blockReceiver(),
|
||||
stage;
|
||||
|
||||
if (thisObj) {
|
||||
stage = thisObj.parentThatIsA(StageMorph);
|
||||
if (stage) {
|
||||
if (thisObj.colorFiltered(color1).isTouching(
|
||||
stage.colorFiltered(color2, thisObj)
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
return thisObj.parts.some(
|
||||
function (any) {
|
||||
return any.colorFiltered(color1).isTouching(
|
||||
stage.colorFiltered(color2, any)
|
||||
return any.isTouching(
|
||||
stage.colorFiltered(aColor, any, tolerance)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -3891,6 +3870,41 @@ Process.prototype.reportColorIsTouchingColor = function (color1, color2) {
|
|||
return false;
|
||||
};
|
||||
|
||||
Process.prototype.reportFuzzyTouchingColor =
|
||||
Process.prototype.reportTouchingColor;
|
||||
|
||||
Process.prototype.reportColorIsTouchingColor = function (
|
||||
color1,
|
||||
color2,
|
||||
tolerance
|
||||
) {
|
||||
// also check for any parts (subsprites)
|
||||
var thisObj = this.blockReceiver(),
|
||||
stage;
|
||||
|
||||
if (thisObj) {
|
||||
stage = thisObj.parentThatIsA(StageMorph);
|
||||
if (stage) {
|
||||
if (thisObj.colorFiltered(color1, tolerance).isTouching(
|
||||
stage.colorFiltered(color2, thisObj, tolerance)
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
return thisObj.parts.some(
|
||||
function (any) {
|
||||
return any.colorFiltered(color1, tolerance).isTouching(
|
||||
stage.colorFiltered(color2, any, tolerance)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Process.prototype.reportFuzzyColorIsTouchingColor =
|
||||
Process.prototype.reportColorIsTouchingColor;
|
||||
|
||||
Process.prototype.reportAspect = function (aspect, location) {
|
||||
// sense colors and sprites anywhere,
|
||||
// use sprites to read/write data encoded in colors.
|
||||
|
|
Ładowanie…
Reference in New Issue