paper.js/examples/Animated/RadialRainbows.html
2011-05-03 08:54:13 +01:00

71 lines
No EOL
1.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript">var root = '../../'</script>
<script type="text/javascript" src="../../src/load.js"></script>
<script type="text/paperscript" canvas="canvas">
var vector = new Point(document.size.height, 0);
var point = new Point(document.size) / 2;
var colors = [];
for (var i = 0, l = 60; i < l; i++) {
var color = new RGBColor(1, 0, 0);
var cycles = 4;
color.hue = i / l * cycles * 360;
colors.push(color);
}
var gradient = new Gradient(colors, 'radial');
var gradientColor = new GradientColor(gradient, point, point + vector);
var path = new Path.Rectangle(new Rectangle([0, 0], document.size));
path.fillColor = gradientColor;
tool.eventInterval = 30;
var mouseDown = false;
function onMouseDown(event) {
point = point + vector;
mouseDown = true;
}
function onMouseDrag(event) {
point = point + (event.point - point) / 10;
gradientColor.hilite = point;
iterate();
}
function onMouseUp(event) {
vector.length = 10;
mouseDown = false;
}
var grow = false;
var vector = new Point(150, 0);
setInterval(draw, 30);
function draw() {
if (!mouseDown) {
iterate();
document.redraw();
}
}
function iterate() {
for (var i = 0, l = gradient.stops.length; i < l; i++)
gradient.stops[i].color.hue -= 20;
if (grow && vector.length > 300) {
grow = false;
} else if (!grow && vector.length < 75) {
grow = true;
}
vector.length += (grow ? 1 : -1);
vector.angle += 5;
gradientColor.hilite = mouseDown ? point : point + vector;
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>