paper.js/examples/Animated/RadialRainbows.html

82 lines
No EOL
2.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript">var root = '../../'</script>
<script type="text/javascript" src="../../src/load.js"></script>
<script type="text/paperscript" canvas="canvas">
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 path = new Path.Rectangle(document.bounds);
var gradient = new Gradient(colors, 'radial');
var radius = Math.max(document.size.height, document.size.width) * 0.75;
var gradientColor = new GradientColor(gradient, point, point + [radius, 0]);
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;
}
function onFrame() {
if (!mouseDown)
iterate();
}
var grow = false;
var vector = new Point(150, 0);
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;
}
DomEvent.add(window, {
resize: function(event) {
point = new Point(document.size) / 2;
path.bounds = document.bounds;
var radius = Math.max(document.size.height, document.size.width) * 0.75;
var gradientColor = path.fillColor;
gradientColor.origin = point;
var radius = Math.max(document.size.height, document.size.width) * 0.75;
gradientColor.destination = point + [radius, 0];
}
});
</script>
</head>
<body>
<canvas id='canvas' resize></canvas>
</body>