Light Table
A table of generated photographs with a magnifier that follows the pointer. Drag pictures to stack them.
What you are seeing
Sixteen tilted photographs with white borders lie on a dark table: mountains, sea, stones, forest, clouds, dunes, night sky, farmland, aurora and a harbor. The picture nearest the pointer grows and straightens while its neighbors slide aside.
How it works
A newly written SVG document provides the table, the grid bounds, the page controls and the script loading order. The original CC0 scripts do the rest.
Each picture is an SVG image inside nested groups for position, scale and rotation.
A magnifier function pushes nearby pictures outward and enlarges those closest to the pointer.
Pictures drop in with an elastic YUI animation, staggered so a page settles in about three seconds.
The restored version adds dragging, and a dragged picture stays on top of the stack.
History
Posted on October 4, 2009. It originally drew its pictures from a live photo sharing service. The original SVG document carried a reserved-rights notice, so it is not republished. A new document was written to host the CC0 scripts.
Source
/photoAlbum/light-table.svg
<!-- Written for the SVG Wow! reconstruction. Independent of the original file at this path. -->
<?xml-stylesheet type="text/css" href="../res/2.0/style/wowNeutral.css" ?>
<?xml-stylesheet type="text/css" href="light-table.css" ?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="100%" height="100%" viewBox="0 0 800 600"
style="background:#181818"
onload="lightTableBoot();">
<title>Light Table</title>
<desc>Sixteen tilted photographs generated for this site lie on a dark table. The picture nearest the pointer grows and straightens while its neighbors slide aside. Pictures can be dragged and stacked, and prev and next deal a new page.</desc>
<style type="text/css"><![CDATA[
.button:focus { outline: none; }
.button:focus-visible rect { stroke: #f7ab15; stroke-width: 2; }
.button:hover rect { stroke: #bbbbbb; }
]]></style>
<script xlink:href="../res/2.0/scripts/compat/no-unload.js" />
<script xlink:href="../res/2.0/scripts/yui/yahoo-dom-event/yahoo-dom-event.js" />
<script xlink:href="../res/2.0/scripts/yui/animation/animation-min.js" />
<script xlink:href="../res/2.0/scripts/dom-utils.js" />
<script xlink:href="compat.js" />
<script xlink:href="../res/2.0/scripts/tools/magnifier.js" />
<script xlink:href="../res/2.0/scripts/utils/ez-transform.js" />
<script xlink:href="../res/2.0/scripts/animation/animate.js" />
<script xlink:href="thumbnail.js" />
<script xlink:href="sources/photo-source.js" />
<script xlink:href="sources/local-photo-source.js" />
<script xlink:href="light-table.js" />
<script xlink:href="light-table-app.js" />
<script><![CDATA[
function lightTableBoot() {
var root = document.documentElement;
// Tall screens get a narrower table so the 4 by 4 grid stays large.
if (window.innerWidth / window.innerHeight < 0.95) {
root.setAttribute('viewBox', '0 0 460 548');
var bounds = document.getElementById('gridBounds');
bounds.setAttribute('x', 14);
bounds.setAttribute('y', 24);
bounds.setAttribute('width', 432);
bounds.setAttribute('height', 432);
document.getElementById('tableFooter').setAttribute('transform', 'translate(0,484)');
document.getElementById('tableCredit').setAttribute('transform', 'translate(450,0)');
}
sw.photoAlbum.init();
// The prev and next groups also respond to Enter and Space.
['prevPageButton', 'nextPageButton'].forEach(function (id) {
var button = document.getElementById(id);
button.addEventListener('keydown', function (evt) {
if (evt.key === 'Enter' || evt.key === ' ') {
evt.preventDefault();
button.dispatchEvent(new MouseEvent('click', {bubbles: true}));
}
});
});
}
]]></script>
<defs>
<clipPath id="viewportClip">
<rect x="-2000" y="-2000" width="4800" height="4600" />
</clipPath>
</defs>
<g id="content" clip-path="url(#viewportClip)">
<rect id="background" x="-2000" y="-2000" width="4800" height="4600" />
<rect id="gridBounds" x="140" y="22" width="520" height="520" fill="none" stroke="none" pointer-events="none" />
<g id="gridContainer"></g>
<g id="tableFooter" transform="translate(0,548)">
<g id="prevPageButton" class="button" display="none" tabindex="0" role="button" aria-label="Previous page">
<rect x="12" y="0" width="64" height="40" rx="5" style="fill:#2a2a2a;fill-opacity:1;stroke:#555555" />
<text x="44" y="25" style="font-size:15px">prev</text>
</g>
<g id="nextPageButton" class="button" display="none" tabindex="0" role="button" aria-label="Next page">
<rect x="84" y="0" width="64" height="40" rx="5" style="fill:#2a2a2a;fill-opacity:1;stroke:#555555" />
<text x="116" y="25" style="font-size:15px">next</text>
</g>
<text id="pageCount" x="164" y="25" style="font-size:15px" aria-live="polite"></text>
<g id="tableCredit" transform="translate(790,0)">
<text class="credits" x="-30" y="25" style="font-size:12px">original generated pictures</text>
<!-- A small lit table with three prints on it. -->
<g id="g2403" transform="translate(-24,10)" aria-hidden="true">
<g id="g2405">
<path id="path2407" d="M1 12 L4 3 H20 L23 12 Z" fill="#3c3a34" stroke="#8f8a7c" stroke-width="1" />
<rect id="rect2409" x="6" y="5" width="3.6" height="3" fill="#f3e4b8" />
<rect id="rect2411" x="10.6" y="5" width="3.6" height="3" fill="#f7ab15" />
<rect id="rect2413" x="15" y="5" width="3.6" height="3" fill="#f3e4b8" />
<path id="path2415" d="M4 15 V12 M20 15 V12" stroke="#8f8a7c" stroke-width="1.4" fill="none" />
<polygon id="polygon2417" points="12,-3 13.2,0 10.8,0" fill="#f7ab15" />
<path id="path2419" d="M8 1 L10 2 M16 1 L14 2" stroke="#f3e4b8" stroke-width="0.8" fill="none" />
</g>
</g>
</g>
</g>
</g>
<!-- Slide navigation from the site's presentation mode. The shared stylesheet keeps it hidden. -->
<g id="presentationNavigation">
<g id="prevButton"><path d="M16 300 l12 -10 v20 z" fill="#888888" /></g>
<g id="nextButton"><path d="M784 300 l-12 -10 v20 z" fill="#888888" /></g>
</g>
</svg>
/photoAlbum/light-table.js
/** =======================================================================
* Vincent Hardy
* License terms: see svg-wow.org
* CC0 http://creativecommons.org/publicdomain/zero/1.0/
* ======================================================================= */
sw.photoAlbum = sw.photoAlbum || {};
yui = YAHOO;
/**
* The light table displays the images from its photo source in a grid over
* which a magnifier can be moved.
*
* @param p_photoSource the pictures and thumbnail source
* @param p_gridContainer id or element into which the thumbnails are created
* @param p_gridBounds the bounds of the grid.
* @param p_magnifier the light table's magnifier: used to scale thumbnails
* up.
* @param p_nextPage the id or element for the next page button
* @param p_prevPage the id or element for the prev page button
* @param p_pageCount the id or element for the page count text
* @param p_oConfig optional parameters:
* {
* padding: Number (defaults to 0)
* }
*/
sw.photoAlbum.LightTable = function (p_photoSource,
p_gridContainer,
p_gridBounds,
p_magnifier,
p_nextPage,
p_prevPage,
p_pageCount,
p_oConfig) {
var photoSource = p_photoSource;
var gridContainer = sw.stringToElement(p_gridContainer);
var gridBounds = sw.stringToElement(p_gridBounds);
var nextPage = sw.stringToElement(p_nextPage);
var prevPage = sw.stringToElement(p_prevPage);
var pageCountText = sw.stringToElement(p_pageCount);
var magnifier = p_magnifier;
var config = {
padding: 10
};
var pageIndex = -1;
var pageSize = -1;
var thumbnails = [];
var pictures = [];
var thumbnailsPositions = [];
var lastThumbnailReady; // the last loaded thumbnail
var pageCount = -1;
var pageLoaded = false;
var dragged = null;
var dragOffset = {x: 0, y: 0};
var focusIndex = -1;
var reducedMotion = window.matchMedia &&
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (p_oConfig !== undefined) {
if (typeof p_oConfig.padding === "number") {
config.padding = p_oConfig.padding;
}
}
photoSource.events.pageCountRetrieved.subscribe(onPageCountRetrieved);
photoSource.events.pageRetrieved.subscribe(onPageRetrieved);
photoSource.retrievePageCount();
magnifier.events.onChange.subscribe(onMagnifierChange);
yui.util.Event.addListener(nextPage, "click", onNextPage);
yui.util.Event.addListener(prevPage, "click", onPrevPage);
// Dragging a picture moves it and leaves it on top of the stack.
gridContainer.addEventListener("pointerdown", onDragStart, false);
document.documentElement.addEventListener("pointermove", onDragMove, false);
document.documentElement.addEventListener("pointerup", onDragEnd, false);
document.documentElement.addEventListener("pointercancel", onDragEnd, false);
this.nextPage = function () { if (pageLoaded) { onNextPage(); } };
this.prevPage = function () { if (pageLoaded) { onPrevPage(); } };
this.isReady = function () { return pageLoaded; };
this.getPageIndex = function () { return pageIndex; };
this.getThumbnails = function () { return thumbnails; };
/**
* Moves the magnifier onto the picture p_delta places from the current one.
*/
this.focusRelative = function (p_delta) {
if (pageLoaded && thumbnails.length > 0) {
focusIndex = (focusIndex + p_delta + thumbnails.length) %
thumbnails.length;
var e = thumbnails[focusIndex].element;
magnifier.setPosition(e.tx, e.ty);
}
};
function toGridPoint (p_evt) {
var m = gridContainer.getScreenCTM().inverse();
return {
x: m.a * p_evt.clientX + m.c * p_evt.clientY + m.e,
y: m.b * p_evt.clientX + m.d * p_evt.clientY + m.f
};
}
function onDragStart (p_evt) {
var t = p_evt.target.thumbnail;
if (t === undefined || pageLoaded !== true) {
return;
}
p_evt.preventDefault();
var pt = toGridPoint(p_evt);
dragged = t;
dragOffset.x = t.element.tx - pt.x;
dragOffset.y = t.element.ty - pt.y;
gridContainer.appendChild(t.element);
t.rotate(0);
t.scale(t.originalScale * 1.6);
t.moveTo(t.element.tx, t.element.ty);
}
function onDragMove (p_evt) {
if (dragged !== null) {
var pt = toGridPoint(p_evt);
dragged.element.tx = pt.x + dragOffset.x;
dragged.element.ty = pt.y + dragOffset.y;
dragged.moveTo(dragged.element.tx, dragged.element.ty);
}
}
function onDragEnd () {
if (dragged !== null) {
dragged = null;
onMagnifierChange();
}
}
/**
* Handles next page request
*/
function onNextPage () {
pageLoaded = false;
setNextPrevState(false);
var newPageIndex = pageIndex + 1;
if (newPageIndex >= pageCount) {
newPageIndex = 0;
}
if (thumbnails.length > 0) {
thumbnails[0].animOut.animate();
}
var getPage = function () {
pageLoaded = false;
photoSource.retrievePage(newPageIndex);
}
setTimeout(getPage, 1000);
}
/**
* Handles prev page request
*/
function onPrevPage () {
pageLoaded = false;
setNextPrevState(false);
var newPageIndex = pageIndex - 1;
if (newPageIndex < 0) {
newPageIndex = pageCount - 1;
}
if (thumbnails.length > 0) {
thumbnails[0].animOut.animate();
}
var getPage = function () {
pageLoaded = false;
photoSource.retrievePage(newPageIndex);
}
setTimeout(getPage, 1000);
}
/**
* Sets the state of the next and previous controls.
*/
function setNextPrevState (p_enabled) {
var display = "inline";
if (p_enabled === false) {
display = "none";
}
nextPage.setAttribute("display", display);
prevPage.setAttribute('display', display);
}
/**
* Handles magnification events.
*/
function onMagnifierChange () {
// Apply the magnifier to all the existing thumbnails
var n = thumbnails.length;
var t;
var result = {};
var highlight;
var maxMag = 0;
var opacity = 1;
if (pageLoaded === true) {
for (var i = 0; i < n; i++) {
t = thumbnails[i];
if (t === dragged) {
continue;
}
magnifier.processPoint(t.element.tx, t.element.ty, result);
t.moveTo(result.x, result.y);
t.scale(t.originalScale * result.magnification);
t.rotate(t.originalRotation * Math.sqrt(result.p));
if (!t.fade.isAnimated() && !t.animIn.isAnimated()) {
opacity = 0.35 + 0.65 * (1-result.p);
// t.element.style.opacity = opacity;
}
if (result.magnification > maxMag) {
highlight = t;
maxMag = result.magnification;
}
}
if (highlight !== undefined && dragged === null &&
maxMag > magnifier.minMagnification &&
gridContainer.lastChild !== highlight.element) {
// Move to the top.
gridContainer.appendChild(highlight.element);
}
}
}
/**
* Called when the photoShource has computed its page count.
* We simply retrieve the first page.
*/
function onPageCountRetrieved (type, args) {
if (args[0].count >= 1) {
pageCount = args[0].count;
photoSource.retrievePage(0);
} else {
alert("There are no pictures in the photo source");
}
}
/**
* Updates the current page counter
*/
function updatePageCount () {
pageCountText.removeAllChildren();
pageCountText.appendChild(
document.createTextNode((pageIndex + 1) + " / " + pageCount));
}
/**
* Called when the photoSource has retrieved the list of pictures for a
* given page.
*/
function onPageRetrieved (type, args) {
var result = args[0];
var thumbnail;
var url;
var gridBBox = gridBounds.getBBox();
var minY = gridBBox.y - gridBounds.getViewportBBox().y;
var maxY = gridBBox.y + gridBBox.height +
gridBounds.getViewportBBox().y;
var w = gridBBox.width;
var h = gridBBox.height;
var p = config.padding;
var x = gridBBox.x;
var y = gridBBox.y;
var cw; // content width
var ch; // content height
var dw;
var dh;
var r;
var c;
var s;
var n;
var pi;
var pos;
var nPos;
if (result.size >= 1) {
pageIndex = result.index;
pageSize = result.size;
focusIndex = -1;
updatePageCount();
// Empty the current thumbnailsContent children.
thumbnails = [];
pictures = [];
thumbnailsPositions = [];
// Recompute the thumbnails positions based on the grid bounds
// and padding. We also derive the thumbnail size.
// Ideally, we would like the number of rows times the number
// of colums to be exactly the number of page items.
n = result.size;
c = Math.floor(Math.sqrt(n * w / h));
r = Math.floor(n / c);
s = (w - p * (c - 1)) / c;
cw = c * s + (c - 1) * p;
ch = r * s + (r - 1) * p;
dw = w - cw;
dh = h - ch;
nPos = c * r;
minY -= s;
maxY += s;
for (var ri = 0; ri < r; ri++) {
for (var ci = 0; ci < c; ci++) {
thumbnailsPositions.push({
x: dw / 2 + x + s / 2 + ci * (p + s),
y: dh / 2 + y + s / 2 + ri * (p + s)
});
}
}
for (var i = 0; i < result.size; i++) {
url = photoSource.getThumbnailURL(result.index, i);
thumbnail = new sw.photoAlbum.Thumbnail(url);
thumbnail.s = s;
thumbnail.photoIndex = i;
nPos = thumbnailsPositions.length - 1;
if (nPos >= 0) {
thumbnail.events.onReady.subscribe(onThumbnailReady);
thumbnail.initThumbnail();
pi = Math.round(nPos * Math.random());
pos = thumbnailsPositions[pi];
thumbnailsPositions.splice(pi, 1);
thumbnail.pos = pos;
thumbnail.element.tx = pos.x;
thumbnail.element.ty = minY;
// thumbnail.element.style.opacity = 0.35;
thumbnail.animIn =
new sw.animation.Animate(thumbnail.element,
{
txf: {
from: {ty: minY, r: -40},
to: {ty: pos.y, r: 0},
template: "translate(" + pos.x + ",#ty),rotate(#r)"
}/*,
ty: {
from: minY,
to: pos.y
},
r: {
from: -40,
to: 0
}*/
},
2,
yui.util.Easing.elasticOut,
"translate(" + pos.x + ",#ty),rotate(#r)"
);
thumbnail.fade =
new sw.animation.Animate(thumbnail.element,
{
opacity: {
from: 1,
to: 1 // 0.35
}
});
thumbnail.animIn.onEnd(thumbnail.fade);
thumbnail.animOut =
new sw.animation.Animate(thumbnail.element,
{
txf: {
from: {ty: pos.y},
to: {ty: maxY},
template: "translate(" + pos.x + ",#ty)"
}
},
0.5 + 0.5 * Math.random(),
yui.util.Easing.backIn,
"translate(" + pos.x + ",#ty)"
);
thumbnail.animOut.onComplete.subscribe(
getCompleteHandler(thumbnail));
} else {
// Else, there is no space left, the picture is left out.
// Arguable strategy, I know, I know... :-)
pageSize--;
}
}
} else {
alert("There are no pictures in page " + result.index);
}
}
/**
* Called when all the page thumbnails have been loaded
*/
function onPageThumbnailsLoaded () {
setNextPrevState(true);
pageLoaded = true;
}
/**
* Handles a new thumbnail when it becomes ready
*/
function onThumbnailReady (type, args) {
var evt = args[0];
var thumbnail = evt.thumbnail;
var prev;
var r = 2 * (Math.random() - 0.5);
gridContainer.appendChild(thumbnail.element);
thumbnail.anchor();
var bbox = thumbnail.element.getBBox();
var scaleX = thumbnail.s / bbox.width;
var scaleY = thumbnail.s / bbox.height;
var scale = scaleX;
if (scaleY < scaleX) {
scale = scaleY;
}
thumbnail.originalScale = scale;
thumbnail.scale(scale);
thumbnail.moveTo(thumbnail.pos.x, -300);
thumbnail.originalRotation = r * 30;
thumbnail.rotate(thumbnail.originalRotation);
thumbnails.push(thumbnail);
// The original chained each 2s drop after the previous one, which
// was hidden by network latency. With local files, stagger instead.
if (reducedMotion) {
thumbnail.element.tx = thumbnail.pos.x;
thumbnail.element.ty = thumbnail.pos.y;
thumbnail.moveTo(thumbnail.pos.x, thumbnail.pos.y);
} else {
setTimeout(thumbnail.animIn.getStartHandler(),
(thumbnails.length - 1) * 80);
}
// Have all the thumbnails out animation start at the same time
if (thumbnail !== thumbnails[0]) {
thumbnails[0].animOut.onBegin(thumbnail.animOut);
}
lastThumbnailReady = thumbnail;
if (thumbnails.length === pageSize) {
// We loaded all the thumbnails.
if (reducedMotion) {
onPageThumbnailsLoaded();
} else {
thumbnail.animIn.onEnd(onPageThumbnailsLoaded);
}
}
}
/**
* Gets the complet hander for the given thumbnail.
*
* @param p_thumbnail
*/
function getCompleteHandler (p_thumbnail) {
return function () {
gridContainer.removeChild(p_thumbnail.element);
}
}
};/photoAlbum/light-table-app.js
/**
* The app script puts the pieces together and assembles the different
* objects.
*/
sw.photoAlbum = sw.photoAlbum || {};
yui = YAHOO;
sw.photoAlbum.init = function () {
// Boiler plate demo initialization
sw.init();
var photoSource = new sw.photoAlbum.LocalPhotoSource({pageSize: 16});
var magnifier = new sw.tools.Magnifier(150, -1000, -1000, 3, 1);
var gridContainer = document.getElementById("gridContainer");
magnifier.direction = magnifier.DIRECTION_BOTH;
// Pointer events also cover touch input. getScreenCTM replaces getCTM,
// which does not map client coordinates through nested svg elements.
document.documentElement.addEventListener("pointermove", function (evt) {
var matrix = gridContainer.getScreenCTM().inverse();
var cx = evt.clientX;
var cy = evt.clientY;
magnifier.setPosition(matrix.a * cx + matrix.c * cy + matrix.e,
matrix.b * cx + matrix.d * cy + matrix.f);
}, false);
var lightTable = sw.photoAlbum.lightTable = new sw.photoAlbum.LightTable(photoSource,
"gridContainer",
"gridBounds",
magnifier,
"nextPageButton",
"prevPageButton",
"pageCount",
{padding: 0});
// The wheel and the + and - keys change the magnifier strength.
function zoomBy (p_delta) {
magnifier.maxMagnification =
Math.max(1.5, Math.min(5, magnifier.maxMagnification + p_delta));
magnifier.setPosition(magnifier.x, magnifier.y);
}
document.documentElement.addEventListener("wheel", function (evt) {
evt.preventDefault();
zoomBy(evt.deltaY < 0 ? 0.25 : -0.25);
}, {passive: false});
// Keyboard: left and right step through the pictures, page up and page
// down change page, + and - zoom.
document.addEventListener("keydown", function (evt) {
switch (evt.key) {
case "ArrowRight": lightTable.focusRelative(1); break;
case "ArrowLeft": lightTable.focusRelative(-1); break;
case "PageDown": case "n": lightTable.nextPage(); break;
case "PageUp": case "p": lightTable.prevPage(); break;
case "+": case "=": zoomBy(0.25); break;
case "-": zoomBy(-0.25); break;
default: return;
}
evt.preventDefault();
}, false);
}/photoAlbum/light-table.css
#background {
fill: #222;
}
#content {
font-family: Didot, Georgia, serif;
text-align:center;
}
.thumbnailFrame {
stroke-width: 4;
stroke: white;
fill: none;
}
.thumbnailsPaneBorder {
stroke: white;
shape-rendering: crispEdges;
}
.thumbnailShadow {
stroke: black;
stroke-width: 3;
fill: black;
/* filter: url(album.svg#dropShadow);*/
}
#pictureShadow {
/* filter: url(album.svg#dropShadow);*/
}
.button text {
fill: white;
font-family: 'Myriad Pro', 'Helvetica Neue', Arial, sans-serif;
font-size: 10px;
text-anchor: middle;
}
#gridContainer {
touch-action: none;
cursor: grab;
}
.button rect {
fill: red;
fill-opacity: 0;
cursor: pointer;
stroke: none;
}
.credits {
fill: white;
fill-opacity: 0.6;
font-family: 'Myriad Pro', 'Helvetica Neue', Arial, sans-serif;
font-size: 10px;
text-anchor: end;
}
#pageCount {
fill: white;
font-family: 'Myriad Pro', 'Helvetica Neue', Arial, sans-serif;
font-size: 10px;
}/photoAlbum/thumbnail.js
/** =======================================================================
* Vincent Hardy
* License terms: see svg-wow.org
* CC0 http://creativecommons.org/publicdomain/zero/1.0/
* ======================================================================= */
sw.photoAlbum = sw.photoAlbum || {};
yui = YAHOO;
/**
* This class is used to load and provide effects on thumbnails images.
*/
/**
* Constructor
*
* @param p_thumbURL the url for the thumbnail image
* @param p_oImageURL optional the url for the corresponding image
*/
sw.photoAlbum.Thumbnail = function (p_thumbURL, p_oImageURL) {
this.thumbURL = p_thumbURL;
this.imageURL = p_oImageURL;
this.events = {};
this.events.onReady = new YAHOO.util.CustomEvent(this.THUMBNAIL_READY);
sw.photoAlbum.Thumbnail.superclass.constructor.call(this, null);
};
yui.lang.extend(sw.photoAlbum.Thumbnail, sw.utils.EZTransform, {
// =============================================================================
// Constants
// =============================================================================
MAX_THUMB_ROTATION: 35,
MIN_THUMB_ROTATION: 10,
THUMBNAIL_READY: "THUMBNAIL_READY",
/**
* Initializes thumbnail by initiating the image download.
*/
initThumbnail : function () {
this.thumbImage = new Image();
this.scaleFactor = 1;
this.rotation = 0;
this.x = 0;
this.y = 0;
var that = this;
this.thumbImage.onload = function (evt) {
that.buildThumbContent();
that.events.onReady.fire({
thumbnail: that,
width: that.thumbImage.width,
height: that.thumbImage.height
});
}
// A picture that fails to load must not leave a page unfinished.
this.thumbImage.onerror = function () {
that.thumbImage.onerror = null;
that.thumbImage.src = "load-error-image.png";
};
this.thumbImage.src = this.thumbURL;
},
/**
* Builds the graphical content for this thumbnail
*/
buildThumbContent : function () {
var thumbImage = this.thumbImage;
var w = thumbImage.width;
var h = thumbImage.height;
var c;
var thumbnailInsert = sw.loadContent.call(null,
{
tag: "g",
children: [
{
tag: "rect",
"class": "thumbnailShadow",
width: thumbImage.width,
height: thumbImage.height
},
{
tag: "image",
"xlink:href": thumbImage.src,
width: thumbImage.width,
height: thumbImage.height,
id: "thumb_" + this.pictureName
},
{
tag: "rect",
width: thumbImage.width,
height: thumbImage.height,
"class": "thumbnailFrame"
}
]
}
);
// Add a 'thumbnail' reference to all the content elements, so that
// it can be used on events triggered by these elements.
thumbnailInsert.thumbnail = this;
c = thumbnailInsert.firstChild;
while (c !== null) {
c.thumbnail = this;
c = c.nextSibling;
}
this.setWrapped(thumbnailInsert);
}
});
/photoAlbum/compat.js
/**
* Small compatibility layer for the 2009 demo code, loaded after dom-utils.js.
* - getTransformToElement was removed from browsers.
* - SVGMatrix.transformPoint now returns a new point in some engines, so the
* viewport bounding box is computed here without relying on it.
* Released under CC0, like the demos that use it.
*/
(function () {
var proto = (window.SVGGraphicsElement || window.SVGElement).prototype;
if (!proto.getTransformToElement) {
proto.getTransformToElement = function (target) {
return target.getScreenCTM().inverse().multiply(this.getScreenCTM());
};
}
sw.getViewportBBox = function () {
var b = this.getBBox();
var viewport = this.nearestViewportElement || this.ownerSVGElement;
var m = viewport.getScreenCTM().inverse().multiply(this.getScreenCTM());
var xs = [], ys = [];
[[b.x, b.y], [b.x + b.width, b.y], [b.x, b.y + b.height],
[b.x + b.width, b.y + b.height]].forEach(function (p) {
xs.push(m.a * p[0] + m.c * p[1] + m.e);
ys.push(m.b * p[0] + m.d * p[1] + m.f);
});
var minX = Math.min.apply(null, xs), minY = Math.min.apply(null, ys);
return {
x: minX,
y: minY,
width: Math.max.apply(null, xs) - minX,
height: Math.max.apply(null, ys) - minY
};
};
})();
/photoAlbum/sources/photo-source.js
/** =======================================================================
* Vincent Hardy
* License terms: see svg-wow.org
* CC0 http://creativecommons.org/publicdomain/zero/1.0/
* ======================================================================= */
sw.photoAlbum = sw.photoAlbum || {};
yui = YAHOO;
/**
* Base class for photo sources. Implementations need to implement the
* appropriate "XYZImpl" methods.
*/
sw.photoAlbum.PhotoSource = function () {
this.events = {
pageCountRetrieved :
new yui.util.CustomEvent(this.PAGE_COUNT_RETRIEVED),
pageRetrieved :
new yui.util.CustomEvent(this.PAGE_RETRIEVED)
};
}
sw.photoAlbum.PhotoSource.prototype = {
/**
* Refer back to the constructor
*/
constructor: sw.photoAlbum.PhotoSource,
/**
* Request the retrieval of the page count.
*/
retrievePageCount : function () {
throw new Error("Should be implemented by concrete implementations");
},
/**
* Request the retrieval of the first page
*
* @param pageIndex the index of the page to retrieve.
*/
retrievePage : function (pageIndex) {
throw new Error("Should be implemented by concrete implementations");
},
/**
* Request the thumbnail url for the given page and index
*
* @param pageIndex
* @param photoIndex
*/
getThumbnailURL : function (pageIndex, photoIndex) {
throw new Error("Should be implemented by concrete implementations");
},
/**
* Request the image for the given page and index
*
* @param pageIndex
* @param photoIndex
*/
getPictureURL : function (pageIndex, photoIndex) {
throw new Error("Should be implemented by concrete implementations");
},
// Constants
PAGE_COUNT_RETRIEVED : "PAGE_COUNT_RETRIEVED",
PAGE_RETRIEVED : "PAGE_RETRIEVED"
};
/photoAlbum/sources/local-photo-source.js
/**
* Local photo source for the Photo Album and Light Table demos.
*
* It replaces the original remote source. All pictures are original and were
* computed by generate-photographs.js, so the demos make no remote requests.
* Released under CC0, like the demos that use it.
*/
sw.photoAlbum = sw.photoAlbum || {};
yui = YAHOO;
sw.photoAlbum.generatedPhotos = [{"name":"photo-01","title":"Ridges 1"},
{"name":"photo-02","title":"Open water 1"},
{"name":"photo-03","title":"River stones 1"},
{"name":"photo-04","title":"Fog in the pines 1"},
{"name":"photo-05","title":"Cloud bank 1"},
{"name":"photo-06","title":"Still lake 1"},
{"name":"photo-07","title":"Dunes 1"},
{"name":"photo-08","title":"Garden light 1"},
{"name":"photo-09","title":"Night sky 1"},
{"name":"photo-10","title":"Farmland 1"},
{"name":"photo-11","title":"Aurora 1"},
{"name":"photo-12","title":"Harbor city 1"},
{"name":"photo-13","title":"Ridges 2"},
{"name":"photo-14","title":"Open water 2"},
{"name":"photo-15","title":"River stones 2"},
{"name":"photo-16","title":"Fog in the pines 2"},
{"name":"photo-17","title":"Cloud bank 2"},
{"name":"photo-18","title":"Still lake 2"},
{"name":"photo-19","title":"Dunes 2"},
{"name":"photo-20","title":"Garden light 2"},
{"name":"photo-21","title":"Night sky 2"},
{"name":"photo-22","title":"Farmland 2"},
{"name":"photo-23","title":"Aurora 2"},
{"name":"photo-24","title":"Harbor city 2"},
{"name":"photo-25","title":"Ridges 3"},
{"name":"photo-26","title":"Open water 3"},
{"name":"photo-27","title":"River stones 3"},
{"name":"photo-28","title":"Fog in the pines 3"},
{"name":"photo-29","title":"Cloud bank 3"},
{"name":"photo-30","title":"Still lake 3"},
{"name":"photo-31","title":"Dunes 3"},
{"name":"photo-32","title":"Garden light 3"},
{"name":"photo-33","title":"Night sky 3"},
{"name":"photo-34","title":"Farmland 3"},
{"name":"photo-35","title":"Aurora 3"},
{"name":"photo-36","title":"Harbor city 3"},
{"name":"photo-37","title":"Ridges 4"},
{"name":"photo-38","title":"Open water 4"},
{"name":"photo-39","title":"River stones 4"},
{"name":"photo-40","title":"Fog in the pines 4"},
{"name":"photo-41","title":"Cloud bank 4"},
{"name":"photo-42","title":"Still lake 4"},
{"name":"photo-43","title":"Dunes 4"},
{"name":"photo-44","title":"Garden light 4"},
{"name":"photo-45","title":"Night sky 4"},
{"name":"photo-46","title":"Farmland 4"},
{"name":"photo-47","title":"Aurora 4"},
{"name":"photo-48","title":"Harbor city 4"}];
/**
* @param p_oConfig optional: { pageSize: Number }. Defaults to one page holding
* every picture.
*/
sw.photoAlbum.LocalPhotoSource = function (p_oConfig) {
sw.photoAlbum.LocalPhotoSource.superclass.constructor.call(this);
this.photos = sw.photoAlbum.generatedPhotos;
this.pageSize = (p_oConfig && p_oConfig.pageSize) || this.photos.length;
};
yui.lang.extend(sw.photoAlbum.LocalPhotoSource, sw.photoAlbum.PhotoSource, {
retrievePageCount : function () {
var that = this;
setTimeout(function () {
that.events.pageCountRetrieved.fire({
count: Math.ceil(that.photos.length / that.pageSize)
});
}, 0);
},
retrievePage : function (pageIndex) {
var start = pageIndex * this.pageSize;
var size = Math.min(this.pageSize, this.photos.length - start);
var that = this;
setTimeout(function () {
that.events.pageRetrieved.fire({index: pageIndex, size: size});
}, 0);
},
_photo : function (pageIndex, photoIndex) {
return this.photos[pageIndex * this.pageSize + photoIndex];
},
getThumbnailURL : function (pageIndex, photoIndex) {
return "pictures/thumbnails/thumb_" +
this._photo(pageIndex, photoIndex).name + ".jpg";
},
getPictureURL : function (pageIndex, photoIndex) {
return "pictures/" + this._photo(pageIndex, photoIndex).name + ".jpg";
},
getTitle : function (pageIndex, photoIndex) {
return this._photo(pageIndex, photoIndex).title;
}
});
/photoAlbum/sources/generate-photographs.js
/**
* Procedural "photographs" for the Photo Album and Light Table demos.
*
* Every picture in photoAlbum/pictures was computed by this file. No camera,
* stock image or third-party texture is involved. renderPhotograph(index, w, h)
* is deterministic: the same index and size always give the same pixels.
*
* The demos do not run this code. They load the JPEG files it produced.
* This source is released under CC0, like the demos that use it.
*/
(function (root) {
'use strict';
function prng(a) {
return function () {
a = (a + 0x6D2B79F5) | 0;
var t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function Noise(seed) {
var rnd = prng(seed);
var values = new Float32Array(256);
var perm = new Uint8Array(512);
var i, j, t;
for (i = 0; i < 256; i++) { values[i] = rnd(); perm[i] = i; }
for (i = 255; i > 0; i--) {
j = Math.floor(rnd() * (i + 1));
t = perm[i]; perm[i] = perm[j]; perm[j] = t;
}
for (i = 0; i < 256; i++) { perm[i + 256] = perm[i]; }
this.at = function (x, y) {
var xi = Math.floor(x), yi = Math.floor(y);
var fx = x - xi, fy = y - yi;
var u = fx * fx * (3 - 2 * fx), v = fy * fy * (3 - 2 * fy);
var X = xi & 255, Y = yi & 255;
var a = values[perm[X + perm[Y]]];
var b = values[perm[X + 1 + perm[Y]]];
var c = values[perm[X + perm[(Y + 1) & 255]]];
var d = values[perm[X + 1 + perm[(Y + 1) & 255]]];
return a + (b - a) * u + (c - a) * v + (a - b - c + d) * u * v;
};
}
Noise.prototype.fbm = function (x, y, octaves) {
var sum = 0, amp = 0.5, norm = 0;
for (var i = 0; i < octaves; i++) {
sum += amp * this.at(x, y);
norm += amp;
amp *= 0.5;
x = x * 2.03 + 17.1;
y = y * 2.03 + 9.2;
}
return sum / norm;
};
Noise.prototype.ridged = function (x, y, octaves) {
var sum = 0, amp = 0.5, norm = 0, n;
for (var i = 0; i < octaves; i++) {
n = 1 - Math.abs(2 * this.at(x, y) - 1);
sum += amp * n * n;
norm += amp;
amp *= 0.5;
x = x * 2.1 + 3.7;
y = y * 2.1 + 5.3;
}
return sum / norm;
};
function clamp(x, a, b) { return x < a ? a : (x > b ? b : x); }
function smooth(a, b, x) { var t = clamp((x - a) / (b - a), 0, 1); return t * t * (3 - 2 * t); }
function mix(a, b, t) { return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t]; }
function scale(c, k) { return [c[0] * k, c[1] * k, c[2] * k]; }
function add(a, b, k) { return [a[0] + b[0] * k, a[1] + b[1] * k, a[2] + b[2] * k]; }
// Times of day: zenith, horizon, sun, haze
var SKIES = [
{ top: [38, 74, 130], low: [246, 186, 130], sun: [255, 226, 170], haze: [226, 170, 150] },
{ top: [44, 110, 186], low: [196, 224, 240], sun: [255, 250, 232], haze: [176, 204, 222] },
{ top: [52, 44, 104], low: [250, 128, 76], sun: [255, 208, 120], haze: [214, 118, 104] },
{ top: [16, 26, 62], low: [132, 106, 150], sun: [244, 196, 186], haze: [92, 88, 130] }
];
function skyColor(n, s, u, v, sunU, sunV, aspect, cloudy) {
var c = mix(s.top, s.low, Math.pow(clamp(v, 0, 1), 1.5));
var dx = (u - sunU) * aspect, dy = v - sunV;
var d = Math.sqrt(dx * dx + dy * dy);
c = add(c, s.sun, 0.55 * Math.exp(-d * 4.5));
c = mix(c, s.sun, smooth(0.052, 0.04, d));
if (cloudy > 0) {
var cl = n.fbm(u * 3.2 * aspect + 4, v * 9 + 2, 6);
var k = smooth(0.56 - cloudy * 0.12, 0.76, cl) * (1 - smooth(0.7, 1, v));
var lit = mix(scale(s.low, 0.72), s.sun, clamp(1 - d * 1.5, 0, 1));
c = mix(c, lit, k * 0.86);
}
return c;
}
function ridgeLine(n, w, base, amp, freq, off) {
var a = new Float32Array(w);
for (var x = 0; x < w; x++) {
a[x] = base - amp * (n.ridged(x / w * freq + off, off * 1.7, 6) - 0.32);
}
return a;
}
/* ===== Scenes. Each returns shade(px, py, u, v) giving [r, g, b]. ===== */
function mountains(w, h, r, n) {
var s = SKIES[Math.floor(r() * 4)], aspect = w / h;
var sunU = 0.2 + r() * 0.6, sunV = 0.3 + r() * 0.22;
var L = 5, ridges = [], tint = [58 + r() * 26, 62 + r() * 22, 74 + r() * 26], i;
for (i = 0; i < L; i++) {
ridges.push(ridgeLine(n, w, 0.45 + i * 0.105, 0.34 - i * 0.03, (1.6 + i * 0.9) * aspect, r() * 90 + i * 11));
}
return function (px, py, u, v) {
for (var l = L - 1; l >= 0; l--) {
if (v >= ridges[l][px]) {
var depth = l / (L - 1);
var below = v - ridges[l][px];
var tex = n.fbm(u * (9 + l * 5) * aspect + l * 7, v * (20 + l * 7), 5);
var c = scale(tint, 0.5 + tex * 0.95);
if (l <= 2 && below < 0.05 + tex * 0.09) {
c = mix(c, [236, 236, 240], smooth(0.05 + tex * 0.09, 0.012, below) * 0.92);
}
if (l === L - 1) { c = mix(c, [34, 52, 38], 0.72); }
return mix(c, s.haze, Math.pow(1 - depth, 1.5) * 0.78);
}
}
return skyColor(n, s, u, v, sunU, sunV, aspect, 0.6);
};
}
function lake(w, h, r, n) {
var inner = mountains(w, h, r, n);
var line = 0.56 + r() * 0.1;
return function (px, py, u, v) {
if (v < line) { return inner(px, py, u, v * (0.82 / line)); }
var d = (v - line) / (1 - line);
var ripple = (n.fbm(u * 8, v * 90, 3) - 0.5) * (0.012 + d * 0.06);
var mv = line - (v - line) * 1.05 + ripple;
var mpx = clamp(Math.round(px + ripple * w * 0.7), 0, w - 1);
var c = inner(mpx, py, clamp(mpx / w, 0, 1), clamp(mv, 0, 1) * (0.82 / line));
return mix(scale(c, 0.8), [26, 46, 62], 0.14 + d * 0.3);
};
}
function sea(w, h, r, n) {
var s = SKIES[[0, 2, 2, 3][Math.floor(r() * 4)]], aspect = w / h;
var line = 0.5 + r() * 0.14, sunU = 0.3 + r() * 0.4, sunV = line - 0.05 - r() * 0.12;
var deep = [18 + r() * 12, 44 + r() * 20, 72 + r() * 24];
return function (px, py, u, v) {
if (v < line) { return skyColor(n, s, u, v / line * 0.96, sunU, sunV / line, aspect, 0.9); }
var d = (v - line) / (1 - line), persp = 1 / (d + 0.035);
var wave = n.fbm(u * aspect * persp * 1.3, persp * 2.4, 4);
var c = mix(mix(s.low, deep, smooth(0, 0.34, d)), scale(deep, 0.6), d);
c = scale(c, 0.76 + wave * 0.5);
var path = Math.abs(u - sunU) * aspect / (0.05 + d * 0.32);
var glint = Math.exp(-path * path) * smooth(0.54, 0.72, wave);
return add(c, s.sun, glint * 0.95);
};
}
function dunes(w, h, r, n) {
var s = SKIES[[0, 1, 2, 1][Math.floor(r() * 4)]], aspect = w / h, L = 4, lines = [], i;
var sand = [206 + r() * 30, 146 + r() * 24, 86 + r() * 26];
for (i = 0; i < L; i++) {
lines.push(new Float32Array(w));
var off = r() * 50, base = 0.42 + i * 0.15;
for (var x = 0; x < w; x++) {
lines[i][x] = base - 0.11 * Math.sin(x / w * (2.2 + i) * aspect + off) - 0.09 * (n.fbm(x / w * 1.7 * aspect + off, i * 3.1, 3) - 0.5);
}
}
return function (px, py, u, v) {
for (var l = L - 1; l >= 0; l--) {
if (v >= lines[l][px]) {
var slope = lines[l][clamp(px + 2, 0, w - 1)] - lines[l][clamp(px - 2, 0, w - 1)];
var below = v - lines[l][px];
var side = clamp(0.56 + slope * 95 - below * 0.8, 0.16, 1.14);
var ripples = 0.95 + 0.07 * Math.sin((v * 310 + n.fbm(u * 5 * aspect, v * 8, 3) * 26));
var c = scale(sand, side * ripples);
return mix(c, s.haze, (1 - l / (L - 1)) * 0.34);
}
}
return skyColor(n, s, u, v * 1.05, 0.72, 0.2, aspect, 0.2);
};
}
function forest(w, h, r, n) {
var s = SKIES[[0, 1, 3, 1][Math.floor(r() * 4)]], aspect = w / h, L = 6, rows = [], i;
var green = [26 + r() * 16, 56 + r() * 26, 42 + r() * 18];
for (i = 0; i < L; i++) {
var line = new Float32Array(w), base = 0.36 + i * 0.1, off = r() * 40;
line.fill(base - 0.012 * n.fbm(off, i, 2));
// Each tree is its own tapered, jagged cone, so spacing and height vary.
var cx = -0.05 * w;
while (cx < w * 1.05) {
var hgt = (0.11 + i * 0.038) * (0.55 + 0.6 * r());
var half = hgt * h * (0.2 + r() * 0.1);
var tiers = 6 + Math.floor(r() * 5), phase = r() * 6;
var from = Math.max(0, Math.floor(cx - half)), to = Math.min(w - 1, Math.ceil(cx + half));
for (var x = from; x <= to; x++) {
var q = 1 - Math.abs(x - cx) / half;
if (q <= 0) { continue; }
var teeth = 0.8 + 0.2 * Math.abs(Math.sin(q * tiers * 1.6 + phase));
var top = base - hgt * Math.pow(q, 1.25) * teeth;
if (top < line[x]) { line[x] = top; }
}
cx += half * (0.45 + r() * 0.95);
}
rows.push(line);
}
return function (px, py, u, v) {
for (var l = L - 1; l >= 0; l--) {
if (v >= rows[l][px]) {
var depth = l / (L - 1);
var c = scale(green, 0.42 + 0.9 * n.fbm(u * 60, v * 60, 3) * depth + 0.2);
var fog = (1 - depth) * 0.86 + 0.16 * n.fbm(u * 3 + l, v * 7, 4);
return mix(c, mix(s.low, s.haze, 0.45), clamp(fog, 0, 0.94));
}
}
return mix(skyColor(n, s, u, v, 0.5, 0.15, aspect, 0.25), s.low, 0.35);
};
}
function fields(w, h, r, n) {
var s = SKIES[[1, 0, 1, 2][Math.floor(r() * 4)]], aspect = w / h;
var line = 0.34 + r() * 0.12, colors = [[120, 152, 58], [186, 168, 72], [86, 126, 56], [156, 134, 62], [198, 190, 104]];
var bend = r() * 7, hillSeed = r() * 30;
return function (px, py, u, v) {
var horizon = line - 0.06 * (n.fbm(u * 2.4 * aspect + hillSeed, 1.2, 4) - 0.5);
if (v < horizon) { return skyColor(n, s, u, v / horizon * 0.92, 0.72, 0.28, aspect, 1); }
var d = (v - horizon) / (1 - horizon), persp = 1 / (d + 0.06);
var fu = (u - 0.5) * aspect * persp * 0.55 + Math.sin(d * 3 + bend) * 0.5;
var fv = persp * 0.8;
var warp = n.fbm(fu * 0.6, fv * 0.6, 3) * 1.2;
var cell = Math.floor(fu + warp) * 7 + Math.floor(fv + warp * 0.6) * 13;
var base = colors[Math.abs(cell) % colors.length];
var rows = 0.92 + 0.11 * Math.sin((fu + warp) * (24 + (Math.abs(cell) % 3) * 12));
var c = scale(base, rows * (0.72 + n.fbm(u * 28, v * 34, 4) * 0.58));
return mix(c, s.haze, Math.pow(1 - d, 5) * 0.66);
};
}
function cloudscape(w, h, r, n) {
var s = SKIES[Math.floor(r() * 3)], aspect = w / h, sunU = r(), off = r() * 40;
return function (px, py, u, v) {
var sky = mix(s.top, s.low, Math.pow(v, 1.3));
var x = u * 2.4 * aspect + off, y = v * 3.6 + off * 0.3;
var warp = n.fbm(x * 0.8, y * 0.8, 3);
var density = n.fbm(x + warp, y + warp * 0.8, 7) + v * 0.3 - 0.13;
var lightProbe = n.fbm(x + warp - 0.09, y + warp * 0.8 - 0.12, 5) + v * 0.3 - 0.13;
var k = smooth(0.44, 0.68, density);
var lit = clamp(0.62 + (density - lightProbe) * 5.2, 0.16, 1.2);
var cloud = mix(scale(s.haze, 0.6), mix([255, 252, 246], s.sun, 0.36), lit);
var glow = Math.exp(-Math.abs(u - sunU) * 2.4) * 0.14;
return add(mix(sky, cloud, k), s.sun, glow);
};
}
function nightSky(w, h, r, n) {
var aspect = w / h, tilt = 0.3 + r() * 0.9, off = r() * 20;
var ridge = ridgeLine(n, w, 0.86, 0.22, 2.5 * aspect, r() * 40);
var stars = new Float32Array(w * h), count = Math.floor(w * h / 190), i;
for (i = 0; i < count; i++) {
var at = Math.floor(r() * w) + Math.floor(r() * h) * w;
stars[at] = Math.pow(r(), 3.4) * 1.4 + 0.1;
}
return function (px, py, u, v) {
if (v >= ridge[px]) { return scale([12, 16, 22], 0.5 + n.fbm(u * 30, v * 30, 3) * 0.5); }
var c = mix([7, 11, 30], [32, 42, 76], Math.pow(v, 2.1));
var band = (v - 0.45) * Math.cos(tilt) - (u - 0.5) * aspect * Math.sin(tilt) * 0.5;
var along = (u - 0.5) * aspect * Math.cos(tilt) + (v - 0.45) * Math.sin(tilt);
var cloud = n.fbm(along * 3.2 + off, band * 8 + off, 6);
var m = Math.exp(-band * band * 26) * smooth(0.28, 0.72, cloud);
c = add(c, [172, 152, 182], m * 0.78);
c = add(c, [255, 208, 170], Math.exp(-band * band * 110) * smooth(0.45, 0.8, cloud) * 0.34);
var star = stars[px + py * w];
if (star > 0) { c = add(c, [255, 246, 232], Math.min(star * (1 + m), 1)); }
return add(c, [255, 150, 96], Math.exp(-(ridge[px] - v) * 13) * 0.11);
};
}
function aurora(w, h, r, n) {
var aspect = w / h, off = r() * 30, hue = r();
var ridge = ridgeLine(n, w, 0.62, 0.12, 2.1 * aspect, r() * 40);
var line = 0.7, stars = prng(77 + Math.floor(off * 9));
var green = [76, 246, 150], top = hue > 0.5 ? [150, 92, 232] : [60, 180, 226];
var field = new Float32Array(w * h), count = Math.floor(w * h / 420), i;
for (i = 0; i < count; i++) { field[Math.floor(stars() * w * h)] = stars() * 0.8; }
function air(px, py, u, v) {
var c = mix([6, 12, 30], [20, 44, 64], Math.pow(v / line, 1.6));
for (var b = 0; b < 3; b++) {
var center = 0.25 + b * 0.13 + 0.12 * Math.sin(u * 3.4 * aspect + off + b * 2) + 0.07 * (n.fbm(u * 3 * aspect + b, off, 4) - 0.5) * 3;
var dy = v - center;
var rays = 0.5 + 0.5 * n.fbm(u * 46 * aspect + b * 9, off + b, 3);
var below = Math.exp(-Math.max(dy, 0) * 34), above = Math.exp(-Math.max(-dy, 0) * 7.5);
var k = below * above * Math.pow(rays, 2.1) * 1.9;
c = add(c, mix(green, top, clamp(-dy * 6.4, 0, 1)), k * 0.62);
}
var star = field[px + py * w];
return star > 0 ? add(c, [240, 244, 255], star) : c;
}
return function (px, py, u, v) {
if (v >= line) {
var d = (v - line) / (1 - line);
var wob = (n.fbm(u * 7, v * 80, 3) - 0.5) * (0.02 + d * 0.05);
var my = clamp(line - (v - line) * 1.1 + wob, 0, line - 0.001);
var mx = clamp(Math.round(px + wob * w), 0, w - 1);
var rc = my >= ridge[mx] ? [8, 12, 18] : air(mx, Math.floor(my * h), mx / w, my);
return mix(scale(rc, 0.72), [6, 14, 24], 0.2 + d * 0.3);
}
return v >= ridge[px] ? scale([9, 14, 20], 0.5 + n.fbm(u * 25, v * 25, 3) * 0.6) : air(px, py, u, v);
};
}
function stones(w, h, r, n) {
var aspect = w / h, cells = 15 + Math.floor(r() * 8), pts = [], i;
var tones = [[146, 136, 124], [98, 92, 88], [182, 170, 150], [122, 112, 106], [166, 128, 104], [80, 88, 96]];
for (i = 0; i < cells * cells; i++) {
pts.push({ x: (i % cells + 0.15 + r() * 0.7) / cells * aspect, y: (Math.floor(i / cells) + 0.15 + r() * 0.7) / cells, tone: tones[Math.floor(r() * tones.length)], k: 0.76 + r() * 0.42 });
}
return function (px, py, u, v) {
var x = u * aspect + (n.fbm(u * 8, v * 8, 2) - 0.5) * 0.03;
var y = v + (n.fbm(u * 8 + 5, v * 8, 2) - 0.5) * 0.03;
var cx = Math.floor(x / aspect * cells), cy = Math.floor(y * cells);
var best = 9, second = 9, pick = pts[0];
for (var a = -2; a <= 2; a++) {
for (var b = -2; b <= 2; b++) {
var q = pts[clamp(cy + b, 0, cells - 1) * cells + clamp(cx + a, 0, cells - 1)];
var d = (q.x - x) * (q.x - x) + (q.y - y) * (q.y - y);
if (d < best) { second = best; best = d; pick = q; }
else if (d < second && q !== pick) { second = d; }
}
}
var edge = Math.sqrt(second) - Math.sqrt(best);
if (edge < 0.0045) { return [18, 16, 15]; }
var dome = smooth(0.003, 0.038, edge);
var nx = (pick.x - x) * cells, ny = (pick.y - y) * cells;
var light = clamp(0.56 + dome * 0.3 + (nx * 0.34 + ny * 0.44), 0.16, 1.32);
var speck = 0.86 + n.fbm(x * 70, y * 70, 4) * 0.32;
return scale(pick.tone, pick.k * light * speck * (0.5 + 0.5 * dome));
};
}
function bokeh(w, h, r, n) {
var aspect = w / h, discs = [], i, palette = [[255, 196, 92], [255, 118, 96], [148, 214, 118], [255, 232, 170], [116, 190, 226]];
var bgA = [26 + r() * 24, 46 + r() * 30, 34 + r() * 24], bgB = [82 + r() * 40, 96 + r() * 36, 58 + r() * 26];
for (i = 0; i < 46; i++) {
discs.push({ x: r() * aspect, y: r(), r: 0.025 + r() * r() * 0.095, c: palette[Math.floor(r() * palette.length)], a: 0.1 + r() * 0.32 });
}
var stemX = 0.25 + r() * 0.5, lean = (r() - 0.5) * 0.5, budY = 0.26 + r() * 0.2;
return function (px, py, u, v) {
var x = u * aspect;
var c = mix(bgA, bgB, n.fbm(u * 2.4 * aspect, v * 2.4, 4));
for (var d = 0; d < discs.length; d++) {
var o = discs[d], dist = Math.sqrt((o.x - x) * (o.x - x) + (o.y - v) * (o.y - v));
if (dist < o.r) {
c = add(c, o.c, o.a * (0.72 + 0.28 * smooth(o.r * 0.72, o.r, dist)) * smooth(o.r, o.r * 0.95, dist));
}
}
var sx = (stemX + lean * (1 - v) * (1 - v)) * aspect;
if (v > budY && Math.abs(x - sx) < 0.0065) { return mix([56, 104, 48], [112, 158, 72], (x - sx) / 0.013 + 0.5); }
var bx = x - (stemX + lean * (1 - budY) * (1 - budY)) * aspect, by = v - budY;
var ang = Math.atan2(by, bx), rad = Math.sqrt(bx * bx + by * by);
var petal = 0.062 * (0.74 + 0.26 * Math.abs(Math.cos(ang * 3.5)));
if (rad < petal) {
if (rad < 0.017) { return mix([244, 196, 60], [176, 104, 34], n.at(x * 300, v * 300)); }
return scale([246, 232, 226], 0.7 + 0.36 * (rad / petal) * (0.7 + 0.3 * Math.cos(ang * 7)));
}
return c;
};
}
function skyline(w, h, r, n) {
var s = SKIES[[2, 3, 3, 0][Math.floor(r() * 4)]], aspect = w / h;
var line = 0.7 + r() * 0.06, rows = [], layer, x;
for (layer = 0; layer < 3; layer++) {
var tops = new Float32Array(w), id = new Int32Array(w), at = 0, k = 0;
while (at < w) {
var bw = Math.floor((0.03 + r() * 0.055) * w * (1 + layer * 0.5));
var top = line - (0.1 + layer * 0.06) - r() * (0.11 + layer * 0.12);
for (x = at; x < Math.min(w, at + bw); x++) { tops[x] = top; id[x] = k; }
at += bw; k++;
}
rows.unshift({ tops: tops, id: id, shade: 0.3 + (2 - layer) * 0.2 });
}
function city(px, py, u, v) {
for (var l = 2; l >= 0; l--) {
var row = rows[l];
if (v >= row.tops[px] && v < line) {
var c = mix([18, 18, 34], s.haze, (2 - l) * 0.21);
var wx = Math.floor(px / 4), wy = Math.floor(py / 5);
if (px % 4 !== 0 && py % 5 > 1 && n.at(wx * 3.3 + row.id[px], wy * 2.9 + l * 5) > 0.67) {
var lamp = n.at(wx * 7.1, wy * 5.7) > 0.5 ? [255, 214, 136] : [186, 216, 240];
c = mix(c, lamp, 0.92 - (2 - l) * 0.16);
}
return c;
}
}
return skyColor(n, s, u, v / line * 0.94, 0.68, 0.46, aspect, 0.7);
}
return function (px, py, u, v) {
if (v < line) { return city(px, py, u, v); }
var d = (v - line) / (1 - line);
var wob = (n.fbm(u * 9, v * 110, 3) - 0.5) * (0.015 + d * 0.05);
var mv = clamp(line - (v - line) * 1.05 + wob, 0, line - 0.001);
var mx = clamp(Math.round(px + wob * w * 0.6), 0, w - 1);
return mix(scale(city(mx, Math.floor(mv * h), mx / w, mv), 0.7), [10, 18, 34], 0.16 + d * 0.32);
};
}
var SCENES = [mountains, sea, stones, forest, cloudscape, lake, dunes, bokeh, nightSky, fields, aurora, skyline];
var NAMES = ['Ridges', 'Open water', 'River stones', 'Fog in the pines', 'Cloud bank', 'Still lake', 'Dunes', 'Garden light', 'Night sky', 'Farmland', 'Aurora', 'Harbor city'];
/**
* Renders one picture.
* @return {Uint8ClampedArray} RGBA pixels, w * h * 4 long
*/
function renderPhotograph(index, w, h) {
var seed = 40961 + index * 7919;
var r = prng(seed);
var n = new Noise(seed ^ 0x5bd1e995);
var shade = SCENES[index % SCENES.length](w, h, r, n);
var grainRnd = prng(seed + 3);
var warm = (r() - 0.5) * 0.07, contrast = 1.04 + r() * 0.1;
var out = new Uint8ClampedArray(w * h * 4);
var i = 0;
for (var y = 0; y < h; y++) {
for (var x = 0; x < w; x++) {
var u = (x + 0.5) / w, v = (y + 0.5) / h;
var c = shade(x, y, u, v);
var dx = u - 0.5, dy = v - 0.5;
var vignette = 1 - 0.62 * Math.pow(dx * dx + dy * dy, 1.15);
var grain = (grainRnd() + grainRnd() - 1) * 5.2;
for (var k = 0; k < 3; k++) {
var value = c[k] * vignette * (k === 0 ? 1 + warm : (k === 2 ? 1 - warm : 1)) / 255;
value = clamp(0.5 + (value - 0.5) * contrast, 0, 1);
value = value * value * (3 - 2 * value) * 0.34 + value * 0.66;
out[i + k] = value * 255 + grain;
}
out[i + 3] = 255;
i += 4;
}
}
return out;
}
root.ProceduralPhotographs = {
renderPhotograph: renderPhotograph,
titleFor: function (index) {
return NAMES[index % NAMES.length] + ' ' + (Math.floor(index / NAMES.length) + 1);
},
/* Every sixth picture is a portrait. */
isPortrait: function (index) { return index % 6 === 5; }
};
})(typeof window !== 'undefined' ? window : globalThis);
/res/2.0/scripts/tools/magnifier.js
/** =======================================================================
* Vincent Hardy
* License terms: see svg-wow.org
* CC0 http://creativecommons.org/publicdomain/zero/1.0/
* ======================================================================= */
var yui = yui || YAHOO;
sw.tools = sw.tools || {};
/**
* Provides a magnifying function and returns the modified position
* and size of a given point.
*
* Inspired by Jared Tarbel's text sphere:
* http://www.levitated.net/daily/levTextSphere.html
*
* @param radius the magnifier's radius.
* @param x the magnifier's x position
* @param y the magnifier's y position
* @param maxMagnification the magnifier's maximum magnification (at
* it's center position).
* @param minMagnification the magnifier's minimum magnification (at
* it's center position).
* @param direction one of <code>DIRECTION_BOTH</code>, <code>DIRECTION_X</code>
* <code>DIRECTION_Y</code>
*/
sw.tools.Magnifier = function (radius, x, y,
maxMagnification,
minMagnification,
direction) {
this.radius = radius;
this.x = x;
this.y = y;
this.maxMagnification = maxMagnification;
this.minMagnification = minMagnification;
this.direction = direction;
this.events = {
onChange: new yui.util.CustomEvent(this.MAGNIFIER_CHANGE)
}
}
/**
* Constants
*/
sw.tools.Magnifier.prototype.MAGNIFIER_CHANGE = "MAGNIFIER_CHANGE";
sw.tools.Magnifier.prototype.DIRECTION_BOTH = 0;
sw.tools.Magnifier.prototype.DIRECTION_X = 1;
sw.tools.Magnifier.prototype.DIRECTION_Y= 2;
/**
* Sets the current radius
*
* @param newRadius the new magnifier radius
*/
sw.tools.Magnifier.prototype.setRadius = function (newRadius) {
if (this.radius !== newRadius) {
this.radius = newRadius;
this.events.onChange.fire();
}
}
/**
* Change the magnifier position.
*/
sw.tools.Magnifier.prototype.setPosition = function (x, y) {
this.x = x;
this.y = y;
this.events.onChange.fire();
}
/**
* Computes the displacement for the given point.
*
* @param x the input point's x coordinate
* @param y the input point's y coordinate
* @param result an object where the displaced coordinates and magnification
* factor will be stored.
*/
sw.tools.Magnifier.prototype.processPoint = function (x, y, result) {
var dx = x - this.x;
var dy = y - this.y;
var displacement;
var d = Math.sqrt(dx * dx + dy * dy);
var p = d / this.radius;
if (p >= 1) {
result.x = x;
result.y = y;
result.magnification = this.minMagnification;
result.displacement = 0;
result.p = 1;
} else {
// On the edge of the magnifier, there is no displacement.
// There is no displacement at the center either.
// The maximum displacement is half way (p = 0.5) between
// the edge of the lens and its center.
displacement = Math.sin(Math.PI * p);
result.x = x + dx * displacement;
result.y = y + dy * displacement;
// The maximum magnification is reached at the center of the lens (p = 0).
// On the edge (p = 1), the magnification is 1 (no magnification).
result.magnification = this.minMagnification +
(this.maxMagnification - this.minMagnification) *
(1 - Math.sin(p * Math.PI / 2));
result.displacement = displacement;
result.p = p;
}
switch (this.direction) {
case this.DIRECTION_X: {
result.y = y;
break;
}
case this.DIRECTION_Y: {
result.x = x;
break;
}
default:
break;
}
}/res/2.0/scripts/animation/animate.js
/** =======================================================================
* Vincent Hardy
* License terms: see svg-wow.org
* CC0 http://creativecommons.org/publicdomain/zero/1.0/
* ======================================================================= */
(function () {
sw.animation = sw.animation || {};
yui = YAHOO;
var Anim = yui.util.Anim;
/**
* Object with the names of the transform pseudo attributes.
*/
var PSEUDO_ATTRIBUTES = {
tx: "#tx",
ty: "#ty",
sx: "#sx",
sy: "#sy",
r: "#r"
};
var PSEUDO_DEFAULTS = {
tx: 0,
ty: 0,
sx: 1,
sy: 1,
r: 0
};
var PSEUDO_ATTRIBUTES_ARRAY = ["tx", "ty", "sx", "sy", "r"];
var N_PSEUDO_ATTRIBUTES = PSEUDO_ATTRIBUTES_ARRAY.length;
/**
* Simple extension of the YUI animation classes to handle SVG transforms.
*
* The extension handles the "r", "sx", "sy", "tx" and "ty" pseudo attributes
* by manipulating the transform of the target element using a template.
*
* @param p_el the element that will be animated
* @param p_attributes the attributes to animate. This animation class adds the
* "r" (rotation), "tx", "ty", "sx" and "sy" (scale) pseudo-attributes.
* @param p_oTransformTemplate the template for the transform attribute to
* animate. By default, it is
* "translate(#tx,#ty) scale(#sx,#sy) rotate(#r)"
* but it can be set to any string.
* @param p_oDuration the animation duration
* @param p_oMethod easing method
*
* @see http://developer.yahoo.com/yui/docs/YAHOO.util.Anim.html
*/
sw.animation.Animate = function (p_el, p_attributes,
p_oDuration,
p_oMethod) {
sw.animation.Animate.superclass.constructor.call(this, p_el,
p_attributes, p_oDuration, p_oMethod);
var el = sw.stringToElement(p_el);
var _endCallbacks = [];
var _endAnimations = [];
var _beginCallbacks = [];
var _beginAnimations = [];
this._endCallbacks = _endCallbacks;
this._endAnimations = _endAnimations;
this._beginCallbacks = _beginCallbacks;
this._beginAnimations = _beginAnimations;
this.onComplete.subscribe(function () {
for (var i = 0; i < _endCallbacks.length; i++) {
_endCallbacks[i]();
}
for (i = 0; i < _endAnimations.length; i++) {
_endAnimations[i].animate();
}
});
this.onStart.subscribe(function () {
for (var i = 0; i < _beginCallbacks.length; i++) {
_beginCallbacks[i]();
}
for (i = 0; i < _beginAnimations.length; i++) {
_beginAnimations[i].animate();
}
});
};
yui.lang.extend(sw.animation.Animate,
Anim, {
/**
* Sets the new attribute value
*
* @param p_attr the attribute name
* @param p_val the attribute value
* @param p_unit the unit
*/
setAttribute : function (p_attr, p_val, p_unit) {
var el = this.getEl();
if (attributeHandlers[p_attr] &&
attributeHandlers[p_attr].setAttribute) {
return attributeHandlers[p_attr].setAttribute.call(this, el, p_val);
} else {
// Let the base class handle the attributes
sw.animation.Animate.superclass.setAttribute.call(this,
p_attr, p_val, p_unit);
}
},
/**
* Gets the attribute value
*
* @param p_attr the attribute name
*/
getAttribute : function (p_attr) {
if (attributeHandlers[p_attr] &&
attributeHandlers[p_attr].getAttribute) {
return attributeHandlers[p_attr].getAttribute.call(this, this.getEl());
} else {
// Let the base class handle the attribute
return sw.animation.Animate.superclass.
getAttribute.call(this, p_attr);
}
},
/**
* Overrides the default implementation to check if there is an attribute
* handler for the attribute.
* @param {String} attr The name of the attribute.
* @param {Number} start The value this attribute should start from for this animation.
* @param {Number} end The value this attribute should end at for this animation.
* @return The Value to be applied to the attribute.
*/
doMethod : function (attr, start, end) {
var val;
if (attributeHandlers[attr] &&
attributeHandlers[attr].interpolate) {
var p = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
val = attributeHandlers[attr].interpolate.call(this, start, end, p);
} else {
val = Anim.prototype.doMethod.call(this, attr, start, end);
}
return val;
},
/**
* Implementation helper: applies the current transform.
* Note that this quite costly, from a computation perspective, so
* it should be use conservatively.
*/
applyTransform : function () {
var txf = this.transformTemplate;
var el = this.getEl();
var attrs = PSEUDO_ATTRIBUTES;
var a = PSEUDO_ATTRIBUTES_ARRAY;
var n = a.length;
var p;
for (var i = 0; i < n; i++) {
p = a[i];
txf = txf.replace(attrs[p], el[p]);
}
el.setAttribute("transform", txf);
},
/**
* Returns a handler that will start this animation instance when invoked.
*/
getStartHandler : function () {
var that = this;
if (this._startHandler === undefined) {
this._startHandler = function () {
that.animate();
};
}
return this._startHandler;
},
/**
* Adds a function of animation to call or play when this animation ends
*
* @param p_animOrCallback an animation or function to trigger when this
* animation ends
*/
onEnd : function (p_animOrCallback) {
if (typeof p_animOrCallback === "function") {
this._endCallbacks.push(p_animOrCallback);
} else if (p_animOrCallback !== null &&
p_animOrCallback !== undefined &&
typeof p_animOrCallback.animate === "function") {
this._endAnimations.push(p_animOrCallback);
}
},
/**
* Adds a function of animation to call or play when this animation begins
*
* @param p_animOrCallback an animation or function to trigger when this
* animation begins
*/
onBegin : function (p_animOrCallback) {
if (typeof p_animOrCallback === "function") {
this._beginCallbacks.push(p_animOrCallback);
} else if (p_animOrCallback !== null &&
p_animOrCallback !== undefined &&
typeof p_animOrCallback.animate === "function") {
this._beginAnimations.push(p_animOrCallback);
}
}
});
/**
* Class static
*/
var attributeHandlers = {};
/**
* Adds a new way to handle a given attribute. The handler should have the
* following:
*
* - setAttribute. A funtion taking the element and value as parameters.
* - getAttribute. A function taking the element as parameter and
* returning the attribute value.
* - interpolate. A function taking the start value, end value, current
* progress in time interval and interpolation method as a parameter. It
* should return the value to apply to the animation target.
*
* @param p_attributeName the name of the attribute to which the handler
* applies.
* @param p_attributeHandler an object holding the setAttribute, getAttribute
* and interpolate methods
*/
sw.animation.Animate.addAttributeHandler = function (p_attributeName,
p_attributeHandler) {
attributeHandlers[p_attributeName] = p_attributeHandler;
};
// =============================================================================
// Generic handler for the SVG transform attribute
// =============================================================================
sw.animation.Animate.addAttributeHandler("txf", {
setAttribute: function (e, v) {
var txf = this.attributes.txf.template, val, p;
if (txf) {
for (var p in v) {
if (v.hasOwnProperty(p)) {
val = v[p];
txf = txf.replace(PSEUDO_ATTRIBUTES[p], val);
e[p] = val;
}
}
e.setAttribute("transform", txf);
}
},
getAttribute: function (e) {
var result = {
tx: 0,
ty: 0,
sx: 1,
sy: 1,
r: 0
};
for (var i = 0; i < N_PSEUDO_ATTRIBUTES; i++) {
a = PSEUDO_ATTRIBUTES_ARRAY[i];
if (e[a] !== undefined) {
result[a] = e[a];
} else {
e[a] = result[a];
}
}
return result;
},
interpolate: function (start, end, p) {
var s, e, a, result = {}, elt;
for (var i = 0; i < N_PSEUDO_ATTRIBUTES; i++) {
a = PSEUDO_ATTRIBUTES_ARRAY[i];
s = start[a];
e = end[a];
if (s === undefined) {
elt = this.getEl();
if (elt[a] !== undefined) {
s = elt[a];
}
if (s === undefined) {
s = PSEUDO_DEFAULTS[a];
}
start[a] = s;
}
if (e !== undefined) {
result[a] = p * e + (1 - p) * s;
} else {
result[a] = s;
}
}
return result;
}
});
})();
/res/2.0/scripts/dom-utils.js
/** =======================================================================
* Vincent Hardy
* License terms: see svg-wow.org
* CC0 http://creativecommons.org/publicdomain/zero/1.0/
* ======================================================================= */
(function () {
// Use the sw (svgWow!) prefix for all the library.
window.sw = window.sw ? window.sw : {};
/**
* Global function for getting an element by id concisely.
*/
if (window.$ === undefined) {
window.$ = function (id) {
return document.getElementById(id);
};
}
// Namespace constants
sw.svgNS = "http://www.w3.org/2000/svg";
sw.xlinkNS = "http://www.w3.org/1999/xlink";
sw.wowNS = "http://www.svgopen.org/2004/svgWow";
sw.xhtmlNS = "http://www.w3.org/1999/xhtml";
// Default namespace prefixes
var defaultNamespacePrefixes = {
svg: sw.svgNS,
xlink: sw.xlinkNS,
sw: sw.wowNS,
xhtml: sw.xhtmlNS
};
// =========================================================================
// DOM Helpers
// =========================================================================
sw.firstElement = function () {
var c = this.firstChild;
var result = null;
while (c !== null) {
if (c.nodeType === Node.ELEMENT_NODE) {
result = c;
break;
}
c = c.nextSibling;
}
return result;
};
sw.nextElement = function () {
var s = this.nextSibling;
var result = null;
while (s !== null) {
if (s.nodeType === Node.ELEMENT_NODE) {
result = s;
break;
}
s = s.nextSibling;
}
return result;
};
sw.prevElement = function () {
var s = this.prevSibling;
var result = null;
while (s !== null) {
if (s.nodeType === Node.ELEMENT_NODE) {
result = s;
break;
}
s = s.prevSibling;
}
return result;
};
sw.removeAllChildren = function () {
var c = this.firstChild;
var nc;
while (c !== null) {
nc = c.nextSibling;
this.removeChild(c);
c = nc;
}
};
sw.getMatrix = function () {
var m = undefined, txf, svg;
if (this.transform !== undefined) {
txf = this.transform.baseVal.consolidate();
if (txf === null) {
svg = this.ownerSVGElement;
m = svg.createSVGMatrix();
txf = this.transform.baseVal.createSVGTransformFromMatrix(m);
this.transform.baseVal.initialize(txf);
} else {
m = txf.matrix;
}
}
return m;
}
sw.setMatrix = function (m) {
var txf, svg;
if (this.transform !== undefined) {
svg = this.ownerSVGElement;
txf = this.transform.baseVal.createSVGTransformFromMatrix(m);
this.transform.baseVal.initialize(txf);
}
return this;
}
sw.getShowHandler = function () {
var that = this;
return function () {
that.setAttribute("display", "inline");
}
};
sw.getHideHandler = function () {
var that = this;
return function () {
that.setAttribute("display", "none");
}
};
/**
* Global function for toggling the current display value.
*
* @param id the id of the element whose display should be toggled between
* 'block' and 'none'
*/
function toggleDisplay(id) {
var elm = $(id);
if(elm) {
elm.style.display = (elm.style.display == "none" ? "block" : "none");
}
}
// =============================================================================
// Simple SVG API
//
// @see: http://www.w3.org/Graphics/SVG/WG/wiki/Simple_SVG_API
// =============================================================================
// List of SVG elements on which the setAttributes method is made available
sw.svgElements = [
"a",
"altGlyph",
"altGlyphDef",
"altGlyphItem",
"animate",
"animateColor",
"animateMotion",
"animateTransform",
"circle",
"clipPath",
"color-profile",
"cursor",
"definition-src",
"defs",
"desc",
"ellipse",
"feBlend",
"feColorMatrix",
"feComponentTransfer",
"feComposite",
"feConvolveMatrix",
"feDiffuseLighting",
"feDisplacementMap",
"feDistantLight",
"feFlood",
"feFuncA",
"feFuncB",
"feFuncG",
"feFuncR",
"feGaussianBlur",
"feImage",
"feMerge",
"feMergeNode",
"feMorphology",
"feOffset",
"fePointLight",
"feSpecularLighting",
"feSpotLight",
"feTile",
"feTurbulence",
"filter",
"font",
"font-face",
"font-face-format",
"font-face-name",
"font-face-src",
"font-face-uri",
"foreignObject",
"g",
"glyph",
"glyphRef",
"hkern",
"image",
"line",
"linearGradient",
"marker",
"mask",
"metadata",
"missing-glyph",
"mpath",
"path",
"pattern",
"polygon",
"polyline",
"radialGradient",
"rect",
"script",
"set",
"stop",
"style",
"svg",
"switch",
"symbol",
"text",
"textPath",
"title",
"tref",
"tspan",
"use",
"view",
"vkern"
];
/**
* This method automatically loads and creates DOM nodes.
*
* The symtax for the object is as follows;
* - the tag property gives the object's tag name
* - the ns property gives the object's namespace. Optional, defaults to the
* SVG namespace.
* - the children property is a set of sub-objects with the same syntax.
*
* @param p_desc the object describing the element to create and initialize.
* @param p_oInsertBefore Optional. the child before which the loaded content
* should be inserted
* @return the element that was created.
*/
sw.loadContent = function (p_desc, p_oInsertBefore) {
var content;
if (typeof p_desc === "string") {
content = document.createTextNode(p_desc);
this.appendChild(document.createTextNode(p_desc));
} else if (typeof p_desc === "object") {
// Save the reserved values first.
var tagOrig = p_desc.tag;
var nsOrig = p_desc.ns;
var childrenOrig = p_desc.children;
// Now, process the element.
var tag = p_desc.tag;
if (tag === undefined) {
throw new Error(
"the element description requires a 'tag' property");
}
var ns = sw.svgNS;
if (p_desc.ns !== undefined) {
ns = p_desc.ns;
}
content = document.createElementNS(ns, tag);
if (content === null || content === undefined) {
throw new Error("was not able to create an element with tag " +
tag + " in namespace " + ns);
}
var children = p_desc.children;
delete p_desc.children;
delete p_desc.tag;
delete p_desc.ns;
content.setAttributes(p_desc);
if (children !== undefined && children !== null) {
var nChildren = children.length;
if (typeof nChildren === "number") {
for (var i = 0; i < nChildren; i++) {
var c = content.loadContent(children[i]);
}
}
}
// Restore
p_desc.children = childrenOrig;
p_desc.tag = tagOrig;
p_desc.ns = nsOrig;
if (p_oInsertBefore === undefined) {
p_oInsertBefore = null;
}
if (this.insertBefore !== undefined) {
this.insertBefore(content, p_oInsertBefore);
}
sw.initIds(content);
} else {
throw new Error("loadContent requires an object or string parameter");
}
return content;
}
/**
* The setAttributes method to be installed on all element classes.
*
* @param attributes an object with the attributes to set on the object this
* method is called on.
*/
sw.setAttributes = function (attributes) {
var value,
ns = null,
nsPrefix,
nsIndex;
for (var p in attributes) {
if (attributes.hasOwnProperty(p) === true) {
nsIndex = p.indexOf(":");
if (nsIndex !== -1) {
nsPrefix = p.substring(0, nsIndex);
ns = this.lookupNamespaceURI(nsPrefix);
if (ns === null) {
// No namespace declaration was found on the node.
// This may be because the node is not in the tree
// yet. The best thing which can be done here is to
// check if we can find the namespace definition on the
// document element.
ns = document.documentElement.lookupNamespaceURI(nsPrefix);
// If the namespace is still not found, check the
// default list of known namespaces
if (defaultNamespacePrefixes[nsPrefix] !== undefined) {
ns = defaultNamespacePrefixes[nsPrefix];
}
}
} else {
ns = null;
}
value = attributes[p];
try {
this.setAttributeNS(ns, p, value);
} catch (e) {
console.log("could not set " + p + " for " + ns + " to " + value);
}
}
}
};
/**
* Get a number of attributes on this element and return them in an object.
*
* @param attr1, ... attrN a variable length list of attributes to retrieve
* from this element.
* @return an object whose properties are the requested attribute values
*/
sw.getAttributes = function () {
var result = {};
var nsIndex = -1;
var attribute;
var ns = null;
var nsPrefix;
for (var i = 0; i < arguments.length; i++) {
attribute = arguments[i];
nsIndex = attribute.indexOf(":");
if (nsIndex !== -1) {
nsPrefix = attribute.substring(0, nsIndex);
ns = this.lookupNamespaceURI(nsPrefix);
if (ns === null) {
ns = svg.lookupNamespaceURI(nsPrefix);
}
} else {
ns = null;
}
result[attribute] = this.getAttributeNS(ns, attribute);
}
return result;
}
/**
* Utility to get the bounds of an object in the nearest viewport space.
*/
sw.getViewportBBox = function () {
var bbox = this.getBBox();
var vBbox = null;
var viewport = this.nearestViewportElement;
var ctm = this.getTransformToElement(viewport);
if (bbox !== null) {
// This is one of the short-comings of SVG: there is no way to get
// the bbox in the desired coordinate space. So we have to transform
// the bounds and compute the box from that, which leads to
// boxes which might be larger than needed (e.g., where there are
// rotations). However, for common cases, this is doing the job.
var points = [
{x: bbox.x, y: bbox.y},
{x: bbox.x + bbox.width, y: bbox.y},
{x: bbox.x, y: bbox.y + bbox.height},
{x: bbox.x + bbox.width, y: bbox.y + bbox.height}
];
var tPoints = [
{}, {}, {}, {}
];
for (var i = 0; i < 4; i++) {
ctm.transformPoint(points[i], tPoints[i]);
}
var minX = tPoints[0].x;
var minY = tPoints[0].y;
var maxX = tPoints[0].x;
var maxY = tPoints[0].y;
for (i = 1; i < 4; i++) {
if (tPoints[i].x < minX) {
minX = tPoints[i].x;
} else if (tPoints[i].x > maxX) {
maxX = tPoints[i].x;
}
if (tPoints[i].y < minY) {
minY = tPoints[i].y;
} else if (tPoints[i].y > maxY) {
maxY = tPoints[i].y;
}
}
vBbox = {
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY
};
}
return vBbox;
};
/**
* Transforms a point.
*
* @param p_pt an object with x/y properties
* @param p_oResult an object where the transformed point is stored
* @return the result
*/
sw.transformPoint = function (p_pt, p_oResult) {
var result = p_oResult;
if (p_oResult === undefined) {
result = {};
}
result.x = this.a * p_pt.x + this.c * p_pt.y + this.e;
result.y = this.b * p_pt.x + this.d * p_pt.y + this.f;
return result;
};
/**
* Sets the matrix to identity
*/
sw.toIdentity = function () {
this.a = 1;
this.b = 0;
this.c = 0;
this.d = 1;
this.e = 0;
this.f = 0;
return this;
};
/**
* Installs the setAttributes method on the prototype object which holds the
* setAttribute (no 's') method.
*
* @param documentElement if undefined, defaults to document.documentElement,
* assuming an SVG root.
* @param scope if undefined, defaults to the global scope.
*/
sw.init = function (documentElement, scope) {
if (documentElement === undefined) {
documentElement = document.documentElement;
}
if (scope === undefined) {
scope = window;
}
var errors = {};
var hasErrors = false;
for (var i = 0; i < sw.svgElements.length; i++) {
var tag = sw.svgElements[i];
var elt = document.createElementNS(sw.svgNS, tag);
if (elt !== null && elt !== undefined) {
var proto = elt.constructor.prototype;
if (proto.setAttributes === undefined) {
proto.setAttributes = sw.setAttributes;
}
if (proto.getAttributes === undefined) {
proto.getAttributes = sw.getAttributes;
}
if (proto.loadContent === undefined) {
proto.loadContent = sw.loadContent;
}
if (proto.firstElmeent === undefined) {
proto.firstElement = sw.firstElement;
}
if (proto.nextElement === undefined) {
proto.nextElement = sw.nextElement;
}
if (proto.prevElement === undefined) {
proto.prevElement= sw.prevElement;
}
if (proto.removeAllChildren === undefined) {
proto.removeAllChildren = sw.removeAllChildren;
}
if (proto.getMatrix === undefined) {
proto.getMatrix = sw.getMatrix;
}
if (proto.setMatrix === undefined) {
proto.setMatrix = sw.setMatrix;
}
if (proto.getViewportBBox === undefined) {
proto.getViewportBBox = sw.getViewportBBox;
}
if (proto.getHideHandler === undefined) {
proto.getHideHandler = sw.getHideHandler;
}
if (proto.getShowHandler === undefined) {
proto.getShowHandler = sw.getShowHandler;
}
} else {
errors[tag] = "Constructed element was " + elt;
hasErrors = true;
}
}
// Hook a transformPoint and toIdentity on SVGMatrix
var svg = documentElement;
var isSVG = true;
if (svg.nodeName !== "svg") {
svg = document.createElementNS(sw.svgNS, "svg");
isSVG = false;
}
var m = svg.createSVGMatrix();
if (m.constructor.prototype.transformPoint === undefined) {
m.constructor.prototype.transformPoint = sw.transformPoint;
}
if (m.constructor.prototype.toIdentity === undefined) {
m.constructor.prototype.toIdentity = sw.toIdentity;
}
if (hasErrors === true) {
throw new Error("Could not install setAttributes on all elements");
}
document.constructor.prototype.loadContent = sw.loadContent;
sw.initIds(documentElement);
// Make the root 'svg' element available in the global scope
if (isSVG) {
scope.svg = documentElement;
}
}
/**
* Processes ids on elements and sets a variable of that name on their parents.
*
* @param elt the element to process. Its children are processed recursively.
*/
sw.initIds = function (elt) {
var id = elt.id;
if (id !== undefined &&
id !== null &&
id !== "" &&
(typeof id === "string") &&
elt.parentNode !== undefined &&
elt.parentNode !== null &&
elt.parentNode[id] === undefined) {
sw.addElementShortHand(id, elt, elt.parentNode);
}
var c = elt.firstChild;
while (c !== null) {
if (c.nodeType === Node.ELEMENT_NODE) {
sw.initIds(c);
}
c = c.nextSibling;
}
}
/**
* Adds a property of the name "id" to the parent chain, starting with the
* parent parameter. If the parent itself has an id, then the property is set
* on that node. Otherwise, the property is set on the first ancestor with an
* id
*
* @param id the name of the property to set
* @param node the value of the property to set
* @param parent the first candidate parent on which the property might be set
*/
sw.addElementShortHand = function(id, node, parent) {
// Note that parent.id is the value of the 'id' attribute on parent
// whereas parent[id] is the value of the property with the name of the
// id parameter (e.g., 'myRect') on parent.
if (parent.id !== undefined && parent.id !== "") {
if (parent[id] === undefined) {
parent[id] = node;
}
} else if (parent.parentNode !== null && parent.parentNode !== parent) {
sw.addElementShortHand(id, node, parent.parentNode);
} else {
if (document[id] === undefined) {
document[id] = node;
}
}
}
/**
* Helper method to find out if an element is a descendant of a given parent
* node.
*
* @param candidate the element that may be the descendant of the parent.
* @param parent the parent under which the candidate may be
*/
sw.isDescendantOf = function (candidate, parent) {
var isDescendant = false;
var p = candidate;
while (p !== parent && p.parentNode !== null) {
p = p.parentNode;
}
return (p === parent);
}
/**
* Helper method: converts a <code>String</code> to an <code>Element</code>
* and throws an error if the element cannot be found. If the parameter is
* not a string, it is returned as is.
*/
sw.stringToElement = function (p_element) {
var element = p_element;
if (typeof p_element === "string") {
element = document.getElementById(p_element);
}
if (element === null) {
throw new Error ("Could not find element with id " + p_element);
}
return element;
}
})();/res/2.0/scripts/utils/ez-transform.js
/** =======================================================================
* Vincent Hardy
* License terms: see svg-wow.org
* CC0 http://creativecommons.org/publicdomain/zero/1.0/
* ======================================================================= */
sw.utils = sw.utils || {};
/**
* An easy transform wrapper provides a simple way to manipulate an object.
* The <code>rotate</code>, <code>scale</code> methods rotate the object
* about its anchor point (center by default).
*
* @param p_wrapped the element to wrap. A <code>String</code> or an element.
* @param p_oName optional. Name for the EZTransform container instance.
*/
sw.utils.EZTransform = function (p_wrapped, p_oName) {
this.initialize(p_wrapped, p_oName);
};
sw.utils.EZTransform.prototype = {
translateTemplate: "translate(#tx,#ty)",
scaleTemplate: "scale(#s)",
rotateTemplate: "rotate(#r)",
initialize : function (p_wrapped, p_oName) {
/**
* The wrapped element
*/
var wrapped = null;
// Load the wrapper structure.
this.element = sw.loadContent.call(null, {
// moveTo group
tag: "g",
name: p_oName === undefined? "moveToGroup" : p_oName,
children: [
{
// scale group
tag: "g",
name: "scaleGroup",
children: [
{
// rotate group
tag: "g",
name: "rotateGroup",
children: [
{
// anchor group
tag: "g",
name: "anchorGroup",
children: [
// element goes here.
]
}
]
}
]
}
]
});
var moveToGroup = this.element;
var scaleGroup = moveToGroup.firstChild;
var rotationGroup = scaleGroup.firstChild;
var anchorGroup = rotationGroup.firstChild;
/**
* Sets the wrapped element.
*
* @param p_wrapped
*/
function setWrapped (p_wrapped) {
// First, remove the existing content if any
anchorGroup.removeAllChildren();
wrapped = null;
if (p_wrapped !== null) {
wrapped = sw.stringToElement(p_wrapped);
}
if (wrapped !== null) {
anchorGroup.appendChild(wrapped);
}
}
this.setWrapped = setWrapped;
setWrapped(p_wrapped);
// Used by moveTo
this.x = 0;
this.y = 0;
/**
* Moves the anchor to the given location.
*
* @param p_x position along the x-axis
* @param p_y position along the y-axis
*/
this.moveTo = function (p_x, p_y) {
if (this.x !== p_x || this.y !== p_y) {
this.x = p_x;
this.y = p_y;
var transform = "translate(".concat(this.x).
concat(",").concat(this.y).
concat(")");
moveToGroup.setAttribute("transform",
this.translateTemplate.replace("#tx", this.x).
replace("#ty", this.y));
}
}
// Used by rotate
this.rotation = 0;
/**
* Rotates this thumbnail by the given angle
*
* @param p_rotation rotation angle in degrees
*/
this.rotate = function (p_rotation) {
if (p_rotation !== this.rotation) {
this.rotation = p_rotation;
rotationGroup.setAttribute("transform",
this.rotateTemplate.replace("#r", this.rotation));
}
}
// Used by scale
this.scaleFactor = 1;
/**
* Scales this thumbnail by the given factor
*
* @param p_scaleFactor the amount of scaling
*/
this.scale = function (p_scaleFactor) {
if (p_scaleFactor !== this.scaleFactor) {
this.scaleFactor = p_scaleFactor;
scaleGroup.setAttribute("transform",
this.scaleTemplate.replace("#s", this.scaleFactor));
}
}
var curBBox = document.documentElement.createSVGRect();
/**
* Anchors the current element using its current bounding box.
*/
this.anchor = function () {
var bbox = wrapped.getBBox();
var tx, ty, transform;
if (curBBox.x !== bbox.x ||
curBBox.y !== bbox.y ||
curBBox.width !== bbox.width ||
curBBox.height !== bbox.height) {
// Anchor about center.
tx = -bbox.x - bbox.width / 2;
ty = -bbox.y - bbox.height / 2;
wrapped.setAttribute("transform",
this.translateTemplate.replace("#tx", tx).
replace("#ty", ty));
curBBox.x = bbox.x;
curBBox.y = bbox.y;
curBBox.width = bbox.width;
curBBox.height = bbox.height;
}
}
}
}