paper.js/examples/Animated/RadialRainbows.html

74 lines
1.8 KiB
HTML
Raw Normal View History

2011-02-21 08:31:26 -05:00
<!DOCTYPE html>
2011-02-19 16:52:27 -05:00
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
2011-03-07 20:07:26 -05:00
<script type="text/javascript">var root = '../../'</script>
<script type="text/javascript" src="../../src/load.js"></script>
2011-03-04 06:38:38 -05:00
<script type="text/paperscript" canvas="canvas">
var vector = new Point(document.size.height, 0);
var point = new Point(document.size) / 2;
var gradient = new Gradient();
gradient.type = 'radial';
var gradientColor = new GradientColor(gradient, point, point + vector);
var stops = [];
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;
var stop = new GradientStop(color, i / l);
2011-03-04 06:38:38 -05:00
stops.push(stop);
}
gradient.stops = stops;
var path = new Path.Rectangle(new Rectangle([0, 0], document.size));
path.fillColor = gradientColor;
tool.eventInterval = 30;
2011-03-04 06:38:38 -05:00
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;
}
2011-02-19 16:52:27 -05:00
2011-03-04 06:38:38 -05:00
var grow = false;
var vector = new Point(150, 0);
setInterval(draw, 30);
2011-03-04 06:38:38 -05:00
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;
2011-03-04 06:38:38 -05:00
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;
2011-02-19 16:52:27 -05:00
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>