- Version:
- 1.0
- Since:
- 05/06/2020
- Source:
Classes
Members
(static, constant) ISLAND_PIXEL_SCALE :number
Scale factor. Higher values results in more pixelated images
Type:
- number
- Source:
(static) NAMES_LIST :Array.<string>
List of island names deriving from polynesian, melanesian, papuan, and austrolasian languages
Type:
- Array.<string>
- Source:
(static, constant) SPRITE_SIZE :number
Sprite scale factor
Type:
- number
- Source:
(static, constant) STRUCTURE_META :number
Magic number for structure meta data. Can be any magic number, just has to be unique
Type:
- number
- Source:
Methods
(static) colour_round(height)
Essentially a lookup table to determine the index of the colour to render a pixel height value at. If the pixel contains structure metadata,
a value of 4 is returned for special behaviour. This is used for shadow casting. Otherwise, the return value maps to the island::colours[v][0] hexidecimal colour code. The order of the indexes determines the base rules for shadow casting.
Parameters:
Name | Type | Description |
---|---|---|
height |
number | Height value to lookup |
- Source:
Returns:
Index of colour value, or 4 for structure meta data.
(static) distance(a, b)
Calculates the distance from a to b
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
- Source:
Returns:
distance from a to b
(static) downloadStaticPNG(png, name)
Downloads static PNG data as a file using dynamic html.
Parameters:
Name | Type | Description |
---|---|---|
png |
string | raw static PNG data |
name |
string | Name to save file as |
- Source:
(static) gen_noise_map(width, height, scale, oct, persist, lac, seed, normalize) → {Array.<number>}
Generates a perlin noise map based on parameters
Parameters:
Name | Type | Default | Description |
---|---|---|---|
width |
number | Width of the noise map | |
height |
number | Height of the noise map | |
scale |
number | Scale to view the base noise map layers. Higher scale values produced more "random" noise, while lower values produce more coherent results. | |
oct |
number | Number of octaves to generate. Each octave will contribute less to the overall noise map. More octaves means more expensive calculations, but more detailed noise maps. | |
persist |
number | The persistence of each octave to effect the overall noise map. Adjusts each octaves amplitude. | |
lac |
number | The lacunarity to apply to each octave. Adjusts each octaves frequency, which determines level of detail. Higher lacunarity creates more "detailed" "random" noise, while lower values creates more abstract shapes. | |
seed |
number | Seed value | |
normalize |
boolean | true | If the noise map should be normalized by it's min and max values to create a smoother more real gradient. Defaults to true. If left false, will record the min and max values as attributes of the return arrary for future normalization. |
- Source:
Returns:
A 2d array of perlin noise. If normalize was set to false, the min and max values are recorded in attributes minHeight and maxHeight.
- Type
- Array.<number>
(static) get_lighting(peak, coord, time)
Generates a lighting value for a coordinate based on a passed predetermined scaler, and the coordinates distance and height differential to a peak coordinate. This value will range between 0 and 1, and directly maps to the required opacity value of the rendered shadow
Parameters:
Name | Type | Description |
---|---|---|
peak |
Array.<number> | a three element array repersenting the x coordinate, y coordinate, and height value of the peak casting shadows |
coord |
Array.<number> | a three element array repersenting the x coordinate, y coordinate, and height value of the pixel which a shadow is being rendered over |
time |
number | Scaler value to determine max shadow length |
- Source:
Returns:
a float between 0 and 1 directly mapping to an opacity value to render the pixel's shadow at
(static) has_structure(val)
Determines if a height value contains structure meta data. Height values are numbers between 0 and 1. (Actually a lie, as they can exceed 1, but for abstract purposes you can consider them a float between 0 and 1). This leaves the integer portion of the number unused, so I use it to contain meta data about the pixel, by salting it with a magic integer when a structure is at that coordinate.
Parameters:
Name | Type | Description |
---|---|---|
val |
number | height value to check |
- Source:
Returns:
boolean if val contains strucutre metadata
(static) hash(num) → {number}
A basic insecure 64bit hash. Hashes a number by repeatedly applying bitwise operations, and salting by each digit of the original number. I've chosen some magic numbers to left shift by, 16, 19, 26, 13, purely through trial and error to get good results. This hash is by no means secure, and should not be used for encryption purposes, but for my purpose of "randomizing" seed values, and generating "random" results (that of course are not actually random, and will unfold the same way every time for the same seed), this works excellently.
Parameters:
Name | Type | Description |
---|---|---|
num |
number | Initial number to salt hash with. |
- Source:
Returns:
64bit hash salted by the initial passed number
- Type
- number
(static) normalize(val, min, max) → {number}
normalize a value to between 0 and 1 based on min and max
Parameters:
Name | Type | Description |
---|---|---|
val |
number | Initial value to normalize |
min |
number | Minimum bound to normalize by |
max |
number | Maximum bound to normalize by |
- Source:
Returns:
val normalized by min and max
- Type
- number
(static) normalize_2d_array(arr, minHeight, maxHeight) → {number}
nomralize a 2d array to between 0 and 1 based on min and max
Parameters:
Name | Type | Description |
---|---|---|
arr |
number | Array of values to normalize |
minHeight |
number | Minimum bound to normalize by |
maxHeight |
number | Maximum bound to normalize by |
- Source:
Returns:
Array of updated normalized values
- Type
- number
(static) region_dist(x, y, w, h) → {number}
Calculates the distance from a point to the center of a region
Parameters:
Name | Type | Description |
---|---|---|
x |
number | x coordinate |
y |
number | y coordinate |
w |
number | width of region |
h |
number | height of region |
- Source:
Returns:
distance from x,y to the center of w,h
- Type
- number
(static) rgb(r, g, b) → {string}
Generates an HTML canvas rgb formatted string from three channel values
Parameters:
Name | Type | Description |
---|---|---|
r |
number | Red channel |
g |
number | Green channel |
b |
number | Blue channel |
- Source:
Returns:
HTML canvas rgb formatted string
- Type
- string
(static) strip_metadata(val)
Strips a height value of it's structure metadata in order to be better used by the shadow renderer. See has_structure for more information
Parameters:
Name | Type | Description |
---|---|---|
val |
number | value to be stripped |
- Source:
Returns:
val stripped of metadata