mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Make the RadialRainbows example interaction smoother.
This commit is contained in:
parent
df0c95e41f
commit
1ae89049ed
1 changed files with 13 additions and 6 deletions
|
@ -30,15 +30,18 @@
|
||||||
var mouseDown = false;
|
var mouseDown = false;
|
||||||
|
|
||||||
function onMouseDown(event) {
|
function onMouseDown(event) {
|
||||||
|
point = point + vector;
|
||||||
mouseDown = true;
|
mouseDown = true;
|
||||||
gradientColor.hilite = event.point;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseDrag(event) {
|
function onMouseDrag(event) {
|
||||||
gradientColor.hilite = event.point;
|
point = point + (event.point - point) / 10;
|
||||||
|
gradientColor.hilite = point;
|
||||||
|
iterate();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseUp(event) {
|
function onMouseUp(event) {
|
||||||
|
vector.length = 10;
|
||||||
mouseDown = false;
|
mouseDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +49,13 @@
|
||||||
var vector = new Point(150, 0);
|
var vector = new Point(150, 0);
|
||||||
setInterval(draw, 30);
|
setInterval(draw, 30);
|
||||||
function draw() {
|
function draw() {
|
||||||
|
if (!mouseDown) {
|
||||||
|
iterate();
|
||||||
|
document.redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function iterate() {
|
||||||
for(var i = 0, l = gradient.stops.length; i < l; i++)
|
for(var i = 0, l = gradient.stops.length; i < l; i++)
|
||||||
gradient.stops[i].color.hue -= 20;
|
gradient.stops[i].color.hue -= 20;
|
||||||
if (grow && vector.length > 300) {
|
if (grow && vector.length > 300) {
|
||||||
|
@ -55,10 +65,7 @@
|
||||||
}
|
}
|
||||||
vector.length += (grow ? 1 : -1);
|
vector.length += (grow ? 1 : -1);
|
||||||
vector.angle += 5;
|
vector.angle += 5;
|
||||||
if (!mouseDown) {
|
gradientColor.hilite = mouseDown ? point : point + vector;
|
||||||
gradientColor.hilite = point + vector;
|
|
||||||
document.redraw();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in a new issue