Package squidpony.squidgrid
Class DetailedMimic
java.lang.Object
squidpony.squidgrid.DetailedMimic
public class DetailedMimic extends Object
Similar to MimicFill, this class can be used to imitate the style of an existing piece of data, but this works on
more than just booleans; it can produce similar styles of texture (its original use in SynTex), of map, of item
placement, and so on by specifying a different technique for differentiating two int values.
Two options are now available; the process() method allows the slow analyze() step to be computed once, before the rest of processing is potentially done many times, but the new neoProcess() method produces comparable or better results and is drastically faster even without needing analysis. This means neoProcess(), based on P.F. Harrison's algorithm in SynTex, is strongly recommended now.
Example results of neoProcess(), with a procedural dungeon first and the mimic versions after it: https://gist.github.com/tommyettinger/405336fb0fc74838d806c021aabe77da (you may need to click Raw and zoom out somewhat for it to render well).
Ported from https://github.com/mxgmn/SynTex by Tommy Ettinger on 6/9/2016.
Two options are now available; the process() method allows the slow analyze() step to be computed once, before the rest of processing is potentially done many times, but the new neoProcess() method produces comparable or better results and is drastically faster even without needing analysis. This means neoProcess(), based on P.F. Harrison's algorithm in SynTex, is strongly recommended now.
Example results of neoProcess(), with a procedural dungeon first and the mimic versions after it: https://gist.github.com/tommyettinger/405336fb0fc74838d806c021aabe77da (you may need to click Raw and zoom out somewhat for it to render well).
Ported from https://github.com/mxgmn/SynTex by Tommy Ettinger on 6/9/2016.
-
Field Summary
Fields Modifier and Type Field Description AestheticDifference
difference
IRNG
random
-
Constructor Summary
Constructors Constructor Description DetailedMimic()
Constructor that uses an unseeded RNG and, without any instruction otherwise, assumes the ints this is asked to compare are colors in RGBA8888 format.DetailedMimic(AestheticDifference diff)
Constructor that uses an unseeded RNG (effectively a random seed) and the given AestheticDifference.DetailedMimic(AestheticDifference diff, IRNG rng)
Constructor that uses the given RNG and the given AestheticDifference. -
Method Summary
Modifier and Type Method Description void
analyze(int[] sample, int width, int height, int detailLevel, int proximity, boolean discrete)
DISCOURAGED; useneoProcess(int[], int, int, int, int, int, int, boolean)
instead, which doesn't need a separate analysis step.static int[]
convertCharToInt(char[][] map)
Utility method to produce 1D int arrays this can process when discrete is true or difference is null.static char[][]
convertIntToChar(int[] arr, int w, int h)
Utility method that takes a 1D int array that represents chars (such as a sample produced byconvertCharToInt(char[][])
or, more likely, the result of processing such a sample with this class) and returns a 2D char array with the requested width and height (which should match the targetWidth and targetHeight given during processing).int[]
neoProcess(int[] sample, int sampleWidth, int sampleHeight, int targetWidth, int targetHeight, int detailLevel, int proximity, boolean discrete)
Processes a 1D int array representing 2D storage of values that can be compared by this object's AestheticDifference (or any values if that is null or discrete is true), and returns a 1D array representing data with potentially different dimensions but similar appearance to sample.int[]
process(int[] sample, int sampleWidth, int sampleHeight, int targetWidth, int targetHeight, int detailLevel, int proximity, double temperature, boolean discrete)
DISCOURAGED; useneoProcess(int[], int, int, int, int, int, int, boolean)
instead, which doesn't need a separate analysis step.
-
Field Details
-
Constructor Details
-
DetailedMimic
public DetailedMimic()Constructor that uses an unseeded RNG and, without any instruction otherwise, assumes the ints this is asked to compare are colors in RGBA8888 format. You can specify your own implementation of the AestheticDifference interface (one function) and pass it to other constructors, as well. -
DetailedMimic
Constructor that uses an unseeded RNG (effectively a random seed) and the given AestheticDifference. An example piece of code that implements an AestheticDifference is available in the docs forAestheticDifference.difference(int, int)
; it is also considered a functional interface if you use Java 8 or newer. You can also use the ready-made implementationAestheticDifference.rgba8888
if you have int data that represents RGBA8888 colors, which can be obtained from libGDX Colors or SColors in the display module.- Parameters:
diff
- an implementation of the AestheticDifference interface, such asAestheticDifference.rgba8888
; may be null, but that forces all calls to processing methods to treat discrete as true
-
DetailedMimic
Constructor that uses the given RNG and the given AestheticDifference. An example piece of code that implements an AestheticDifference is available in the docs forAestheticDifference.difference(int, int)
; it is also considered a functional interface if you use Java 8 or newer. You can also use the ready-made implementationAestheticDifference.rgba8888
if you have int data that represents RGBA8888 colors, which can be obtained from libGDX Colors or SColors in the display module.- Parameters:
diff
- an implementation of the AestheticDifference interface, such asAestheticDifference.rgba8888
; may be null, but that forces all calls to processing methods to treat discrete as truerng
- an IRNG, such as an RNG, to generate random factors; may be seeded to produce reliable output
-
-
Method Details
-
analyze
public void analyze(int[] sample, int width, int height, int detailLevel, int proximity, boolean discrete)DISCOURAGED; useneoProcess(int[], int, int, int, int, int, int, boolean)
instead, which doesn't need a separate analysis step. Analyzes a sample as a 1D int array and stores the needed info to callprocess(int[], int, int, int, int, int, int, double, boolean)
any number of times later on without recalculating some heavy-weight information.- Parameters:
sample
- a 1D array of ints that can be compared by the AestheticDifference this uses (or any ints if discrete is true)width
- the width of the area in sample this should use (sample can be interpreted as different shapes)height
- the height of the area in sample this should use (sample can be interpreted as different shapes)detailLevel
- how much detail to try for; if 0 or less this does nothing, 2 works well in generalproximity
- how far away to consider cells as affecting another; 3 works welldiscrete
- false if this can produce ints other than those in the input; true if it uses a fixed set
-
process
public int[] process(int[] sample, int sampleWidth, int sampleHeight, int targetWidth, int targetHeight, int detailLevel, int proximity, double temperature, boolean discrete)DISCOURAGED; useneoProcess(int[], int, int, int, int, int, int, boolean)
instead, which doesn't need a separate analysis step. Processes a sample as a 1D int array and returns a different 1D int array that mimics the input. If the last time this was called used the same sample, sampleWidth, and sampleHeight parameters, or ifanalyze(int[], int, int, int, int, boolean)
was called with its width equal to sampleWidth and its height equal to sampleHeight, then this doesn't need to perform as many expensive calculations.- Parameters:
sample
- a 1D array of ints that can be compared by the AestheticDifference this uses (or any ints if discrete is true)sampleWidth
- the width of the area in sample this should use (sample can be interpreted as different shapes)sampleHeight
- the height of the area in sample this should use (sample can be interpreted as different shapes)targetWidth
- the desired width of the outputtargetHeight
- the desired height of the outputdetailLevel
- how much detail to try for; if 0 or less this doesn't perform analysis and has somewhat lower quality, but 2 works well in generalproximity
- how far away to consider cells as affecting another; 3 works welltemperature
- a level of unpredictability in the output relative to the input; must be greater than 0discrete
- false if this can produce ints other than those in the input; true if it uses a fixed set- Returns:
- a new 1D int array that can be interpreted as having targetWidth and targetHeight, and mimics sample
-
neoProcess
public int[] neoProcess(int[] sample, int sampleWidth, int sampleHeight, int targetWidth, int targetHeight, int detailLevel, int proximity, boolean discrete)Processes a 1D int array representing 2D storage of values that can be compared by this object's AestheticDifference (or any values if that is null or discrete is true), and returns a 1D array representing data with potentially different dimensions but similar appearance to sample.- Parameters:
sample
- a 1D array of ints that can be compared by the AestheticDifference this uses (or any ints if discrete is true)sampleWidth
- the width of the area in sample this should use (sample can be interpreted as different shapes)sampleHeight
- the height of the area in sample this should use (sample can be interpreted as different shapes)targetWidth
- the desired width of the outputtargetHeight
- the desired height of the outputdetailLevel
- how much detail to try for; here this will always be treated as at least 1proximity
- how far away to consider cells as affecting another; 3 works welldiscrete
- false if this can produce ints other than those in the input; true if it uses a fixed set- Returns:
- a new 1D int array that can be interpreted as having targetWidth and targetHeight, and mimics sample
-
convertCharToInt
Utility method to produce 1D int arrays this can process when discrete is true or difference is null.- Parameters:
map
- a 2D char array- Returns:
- an int array that can be used as a sample
-
convertIntToChar
Utility method that takes a 1D int array that represents chars (such as a sample produced byconvertCharToInt(char[][])
or, more likely, the result of processing such a sample with this class) and returns a 2D char array with the requested width and height (which should match the targetWidth and targetHeight given during processing).- Parameters:
arr
- a 1D int array that represents char valuesw
- the width that arr can be interpreted as; should probably match the targetWidth given in processingh
- the height that arr can be interpreted as; should probably match the targetHeight given in processing- Returns:
- a 2D char array with the given width and height, probably filled with the data from arr
-