summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2021-02-10 08:30:40 -0600
committerColin Okay <okay@toyful.space>2021-02-10 08:30:40 -0600
commit763244469fc82d0bcff663204583de9287e0fb84 (patch)
tree856296ae8cba9647270ff2ca4e65279b9697692b
parent9c09300a671e4ee7db507cf943fff31981de1a45 (diff)
safeish fade effect
-rw-r--r--Source/Main.hx30
1 files changed, 26 insertions, 4 deletions
diff --git a/Source/Main.hx b/Source/Main.hx
index d6fc3bf..3146f89 100644
--- a/Source/Main.hx
+++ b/Source/Main.hx
@@ -11,7 +11,7 @@ import openfl.utils.Timer;
import openfl.display.SimpleButton;
import openfl.text.TextField;
import openfl.text.TextFormat;
-
+import motion.Actuate;
import haxe.ds.Option;
using Lambda;
@@ -102,6 +102,7 @@ class DrawingScreen extends Sprite
suitable for passing in as the "skin" of a wiggler. */
var path: Array<Point> = [];
+ var holdPath:Bool = false;
public function new ()
{
@@ -133,18 +134,37 @@ class DrawingScreen extends Sprite
function onMouseDown (e)
{
+ trace('onMouseDown');
+ refresh();
drawing = true;
timestamp = haxe.Timer.stamp();
path = [ new Point(e.localX, e.localY) ];
- graphics.clear();
graphics.lineStyle(3, 0);
graphics.moveTo( path[0].x, path[0].y );
}
+ function refresh ()
+ {
+ Actuate.stop(this);
+ graphics.clear();
+ alpha = 1.0;
+ visible = true;
+ path = [];
+ holdPath = false;
+ }
+
+ function fadeAndRefresh()
+ {
+ Actuate
+ .tween(this, 0.5, {alpha: 0})
+ .onComplete( refresh );
+ }
+
function onMouseUp (e)
{
drawing = false;
+ if (!holdPath) fadeAndRefresh();
}
function onMouseOut (e)
@@ -164,16 +184,18 @@ class DrawingScreen extends Sprite
function onMouseMove (e)
{
+ if (!drawing) return;
+
var stamp = haxe.Timer.stamp();
var pt = new Point( e.localX, e.localY);
- if (drawing &&
- (stamp - timestamp > sampleRate) &&
+ if ((stamp - timestamp > sampleRate) &&
Point.distance(pt, path[path.length - 1]) >= sampleGap)
{
var intersectIndex = GeomTools.findSelfIntersection( path, pt );
if (intersectIndex != null)
{
drawing = false;
+ holdPath = true;
var intersectionPt =
GeomTools.linesIntersectAt( path[intersectIndex],
path[intersectIndex + 1],