summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2021-02-11 09:39:31 -0600
committerColin Okay <okay@toyful.space>2021-02-11 09:39:31 -0600
commitdb9a109f6253a5a4de878817c0e2ac461e644a73 (patch)
tree3c3d0716e6b7e341a3807c33743bd11f865a4ea2
parent25751281965207ca246f815de6f6750f50033a6e (diff)
generalized linesIntersect fn, using grid based cirle packing
-rw-r--r--Source/Main.hx31
1 files changed, 24 insertions, 7 deletions
diff --git a/Source/Main.hx b/Source/Main.hx
index 99f3932..c762e02 100644
--- a/Source/Main.hx
+++ b/Source/Main.hx
@@ -140,13 +140,21 @@ class Wiggler extends Sprite
{
var bbox = GeomTools.pathBoundingBox( path );
var rad = radiusGradient * radiiSizes;
+ var step = 0.9;
while (rad > 0)
{
- for (i in 0 ... CIRCLE_TRIALS)
- {
- var circ = randomCircle( bbox, rad );
- if (isValidCircle( circ )) circles.push(circ);
- }
+ for (cx in 0...Std.int(bbox.width / (step * rad)))
+ for (cy in 0...Std.int(bbox.height / (step * rad)))
+ {
+ var circ = {
+ x: cx * step * rad,
+ y:cy * step * rad,
+ radius:rad,
+ color: Std.int(Math.random() * 0xFFFFFF)
+ };
+
+ if (isValidCircle( circ )) circles.push( circ );
+ }
rad -= radiusGradient;
}
}
@@ -333,10 +341,17 @@ enum Line {
class GeomTools
{
+ public static function randomBetween(lo:Float,hi:Float):Float
+ {
+ if (hi < lo) return randomBetween(hi, lo);
+
+ return Math.random() * (hi - lo) + lo;
+ }
+
public static function circlesIntersect<C1:Circle,C2:Circle>(c1:C1,c2:C2):Bool
{
var d = dist(c1,c2);
- return d <= c1.radius + c2.radius;
+ return d < c1.radius + c2.radius;
}
public static function pathBoundingBox( path:Array<Point> ):Null<Rectangle>
@@ -495,7 +510,9 @@ class GeomTools
}
- public static function linesIntersectAt(a:Point,b:Point,c:Point,d:Point):Null<Point>
+ public static function linesIntersectAt
+ <P1:PointType,P2:PointType,P3:PointType,P4:PointType>
+ (a:P1,b:P2,c:P3,d:P4):Null<Point>
{
var segments = [lineOfSegment(a, b), lineOfSegment(c, d)];
switch (segments)