class: Filigree
[51:7] extends: object
A filigree pattern that draws itself across the AGR FXGL window the way a climbing plant grows. Build one and call run(). A seed lands a little way in from a random edge and sends two or three stems out from it. Each stem is drawn one short step at a time and turns a little more sharply with every step, so it sets off on a wide sweep and winds into a scroll at its end. Partway along, a stem throws off a branch to either side, and those branches do the same, three generations deep. Every tendril that reaches its full length finishes with a small round flourish. The whole pattern takes growSeconds to draw, holds while it is finished, then fades away and clears itself out of the game world. The numbers at the top of the class are the dials. Change them to alter the timing, the shape of the scrolls, or how much of the window the pattern fills.
Members
- growSeconds
- holdSeconds
- fadeSeconds
- stepsPerSecond
- checkSeconds
- minStems
- maxStems
- stemFan
- aimJitter
- seedInset
- maxDepth
- firstBranchAt
- secondBranchAt
- branchAngle
- minLifeSteps
- stemLifeFraction
- childLifeFactor
- stemReach
- stemTurn
- curlRatio
- stemWidth
- widthFactor
- flourishScale
- leafEvery
- leafLean
- leafLength
- leafFatness
- leafOpenSteps
- leafAlpha
- colors
- glowLevel
- plant
- canvas
- tips
- leafLayer
- leafShade
- opening
- tick
- totalTicks
- clock
- startedAt
- growJob
- stepLen
- seedX
- seedY
- windowWidth
- windowHeight
Methods
-
run ()
Starts the pattern. run() plants the seed and its stems and hands back straight away; the drawing itself happens on a timer over the next growSeconds. 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 pattern, already attached to the game world.
- @r
-
total ()
How long the whole pattern takes: drawing, holding, and fading.
- @r
double- the total time in seconds.
- @r
-
growStep ()
Brings the drawing up to date with the clock. The timer calls this over and over while the pattern is growing, and it takes however many steps are due since the last time it ran -- usually one, and more if the game has been busy. It stops the growth once the whole drawing has been taken or there is nothing left growing. Safe to call before run(), when it has nothing to do.
- @r
thisobject
- @r
-
stepsDue ()
How many growth steps the drawing should have taken by now, read off the game clock rather than counted from the timer's firings. Never more than the whole drawing.
- @r
int- the step the drawing is due to have reached.
- @r
-
stopGrowing ()
Stops the growth job, if it is still running.
- @r
thisobject
- @r
-
takeStep ()
Takes one growth step: every tendril still growing gains a segment, throws a branch if it has reached the point in its life to do so, and drops out of the list once it is finished or has left the window.
- @r
thisobject
- @r
-
fadeOut ()
Fades the whole pattern out once it has stood finished for holdSeconds. The timer calls this.
- @r
thisobject
- @r
-
clearUp ()
Takes the pattern out of the game world once it has faded. The timer calls this.
- @r
thisobject
- @r
-
raiseStems (
double Aim, int StemLife, double Width)Sends the stems out from the seed, fanned either side of straight in and each curling back the way it leant.
- @p
Aimis the heading straight in from the seed's edge, in radians. - @p
StemLifeis how many growth steps a stem gets. - @p
Widthis the stem line width in pixels. - @r
thisobject
- @p
-
advance (
map Tip)Moves a tendril on by one segment: works out where the next point goes, adds it to the line, and sharpens the turn ready for the step after.
- @p
Tipis the tendril, which is changed in place. - @r
thisobject
- @p
-
branch (
map Parent, double Side)Starts a branch off a tendril at the point it has reached. The branch is shorter and thinner than its parent and leans to the given side, and it is not started at all if there is not enough of the drawing left to make anything of it.
- @p
Parentis the tendril the branch leaves. - @p
Sideis which way it leans and curls: 1.0 or -1.0. - @r
map- the new tendril, or null if there was no room for one.
- @p
-
newTip (
double X, double Y, double Angle, double Side, int Life, int Depth, double Width, string Shade)Builds a tendril and the line it draws itself with, and works out the scroll it will wind into. The turn per step is multiplied by the same amount every step, so the turns make a geometric series. Asking for a total of stemTurn radians over Life steps, ending curlRatio times sharper than it began, fixes both the multiplier and the turn to start from.
- @p
Xis where the tendril starts, across, in entity coordinates. - @p
Yis where the tendril starts, down, in entity coordinates. - @p
Angleis the heading it sets off on, in radians. - @p
Sideis which way it curls: 1.0 or -1.0. - @p
Lifeis how many growth steps it gets. Must be two or more. - @p
Depthis how many branches back to the stem, 0 for a stem. - @p
Widthis its line width in pixels. - @p
Shadeis its colour as a web hex string. - @r
map- the new tendril, with its first leaf already due.
- @p
-
sprout (
map Tip)Puts a leaf out from where a tendril has reached, leaning off the way it is heading. The leaf starts at nothing and is opened out by openLeaves over the next few steps.
- @p
Tipis the tendril putting the leaf out. - @r
thisobject
- @p
-
openLeaves ()
Opens every leaf that has not reached its full size by one step, and drops the ones that have. Only a handful are ever opening at once, so this is a good deal cheaper than it looks.
- @r
thisobject
- @r
-
leafShape (
map Leaf, double Length)A leaf as an SVG path: a point at each end and a curve down either side, which is the shape two quadratic curves make when their control points sit either side of the middle.
- @p
Leafis the leaf, which holds where it grew and which way. - @p
Lengthis how long to draw it, in pixels. - @r
string- the path.
- @p
-
flourish (
map Tip)Puts a small round flourish on the end of a finished tendril.
- @p
Tipis the tendril that has just run out of life. - @r
thisobject
- @p
-
seedOnEdge (
int Edge, double Width, double Height, double Inset)Drops the seed a little way in from a random point along one edge of the window. The point stays well in from the corners too, so the pattern has window to spread into either way along the edge.
- @p
Edgeis the edge: 0 top, 1 right, 2 bottom, 3 left. - @p
Widthis the window width in pixels. - @p
Heightis the window height in pixels. - @p
Insetis how far in from the edge to sit, in pixels. - @r
thisobject
- @p
-
inwardAngle (
int Edge)The heading that points into the window from a given edge, leaned over by up to aimJitter so the pattern does not always grow square to its edge. Angles are measured the way the screen is drawn, with Y growing downwards, so a quarter turn heads down the window rather than up.
- @p
Edgeis the edge: 0 top, 1 right, 2 bottom, 3 left. - @r
double- the heading in radians.
- @p
-
inWindow (
double X, double Y)Whether a point on a tendril is still inside the window. Tendrils are drawn in the entity's own coordinates, which start at the seed, so the seed has to be added back on first.
- @p
Xis the point across, in entity coordinates. - @p
Yis the point down, in entity coordinates. - @r
bool- true when the point is on screen.
- @p