Skip to content

Commit

Permalink
Add randomness parameter to Truchet tiling function
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Nov 25, 2024
1 parent 6e9aaac commit 0d3dc13
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ private static Coordinate randomPtInRectangleAround(Coordinate centre, double wi
@Metadata(description="Create Truchet tiling from lines defining lower left tile")
public static Geometry truchetTiling(Geometry tileLines,
@Metadata(title="Grid side cell #")
int nSide) {
int nSide,
@Metadata(title="Randomness")
double randomness) {
PrecisionModel pmSnap = new PrecisionModel(10000.0);
//Geometry tileSnap = snapEndpoints(tileLines.copy(), pmSnap);
Geometry tileSnap = GeometryPrecisionReducer.reduce(tileLines, pmSnap);
Expand All @@ -383,8 +385,13 @@ public static Geometry truchetTiling(Geometry tileLines,
List<Geometry> tiles = new ArrayList<Geometry>();
for (int i = 0; i < nSide; i++) {
for (int j = 0; j < nSide; j++) {

int nPi2 = (i + j) % 4;
if (Math.random() < randomness) {
//-- random rotation by PI/2, translate to grid cell
int nPi2 = (int) (4 * Math.random());
nPi2 = (int) (4 * Math.random());
}

AffineTransformation trans = AffineTransformation.rotationInstance(nPi2 * Math.PI / 2.0,
centre.getX(), centre.getY());
trans.translate(i * side, j * side);
Expand Down

0 comments on commit 0d3dc13

Please sign in to comment.