/***********************************************************************
ifs-inventions v1.01 (31 March 2020)

Copyright 2020 Herman Johannes Haverkort

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

This file is part of the pftrail package. 
The package includes the following files:

* pftrail.cpp
* ifs-classics
* ifs-inventions
* generate-preamble.cpp
* colours
* postamble
* manual.pdf

New versions of the package may be available from 
http://spacefillingcurves.net or http://herman.haverkort.net.

************************************************************************

Curves/traversals in this file:

Traversals filling polygons...

...in two parts:
* golden-b
* silver-rectangle-{d,f,g,j}

...in three parts:
* tribonacci-quadrilateral

...in four parts:
* golden-trapezoid
* golden-right-triangle
* golden-isosceles-triangle
* 60-90-trapezoid-{a,b}

Traversals filling fractals:
* schraa-{1,3,4,5}
* peano-ballet
* peano-railroads
* peano-waters
* ventrellas-family
* gosper-stairway
* ventrellas-groovy-crosser

******************************************************/

/******************************************************
Many traversals in this file come with a specific 
view/rendering configuration. To ignore this and use 
the default view/rendering configuration instead, use 
"-c :default" to use the default view:
******************************************************/

view default

/******************************************************
Scherer's Golden b

   Source of the underlying tessellation:

   Karl Scherer:
   A puzzling journey to the reptiles and related animals, 
   self-published, 1986.
******************************************************/
// Scherer's Golden b is possibly the only non-convex 
// polygon that can be tiled with two smaller copies of 
// itself. A corresponding single-generator plane-
// filling curve does not exist, but several traversals 
// are possible, such as:

IFS golden-b

Square grid
3 segments

segment values:

// 1: 1,        phi^{3/2}, 1, -1
// 2: -2 phi^2, 0,         0,  0
// 3: phi^2,    phi^{1/2}, 1,  1 
// (where phi is the golden ratio (1+sqrt(5))/2

1: 1, 2.058171027271492, 1, -1
2: -5.23606797749979, 0, 0, 0
3: 2.618033988749895, 1.272019649514069, 1, 1

Ridge -1
Altitude 30
Azimuth 30

/******************************************************
Silver-Rectangle traversals
******************************************************/
// In addition to the silver-rectangle variants of 
// Z-order, Gray code, Double-Gray code, and Inside-
// Out, several other single-generator, two parts'
// traversals of sqrt(2):1 rectangles are possible. 
// For example:

IFS silver-rectangle-d

Square grid
3 segments

segment values:
1: -1, 1.414213562373095, 1, 1
2:  4,-1.414213562373095, 0, 0
3: -1, 1.414213562373095, 1, 1

Ridge -1


// the next one deserves a better name: note how it
// complements silver-gray, silver-double-gray, and
// silver-inside-out: these three curves and the 
// one below differ only in the signs of the last
// parameters of the segments, and together they 
// constitute all four possible combinations:

IFS silver-rectangle-f

Square grid
3 segments

segment values:
1: 0, 1.414213562373095, 1, 1
2: 2, 0,                 0, 0
3: 0,-1.414213562373095,-1,-1

Ridge -1
Altitude 35
Azimuth -60


IFS silver-rectangle-g

Square grid
3 segments

segment values:
1: 2, 1.414213562373095, 1,-1
2: 2, 0,                 0, 0
3:-2, 1.414213562373095,-1,-1

Render 0.632,-0.447,1,1
Ridge 1
Azimuth -35


IFS silver-rectangle-j

Square grid
2 generators
// this is really a single-generator traversal,
// but an additional starter generator is provided
// to create a tunnel towards the starting point,
// which lies in the interior of the rectangle

generator A:
3 segments

segment values:
// sentinel to start the tunnel:
1: 0, 0,                 B, 1, 1
// the tunnel (it enters the rectangular image at 
// 1/3 of its length, so that is not too narrow at 
// the point of entry): 
2: 3,-2.82842712474619,  X
// the actual traversal:
3: 3, 1.414213562373095, B, 1, 1

generator B:
3 segments

segment values:
// 2.12... = (3/2) sqrt(2); 2.82... = 2 sqrt(2)
1:-1, 2.121320343559643, B, 1, 1
2: 3,-2.82842712474619,  X
3: 1, 2.121320343559643, B,-1, 1

Render 0.3656, -0.9308, 1, 1
Ridge -1

/******************************************************
Tribonacci-Quadrilateral curve
******************************************************/
// a curve with a structure similar to Peano's curve,
// based on a quadrilateral cut into three pieces with 
// area ratio 1:c:c^2, where c is the Tribonacci 
// constant (real root of c^3 - c^2 - c - 1).

IFS tribonacci-quadrilateral

Square grid
3 segments

segment values:

// 1: c^2, -c,  1, -1
// 2: 0,   c+1, 1,  1
// 3: c,   -1,  1, -1

1:  3.38297577, -1.83928676,  1, -1
2:  0,           2.83928676,  1,  1
3:  1.83928676, -1,           1, -1

/******************************************************
Golden-Trapezoid curve
******************************************************/
// a curve with a structure similar to Hilbert's curve,
// filling a trapezoid with dimensions based on the 
// golden ratio phi = (1+sqrt(5))/2

IFS golden-trapezoid

Square grid
4 segments

segment values:

// 1: 1,     sqrt(2 phi),  1, -1
// 2: phi^2, 0,            1,  1
// 3: phi,   0,            1,  1
// 4: -1,    -sqrt(2 phi), 1, -1

1:  1,           1.79890744,  1, -1
2:  2.61803399,  0,           1,  1
3:  1.61803399,  0,           1,  1
4: -1,          -1.79890744,  1, -1

ridge 0.61803399

/******************************************************
Golden-Right-Triangle curve
******************************************************/
// one of several options to fill a right triangle 
// whose legs have ratio sqrt(phi), where phi is the
// golden ratio 

IFS golden-right-triangle

Square grid
4 segments

segment values:

// 1: 0,   sqrt(phi),  1, -1
// 2: 1,   0,          1,  1
// 3: 0,   -sqrt(phi), 1, -1
// 4: phi, 0,          1,  1

1:  0,           1.27201965,  1, -1
2:  1,           0,           1,  1
3:  0,          -1.27201965,  1, -1
4:  1.61803399,  0,           1,  1

/******************************************************
Golden-Isosceles-Triangle curve
******************************************************/
// one of several options to fill an isosceles triangle 
// with leg-to-base ratio sqrt(phi), where phi is the
// golden ratio 

IFS golden-isosceles-triangle

Square grid
4 segments

segment values:

// 1:  1,     sqrt(4 phi - 1),  1, -1
// 2:  2 phi, 0,                1,  1
// 3: -1,     -sqrt(4 phi - 1), 1, -1
// 4:  2,     0,               -1,  1
 
1:  1,           2.33925970,  1, -1
2:  3.23606798,  0,           1,  1
3: -1,          -2.33925970,  1, -1
4:  2,           0,          -1,  1

Render 1.169630,0.118034,-1,1
Ridge 0.381966
Azimuth 28

/******************************************************
60-90 Trapezoid
******************************************************/
// Two discontinuous traversals for the trapezoid with
// edge length / angle sequence 
// 1, 90 deg, sqrt(3), 90 deg, 2, 60 deg, 2, 120 deg

IFS 60-90-trapezoid-a

Cubic grid
5 segments

segment values:
1: 1, 0, 0, 1,-1
2: 0,-1, 0, 1, 1
3: 0, 0, 1, 0, 0
4: 0, 0,-1, 1, 1
5: 0, 0, 1,-1, 1

Azimuth 20

view 60-90-trapezoid-a-2

Render 0.866,-0.5,1,1
Azimuth 0
Altitude 5
Ridge 0

IFS 60-90-trapezoid-b

Cubic grid
5 segments

segment values:
1: 1, 0, 0, 1,-1
2: 0,-1, 0, 1, 1
3: 0, 0, 1,-1,-1
4: 0, 0,-1, 0, 0
5: 0, 0, 1,-1, 1

Azimuth 20

/******************************************************
Schraa's flea

   Source of the underlying tessellation:

   reverse engineered from a figure on 
   Wolter Schraa's website:
   Fractal Art by Wolter Schraa, 
   https://wolter.home.xs4all.nl,
   section Tessellations,
   last retrieved 13 March 2020.
******************************************************/
// Wolter Schraa's "vlo" (flea?) is a 3-reptile with
// a remarkable structure, resulting in geographical-
// map-like tiles. They cannot be used as the base for
// a single-rule plane-filling curve, but a traversal
// with jumps is, of course, possible. Here are four
// possibilities:

IFS schraa-1

Cubic grid
4 segments

segment values:
1: 1,0,0,1,-1
2: 0,0,-2,0,0
3: -1,0,0,1,1
4: -1,0,0,1,-1

Render 0,1,1,1
Altitude 50
Ridge -1

view schraa-1-topview

Render 0,1,1,1
Altitude 90
Ridge -1


IFS schraa-3

Cubic grid
5 segments

segment values:
1: 0,2,-1,1,1
2: 1,-4,0,0,0
3: -1,2,0,1,-1
4: 1,0,-2,0,0
5: 1,-2,0,1,-1

Render 1,-0.05,1,1
Ridge 0.60
Azimuth -30
Altitude 30

view schraa-3-topview

Render 1,-0.05,1,1
Ridge 0.60
Azimuth -30
Altitude 90


IFS schraa-4

Cubic grid
5 segments

segment values:
1: 2,0,0,1,-1
2: 2,0,-1,0,0
3: 0,2,0,1,1
4: -2,0,1,0,0
5: 2,0,0,-1,1

Render 0,1,1,1
Ridge -1
Altitude 40

view schraa-4-topview

Render 0,1,1,1
Altitude 90
Ridge -1


IFS schraa-5

Cubic grid
5 segments

segment values:
1: 2,0,0,-1,1
2: 0,-1,2,0,0
3: 0,0,2,-1,-1
4: 0,1,-2,0,0
5: 2,0,0,1,-1

Ridge 0.7
Azimuth -20
Altitude 22

view schraa-5-topview

Ridge 0.7
Azimuth -20
Altitude 90

/******************************************************
Peano Ballet
******************************************************/
// A nice self-crossing curve, obtained by simply
// reflecting the segments in the definition of the
// balanced Peano curve 

IFS peano-ballet

Cubic grid
3 segments

segment values:
1: 1, 0, 0, 1, 1
2: 0, 1, 0, 1,-1
3: 1, 0, 0, 1, 1

Altitude 45
Render 0.86603,0.5,1,1
Ridge -1

/******************************************************
Peano Railroads
******************************************************/
// A nice self-crossing curve

IFS peano-railroads

Cubic grid
3 segments

segment values:
1: 1, 0, 0,-1, 1
2: 1, 0, 0, 1,-1
3: 0, 1, 0,-1,-1

Altitude 70
Azimuth -10
Ridge -1

/******************************************************
Peano Waters
******************************************************/
// A nice self-crossing curve, whose image has a 
// boundary that looks very fuzzy, probably very 
// challenging to visualize as a plane-filling trail.

IFS peano-waters

Cubic grid
3 segments

segment values:
1: 1, 0, 0, 1,-1
2: 1, 0, 0,-1,-1
3: 0, 1, 0, 1, 1

ridge -1

/******************************************************
Ventrella's Family

   Re-encoded from: 

   Jeffrey Ventrella:
   Brainfilling curves: a fractal bestiary. 
   Eyebrain books, 2012.
******************************************************/
// A beautiful curve from Ventrella's book

IFS ventrellas-family

Cubic grid
7 segments

segment values:
1: 1, 0, 0,-1,-1
2: 0, 1, 0,-1,-1
3: 1, 0, 0,-1,-1
4: 0, 0, 1,-1,-1
5: 0, 0, 1,-1,-1
6: 1, 0, 0,-1,-1
7: 1, 0, 0,-1,-1

Render 1,0.44,1,1
Altitude 60
Azimuth 50
Distance 1.1
Ridge -1

/******************************************************
Gosper Stairway
******************************************************/
// This curve fills a shape that is like a triangle 
// whose edges are replaced by the same fractal curves 
// that make up the boundary of a Gosper island.
// I designed it to have the apperance of (recursive)
// winding stairs.

IFS gosper-stairway

Cubic grid
7 segments

segment values:
1: 1, 0, 0, 1, 1
2: 0,-1, 0, 1, 1
3: 1, 0, 0, 1, 1
4:-1, 0, 0, 1, 1
5: 0, 1, 0, 1, 1
6: 0, 0,-1, 1, 1
7: 1, 0, 0, 1, 1

render 0.866,0.5,1,1
ridge 0.289
altitude 30

/******************************************************
Ventrella's Groovy Crosser

   Re-encoded from: 

   Jeffrey Ventrella:
   Brainfilling curves: a fractal bestiary. 
   Eyebrain books, 2012.
******************************************************/
// A curve from Ventrella's book whose structure is 
// particular difficult to grasp

IFS ventrellas-groovy-crosser

Cubic grid
7 segments

segment values:
1: 0, 0,-1,-1,-1
2: 1, 0, 0, 1, 1
3: 0, 1, 0, 1, 1
4: 0, 0, 1, 1, 1
5: 0,-1, 0,-1,-1
6: 1, 0, 0, 1, 1
7: 0,-1, 0,-1,-1

Render 1,0,1,-1
Altitude 90
Ridge 0.2
