From 1ae89049ed7f1abadd7657693b204afbfec49511 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Wed, 9 Mar 2011 17:08:20 +0100 Subject: [PATCH] Make the RadialRainbows example interaction smoother. --- examples/Animated/RadialRainbows.html | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/Animated/RadialRainbows.html b/examples/Animated/RadialRainbows.html index 437fc8bb..b2706374 100644 --- a/examples/Animated/RadialRainbows.html +++ b/examples/Animated/RadialRainbows.html @@ -30,15 +30,18 @@ var mouseDown = false; function onMouseDown(event) { + point = point + vector; mouseDown = true; - gradientColor.hilite = event.point; } function onMouseDrag(event) { - gradientColor.hilite = event.point; + point = point + (event.point - point) / 10; + gradientColor.hilite = point; + iterate(); } function onMouseUp(event) { + vector.length = 10; mouseDown = false; } @@ -46,6 +49,13 @@ 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) { @@ -55,10 +65,7 @@ } vector.length += (grow ? 1 : -1); vector.angle += 5; - if (!mouseDown) { - gradientColor.hilite = point + vector; - document.redraw(); - } + gradientColor.hilite = mouseDown ? point : point + vector; }