Skip to content

Commit

Permalink
Merge branch 'v8'
Browse files Browse the repository at this point in the history
  • Loading branch information
KaliedaRik committed Mar 11, 2021
2 parents 963f051 + 991e034 commit 373446f
Show file tree
Hide file tree
Showing 332 changed files with 17,710 additions and 6,872 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Scrawl-canvas Library
Version: `8.5.1 - 26 Feb 2021`
Version: `8.5.2 - 11 Mar 2021`

Scrawl-canvas website: [scrawl-v8.rikweb.org.uk](https://scrawl-v8.rikweb.org.uk).

Expand Down Expand Up @@ -46,7 +46,7 @@ There are three main ways to include Scrawl-canvas in your project:
2. Unzip the file to a folder in your project.
3. Import the library into the script code where you will be using it.

Alternatively, a zip package of the v8.5.1 files can be downloaded from this link: [scrawl.rikweb.org.uk/downloads/scrawl-canvas_8-5-1.zip](https://scrawl.rikweb.org.uk/downloads/scrawl-canvas_8-5-1.zip) - this package only includes the minified file.
Alternatively, a zip package of the v8.5.2 files can be downloaded from this link: [scrawl.rikweb.org.uk/downloads/scrawl-canvas_8-5-2.zip](https://scrawl.rikweb.org.uk/downloads/scrawl-canvas_8-5-2.zip) - this package only includes the minified file.

```html
<!-- Hello world -->
Expand Down Expand Up @@ -95,7 +95,7 @@ Alternatively, a zip package of the v8.5.1 files can be downloaded from this lin
This will pull the requested npm package directly into your web page:
```html
<script type="module">
import scrawl from 'https://unpkg.com/scrawl-canvas@8.5.1';
import scrawl from 'https://unpkg.com/scrawl-canvas@8.5.2';
[...]
</script>
```
Expand Down
13 changes: 8 additions & 5 deletions demo/canvas-007.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@ scrawl.makeFilter({
name: 'offsetChannels',
method: 'offsetChannels',
offsetRedX: -12,
offsetGreenY: 12,
offsetBlueX: 3,
offsetBlueY: -3,
offsetRedY: -8,
offsetGreenX: 12,
offsetGreenY: 16,
offsetBlueX: 5,
offsetBlueY: -15,
});

// __Pixellate__ filter
Expand All @@ -289,8 +291,9 @@ scrawl.makeFilter({
scrawl.makeFilter({
name: 'blur',
method: 'blur',
radius: 6,
passes: 2,
radius: 8,
passes: 1,
excludeTransparentPixels: true,
});

// __AreaAlpha__ filter
Expand Down
4 changes: 4 additions & 0 deletions demo/canvas-008.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
.controls {
grid-template-columns: 1fr 2fr 2fr 1fr 2fr 2fr;
}

img {
display: none;
}
</style>
</head>

Expand Down
2 changes: 1 addition & 1 deletion demo/canvas-019.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// # Demo Canvas 019
// Gradient and Color factories - transparency

// [Run code](../../demo/canvas-018.html)
// [Run code](../../demo/canvas-019.html)
import scrawl from '../source/scrawl.js';


Expand Down
67 changes: 67 additions & 0 deletions demo/canvas-019a.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo Canvas 019a</title>
<link href="css/normalize.css" rel="stylesheet" />
<link href="css/tests.css" rel="stylesheet" />

<style>
img {
display: none;
}
canvas {
display: block;
margin: 0 auto 1em;
border: 1px solid red;
}
.controls {
grid-template-columns: 1fr 1fr;
}
</style>
</head>

<body>
<h1><a href="index.html">Scrawl-canvas v8</a> - Canvas test 019a</h1>
<h2>Gradient and Color factories - transparency - alternative approach using Cells instead of images</h2>

<div class="controls">
<canvas id="hackney" width="400" height="400"></canvas>
<canvas id="heathrow" width="400" height="400"></canvas>
<canvas id="kingston" width="400" height="400"></canvas>
<canvas id="burglary" width="400" height="400"></canvas>
</div>

<p id="reportmessage"></p>

<div class="testinfo">
<h4>Test purpose</h4>
<ul>
<li>Use the four canvases to display a separate image, defined in the DOM.</li>
<li>Check that the `scrawl.createImageFromEntity` functionality works, and that we can capture and use blurred images created dynamically from the originals.</li>
<li>Create four (radial) gradients, each with a transparent hole in the middle. We are testing the following values for CSS transparency:</li>
<ul>
<li>"transparent"</li>
<li>"rgba(0,0,0,0)"</li>
<li>"#00000000"</li>
<li>"#0000"</li>
</ul>
<li>Check that all canvases display as expected, with in-focus areas of the image centred either on the mouse cursor, or in the middle of the canvas.</li>
</ul>
<p><b>Known issue</b>: generating the blurred images from the originals takes a very long time in some browsers (for example: Safari). once the images are generated, then the Demo should be performant across all browsers.</p>
<p><a href="../docs/demo/canvas-019a.html">Annotated code</a></p>
</div>

<img id="hackney-bg" src="img/hackney-grey.jpg" class="places" />
<img id="heathrow-bg" src="img/heathrow-grey.jpg" class="places" />
<img id="kingston-bg" src="img/kingston-grey.jpg" class="places" />
<img id="burglary-bg" src="img/burglary-grey.jpg" class="places" />

<script src="canvas-019a.js" type="module"></script>

</body>

</html>
190 changes: 190 additions & 0 deletions demo/canvas-019a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// # Demo Canvas 019a
// Gradient and Color factories - transparency - alternative approach using Cells instead of images

// [Run code](../../demo/canvas-019a.html)
import scrawl from '../source/scrawl.js';


// #### Scene setup
const canvases = scrawl.library.canvas;

// Import the images we defined in the DOM (in &lt;img> elements)
scrawl.importDomImage('.places');

// For this scene, we'll build a data structure which we can iterate over, to build the entitys, assets and gradients required by the scene
const data = [
{
canvas: canvases['hackney'],
image: 'hackney-bg',
transparency: 'transparent',
},
{
canvas: canvases['heathrow'],
image: 'heathrow-bg',
transparency: 'rgba(0,0,0,0)',
},
{
canvas: canvases['kingston'],
image: 'kingston-bg',
transparency: '#00000000',
},
{
canvas: canvases['burglary'],
image: 'burglary-bg',
transparency: '#0000',
},
];

// This array will hold a set of functions which we will invoke in turn at the start of each Display cycle
const checkFunctions = [];

// The blur filter is temporary - we use it once on each image to generate a blurred version of that image
// + We do it this way because the blur filter is computationally very expensive - capturing a blurred version of the image is a lot better for end user power consumption
scrawl.makeFilter({
name: 'blur',
method: 'blur',
radius: 20,
passes: 2,
});

// Iterate through our data array to create Scrawl-canvas objects
data.forEach(scene => {

// Firstly, build the blurred image in its own cell
// + We only need to compile this once, thus don't include the cell in any part of the Display cycle
let mycell = scene.canvas.buildCell({

name: `${scene.image}-blurred-cell`,
dimensions: ['100%', '100%'],
cleared: false,
compiled: false,
shown: false,
});

scrawl.makePicture({

name: `${scene.image}-blurred-image`,
group: `${scene.image}-blurred-cell`,

asset: `${scene.image}`,

dimensions: ['100%', '100%'],
copyDimensions: ['100%', '100%'],

filters: ['blur'],
method: 'fill',
});

// The new Cell's compile action is blocking, because the blur filter takes a long time to complete. To get something up on the screen we can defer the compile action until after the current RAF completes by putting it in a setTimeout invocation.
setTimeout(() => mycell.compile(), 0);


// Next, build a gradient using transparency and apply it in a second Block which displays in the original canvas
scrawl.makeRadialGradient({

name: `${scene.image}-gradient`,
start: ['50%', '50%'],
end: ['50%', '50%'],
startRadius: '5%',
endRadius: '20%',
})
.updateColor(0, `${scene.transparency}`)
.updateColor(999, 'lightgray');

const gradientBlock = scrawl.makeBlock({

name: `${scene.image}-gradient-block`,
group: `${scene.canvas.base.name}`,

start: ['center', 'center'],
handle: ['center', 'center'],
dimensions: ['200%', '200%'],

fillStyle: `${scene.image}-gradient`,
lockFillStyleToEntity: true,
});

// Now we can draw our blurred image into the scene
// + We use some compositing magic so it only appears where the gradient is not transparent
scrawl.makePicture({

name: `${scene.image}-blurred-block`,
group: scene.canvas.base.name,

asset: `${scene.image}-blurred-cell`,

dimensions: ['100%', '100%'],
copyDimensions: ['100%', '100%'],

method: 'fill',
globalCompositeOperation: 'source-atop',
});

// Lastly, display the original image in the canvas
// + Again, we use compositing magic to draw on the bits missed by the blurred image
scrawl.makePicture({

name: `${scene.image}-original-image`,
group: scene.canvas.base.name,

asset: `${scene.image}`,

dimensions: ['100%', '100%'],
copyDimensions: ['100%', '100%'],

method: 'fill',
globalCompositeOperation: 'destination-over',
});

// Check whether the mouse cursor is hovering over this canvas, and update the filter Block entity's positioning accordingly
const f = () => {

const here = scene.canvas.here;

return function () {

gradientBlock.set({
lockTo: (here.active) ? 'mouse' : 'start',
});
}
};
checkFunctions.push(f());
});

// #### Scene animation
// Function to display frames-per-second data, and other information relevant to the demo
let report = function () {

let testTicker = Date.now(),
testTime, testNow, dragging,
testMessage = document.querySelector('#reportmessage');

return function () {

testNow = Date.now();

// Because we are using the same render object to animate all four canvases, this report function gets run four times for each Display cycle (once each time each canvas is rendered). The fix is to choke the functionality so it actions only after a given number of milliseconds since it was last run - typically 2 milliseconds is enough to ensure the action only runs once per cycle.
if (testNow - testTicker > 2) {

testTime = testNow - testTicker;
testTicker = testNow;

testMessage.textContent = `Screen refresh: ${Math.ceil(testTime)}ms; fps: ${Math.floor(1000 / testTime)}`;
}
};
}();


// Create the Display cycle animation
scrawl.makeRender({

name: 'demo-animation',
target: [canvases['hackney'], canvases['heathrow'], canvases['kingston'], canvases['burglary']],

commence: () => checkFunctions.forEach(f => f()),
afterShow: report,
});


// #### Development and testing
console.log(scrawl.library);
1 change: 1 addition & 0 deletions demo/canvas-029.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ scrawl.makePhrase({
text: 'Lorem ipsum har varit standard ända sedan 1500-talet, när-en-okänd-boksättare-tog att antal bokstäver och blandade dem för att göra ett provexemplar av en bok.',

font: '18px Garamond, serif',
lineHeight: 1,

width: '35%',

Expand Down
27 changes: 16 additions & 11 deletions demo/canvas-040.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import scrawl from '../source/scrawl.js';
// #### Scene setup
const canvas = scrawl.library.canvas.mycanvas;

const balancePoint = 2500;

canvas.setBase({
backgroundColor: 'aliceblue',
});
Expand Down Expand Up @@ -34,8 +36,8 @@ const arrow = scrawl.makeShape({

// We create this effect using a dashed line with very large dash/nodash values
// + We can then set the offset to the point where the displayed dash ends, so it looks like the arrow doesn't have a stroke
lineDash: [10000, 10000],
lineDashOffset: 10000,
lineDash: [balancePoint, balancePoint],
lineDashOffset: balancePoint,

// To retrieve the Shape's length, we need to tell it that it is being used as a path
useAsPath: true,
Expand Down Expand Up @@ -390,17 +392,20 @@ const myWorld = scrawl.makeWorld({

this.progress = item;

arrow.set({
lineDashOffset: 10000 - Math.round(arrow.length * (item / 100)),
});
if (arrow.length != null) {

arrow.set({
lineDashOffset: balancePoint - Math.round(arrow.length * (item / 100)),
});

// The japanb entity has several paths, all of them shorter than the arrow entity's path
// + Most of the paths (around small islands) will be shown relatively quickly - a quirk of using a dashed line to show the tracing effect
japan.set({
lineDashOffset: 10000 - Math.round(japan.length * (item / 270)),
});
// The japan entity has several paths, all of them shorter than the arrow entity's path
// + Most of the paths (around small islands) will be shown relatively quickly - a quirk of using a dashed line to show the tracing effect
japan.set({
lineDashOffset: balancePoint - Math.round(japan.length * (item / 270)),
});

progressElement.value = item;
progressElement.value = item;
}
},
}
],
Expand Down
Loading

0 comments on commit 373446f

Please sign in to comment.