Class ConvChain
java.lang.Object
com.github.yellowstonegames.grid.ConvChain
A class that imitates patterns in an existing
Ported from ConvChain (which is in the public domain).
Region and uses it to fill another Region so it has a
similar visual style. Useful for creating procedural filler around a desired path or series of known rooms. Can also
convert between Regions (samples) and 2D char arrays (maps).
Ported from ConvChain (which is in the public domain).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final RegionPredefined sample; many small separate squares.static final RegionPredefined sample; a large, enclosed, organic space that usually makes large cave-like rooms.static final RegionPredefined sample; several medium-sized organic spaces that usually make tight, chaotic tunnels.static final RegionPredefined sample; a checkerboard pattern that typically loses recognition as such after generation.static final RegionPredefined sample; produces rectangular rooms with small corridors between them.static final RegionPredefined sample; produces a suitable filler for a maze (but it is unlikely to connect both ends like a maze).static final Regionstatic final RegionPredefined sample; produces weird, large areas of "on" and "off" that suddenly change to the other.static final RegionPredefined sample; produces multiple directions of flowing, river-like shapes made of "off".static final RegionPredefined sample; produces rectangular rooms with a dense packing.static final Regionstatic final Region[]static final RegionPredefined sample; produces an uncanny imitation of a maze with a tiny sample size.static final RegionPredefined sample; produces mostly rectangular rooms with very few corridor-like areas.static final RegionPredefined sample; produces largely rectangular rooms with a good amount of thin corridors. -
Method Summary
Modifier and TypeMethodDescriptionstatic Regionfill(Region field, Region sample, double temperature, int iterations, com.github.tommyettinger.random.EnhancedRandom random) The main part of MimicFill; generates a Region that mimics the patterns present in the Region sample, but can produce a larger or smaller output Region than the sample.static Regionfill(Region field, Region sample, double temperature, int iterations, com.github.tommyettinger.random.EnhancedRandom random, int order) The main part of MimicFill; generates a Region that mimics the patterns present in the Region sample, but can produce a larger or smaller output Region than the sample.static RegionmapToSample(Region toFill, char[][] map, char... yes) Converts a 2D char array map to a Region, where any chars in the array or vararg yes will result in true in the returned array at that position and any other chars will result in false.static RegionmarkSample(Region sample, Collection<Coord> points) Given a Region sample (usually a final product of this class' fill() method) and an Iterable of Coord (such as a List or Set of Coord, but a Region can also work), marks every Coord in points as true if it is in-bounds, and returns sample after modifications.static char[][]sampleToMap(Region sample, char on, char off) Converts a Region to a 2D char array, where "on" will be written as the char on, and "off" in the Region will be written as the char off
-
Field Details
-
boulders
Predefined sample; many small separate squares. -
cave
Predefined sample; a large, enclosed, organic space that usually makes large cave-like rooms. -
caves
Predefined sample; several medium-sized organic spaces that usually make tight, chaotic tunnels. -
chess
Predefined sample; a checkerboard pattern that typically loses recognition as such after generation. -
lessRooms
Predefined sample; produces rectangular rooms with small corridors between them. -
maze
Predefined sample; produces a suitable filler for a maze (but it is unlikely to connect both ends like a maze). -
quarterBlack
Predefined sample; produces weird, large areas of "on" and "off" that suddenly change to the other. -
river
Predefined sample; produces multiple directions of flowing, river-like shapes made of "off". -
rooms
Predefined sample; produces rectangular rooms with a dense packing. -
simpleMaze
Predefined sample; produces an uncanny imitation of a maze with a tiny sample size. -
simpleRooms
Predefined sample; produces mostly rectangular rooms with very few corridor-like areas. -
thickWalls
Predefined sample; produces largely rectangular rooms with a good amount of thin corridors. -
ruins
-
openRooms
-
samples
-
-
Method Details
-
mapToSample
Converts a 2D char array map to a Region, where any chars in the array or vararg yes will result in true in the returned array at that position and any other chars will result in false. The result can be given to fill() as its sample parameter.- Parameters:
toFill-map- a 2D char array that you want converted to a Regionyes- an array or vararg of the chars to consider true in map- Returns:
- a 2D boolean array that can be given to fill()
-
sampleToMap
Converts a Region to a 2D char array, where "on" will be written as the char on, and "off" in the Region will be written as the char off- Parameters:
sample- a 2D boolean array that you want converted to a 2D char arrayon- true in sample will be mapped to this char; usually '.'off- false in sample will be mapped to this char; usually '#'- Returns:
- a 2D char array containing only the chars yes and no
-
markSample
Given a Region sample (usually a final product of this class' fill() method) and an Iterable of Coord (such as a List or Set of Coord, but a Region can also work), marks every Coord in points as true if it is in-bounds, and returns sample after modifications. Does not alter the original sample. You may want to use this with techniques like drawing a long line with Bresenham, OrthoLine, or WobblyLine, potentially widening the line with Radius.expand(), and then passing the result as the Iterable of Coord. You could then make the start and end of the line into an entrance and exit and be sure the player can get from one to the other (except for Bresenham and other lines that may make diagonal movements, if the player cannot move diagonally).- Parameters:
sample- a Region; will be modified directlypoints- an Iterable (such as a List or Set) of Coord that will be marked as true if in-bounds- Returns:
- sample, after modifications
-
fill
public static Region fill(Region field, Region sample, double temperature, int iterations, com.github.tommyettinger.random.EnhancedRandom random) The main part of MimicFill; generates a Region that mimics the patterns present in the Region sample, but can produce a larger or smaller output Region than the sample. Takes a Region to fill with the output, a Region as a "sample" (often one of the constants in this class) and several other parameters that affect how closely the output will match the input. The temperature is how "agitated" or "chaotic" the changes to the map can be; 0.2f is definitely recommended for map-like data but other values (between 0 and 1, both exclusive) may be better fits for certain kinds of output. The iterations parameter should usually be between 3 and 5, with higher values taking longer but fitting more closely; values over 5 are barely different from 5 here.- Parameters:
field- a Region that will be modified; should be square, otherwise it will have its size increasedsample- a Region to mimic visually; you can use mapToSample() if you have a 2D char arraytemperature- typically 0.2f works well for this, but other numbers between 0 and 1 may workiterations- typically 3-5 works well for this; lower numbers may have slight problems with quality, and higher numbers make this slightly slowerrandom- an EnhancedRandom to use for the random components of this technique- Returns:
- a new Region, width = size, height = size, mimicking the visual style of sample
-
fill
public static Region fill(Region field, Region sample, double temperature, int iterations, com.github.tommyettinger.random.EnhancedRandom random, int order) The main part of MimicFill; generates a Region that mimics the patterns present in the Region sample, but can produce a larger or smaller output Region than the sample. Takes a Region to fill with the output, a Region as a "sample" (often one of the constants in this class) and several other parameters that affect how closely the output will match the input. The temperature is how "agitated" or "chaotic" the changes to the map can be; 0.2f is definitely recommended for map-like data but other values (between 0 and 1, both exclusive) may be better fits for certain kinds of output. The iterations parameter should usually be between 3 and 5, with higher values taking longer but fitting more closely; values over 5 are barely different from 5 here.- Parameters:
field- a Region that will be modified; should be square, otherwise it will have its size increasedsample- a Region to mimic visually; you can use mapToSample() if you have a 2D char arraytemperature- typically 0.2f works well for this, but other numbers between 0 and 1 may workiterations- typically 3-5 works well for this; lower numbers may have slight problems with quality, and higher numbers make this slightly slowerrandom- an EnhancedRandom to use for the random components of this techniqueorder- the order of the algorithm from 2 to 5 inclusive; this determines how big each sample is (the edge length of a square sample).- Returns:
- a new Region, width = size, height = size, mimicking the visual style of sample
-