class: Fractals
[48:7] extends: object
A fractal curve that the AGR FXGL window flies into, closing in on one point of it for ten seconds. Build one and call run(). The window starts with the whole curve in view and ends hundreds of times closer in. Because the curve is the same shape at every scale, there is always more of it to find: detail too fine to see at the start is what fills the window at the end. Two curves are on offer and one is picked at random. Both are built by the same rule -- take a straight line, replace it with a set of shorter lines, and do the same to each of those forever: snowflake a Koch snowflake, whose every edge grows a peak gasket a Sierpinski gasket, drawn as one unbroken line The numbers at the top of the class are the dials. Change them to alter the timing, how far in it goes, or how fine the drawing is.
Members
- zoomSeconds
- holdSeconds
- fadeSeconds
- zoomDepth
- checkSeconds
- rebuildFactor
- stepsPerFrame
- viewMargin
- maxLeaves
- targetDepth
- maxDepth
- lineWidth
- haloWidth
- haloAlpha
- colors
- curves
- plant
- path
- halo
- curveName
- rulePts
- ruleFlips
- detail
- stray
- base
- targetX
- targetY
- zoomStart
- builtAt
- buildingAt
- halfAcross
- halfDown
- clock
- startedAt
- zoomJob
- pending
- parts
- leaves
- penDown
Methods
-
run ()
Starts the fly in. run() draws the whole curve and hands back straight away; the window then closes in on it over the next zoomSeconds. The entity fades out and clears itself out of the game world when the whole thing is over. Only works inside AGR, which has the FXGL game already running.
- @r
Entity- the curve, already attached to the game world.
- @r
-
newStroke (
string Shade, double Alpha, double Width)Builds one of the two strokes the curve is drawn with.
- @p
Shadeis the colour as a web hex string. - @p
Alphais how solid it is, 0.0 to 1.0. - @p
Widthis how wide it is drawn, in pixels. - @r
SVGPath- the stroke, with no shape set yet.
- @p
-
total ()
How long the whole thing takes: flying in, holding, and fading.
- @r
double- the total time in seconds.
- @r
-
name ()
Which curve this one picked, "snowflake" or "gasket".
- @r
string- the curve's name, or "" before run().
- @r
-
zoomStep ()
Brings the view up to date with the clock. The timer calls this over and over while the window is closing in: it works out how close the view should be by now, gets on with the next redraw, and stretches what is on screen to cover the difference. Safe to call before run(), when it has nothing to do.
- @r
thisobject
- @r
-
fadeOut ()
Fades the curve out once the window has held still for holdSeconds. The timer calls this.
- @r
thisobject
- @r
-
clearUp ()
Takes the curve out of the game world once it has faded. The timer calls this.
- @r
thisobject
- @r
-
stopZooming ()
Stops the fly in job, if it is still running.
- @r
thisobject
- @r
-
startBuild (
double Zoom)Lines up a fresh drawing of the curve for a given closeness. The work itself is left to advanceBuild. The rule that grows the curve is a similarity -- it turns straight lines into straight lines and keeps every shape -- so growing the curve and then scaling it to the window gives the same picture as scaling first and growing after. Scaling first is what this does, which is why every length measured from here on is already in pixels and can be held against the detail straight off.
- @p
Zoomis how many pixels one unit of the curve covers. - @r
thisobject
- @p
-
advanceBuild ()
Works through the drawing for as long as one frame can spare, and puts it on screen once there is nothing left to look at.
- @r
thisobject
- @r
-
finishBuild ()
Hands the finished drawing to both strokes at once, so the picture never shows half of one drawing and half of another.
- @r
thisobject
- @r
-
step (
double Ax, double Ay, double Bx, double By, bool Flip, int Depth)Deals with one straight line: drops it, grows it, or draws it. Two things stop a line from growing. One whose finished stretch of curve cannot reach the window is dropped whole, which is what keeps a drawing to the size of the window rather than the size of the curve. One already shorter than the detail is drawn as it is, since growing it further would not change a pixel.
- @p
Axis the line's starting position across, in pixels. - @p
Ayis the line's starting position down, in pixels. - @p
Bxis the line's finishing position across, in pixels. - @p
Byis the line's finishing position down, in pixels. - @p
Flipis true when the rule is applied mirrored here. - @p
Depthis how many times the rule has been applied to get here. - @r
thisobject
- @p
-
childOf (
double Ax, double Ay, double Bx, double By, bool Flip, int Index)One of the shorter lines the rule replaces a line with. The rule's points are given in a frame where the line runs from (0, 0) to (1, 0), so they are read back out along the line itself and square to it. Mirroring is a matter of taking "square to it" the other way.
- @p
Axis the line's starting position across. - @p
Ayis the line's starting position down. - @p
Bxis the line's finishing position across. - @p
Byis the line's finishing position down. - @p
Flipis true when the rule is applied mirrored here. - @p
Indexis which of the shorter lines is wanted, from 0. - @r
list- the shorter line as [ax, ay, bx, by, flip].
- @p
-
offScreen (
double Ax, double Ay, double Bx, double By, double Pad)Whether a line and everything it can still grow into lie clear of the window.
- @p
Axis the line's starting position across, in pixels. - @p
Ayis the line's starting position down, in pixels. - @p
Bxis the line's finishing position across, in pixels. - @p
Byis the line's finishing position down, in pixels. - @p
Padis how far the finished curve can stray from the line. - @r
bool- true when none of it can show.
- @p
-
strayOf ()
How far a finished stretch of curve can stray from the straight line it grew out of, as a multiple of that line's length. The rule's own points stray by at most the largest of their square measurements. Each shorter line then strays by the same multiple of its own length, and the longest of them is some fraction of the line above it, so the multiple s satisfies s = square + fraction x s.
- @r
double- the multiple.
- @r
-
baseTriangle ()
The three straight lines the curve grows from: a triangle a unit across, drawn corner to corner. The curve's own size does not matter, since run() works out how far out to start from the point it settles on.
- @r
list- three lines, each [ax, ay, bx, by].
- @r
-
pickTarget ()
Settles on the point the window closes in on, by starting from one of the base lines and stepping down into a shorter line of it over and over. Going far deeper than the fly in can ever reach makes it a point of the curve itself, so there is always more of the curve around it however close the window gets.
- @r
thisobject
- @r
-
reach ()
How far the curve reaches from the point being flown into, in the curve's own units. The corners of the base triangle are as far out as its straight lines go, and the curve grown on them strays a little further still.
- @r
double- the distance.
- @r