Constructor
new Island()
Initializes all the needed data members, and runs the main generation methods
- Source:
Members
(static) graphics :Array.<object>
Storage for image sprites
Type:
- Array.<object>
- Source:
(static, constant) numPlantGraphics :number
Number of sprites related to plants. For sorting purposes
Type:
- number
- Source:
(static, constant) numTreeGraphics :number
Number of sprites related to trees. For sorting purposes
Type:
- number
- Source:
(static, constant) numVillageGraphics :number
Number of sprites related to villages. For sorting purposes
Type:
- number
- Source:
(static, constant) shiftPlantGraphics :number
Index of first sprite related to plants. For sorting purposes
Type:
- number
- Source:
(static, constant) shiftTreeGraphics :number
Index of first sprite related to trees. For sorting purposes
Type:
- number
- Source:
canvas_img :object
Storage for the HTML5 canvas element which contains the rendered rectangles making up the base layer of the island.
Type:
- object
- Source:
colours :Array.<string>
Array of colours repersented in hexidecimal, which map one-to-one to the display_data data.
Type:
- Array.<string>
- Source:
display_data :Array.<array>
An array of rectangle verticies to be rendered. The most optimized way to re-render the island is to draw all of these rectangles, however soon this will be deprecated once I impliment static PNG rendering.
Type:
- Array.<array>
- Source:
has_volcano :boolean
Boolean to repersent if lava exists on the island
Type:
- boolean
- Source:
LAC_SCALE_DOWN :number
Lacunarity multiplier used under the hood for atoll/volcano generation types.
Type:
- number
- Source:
lighting_img :object
Storage for the HTML5 canvas element which contains the rendered rectangles making up the shadows layer of the island.
Type:
- object
- Source:
name :string
Island name
Type:
- string
- Source:
raw_data :Array.<number>
2D array of the raw height map data from generation. This isn't used for rendering, rather for interactivity. If you want to test an exact coordinate to see the height of the terrain for instance.
Type:
- Array.<number>
- Source:
replicable_seed :number
Exact copy of the passed seed
Type:
- number
- Source:
seed :number
hash copy of the passed seed
Type:
- number
- Source:
settings :object
Settings (IslandSettings) for generation. Technically isn't const, but is never changed
Type:
- object
- Source:
size :Array.<number>
Coordinate w,h pair to repersent the island's size
Type:
- Array.<number>
- Source:
town :Array.<number>
Coordinate x,y pair of the epicentre of the Island's village
Type:
- Array.<number>
- Source:
Methods
bake_lighting()
Generates the lighting canvas element. Instead of returning, updates lighting_img
- Source:
bake_strip(maxsize, y, ctx_img)
Bakes a diagnal pixel strip of lighting data. Renders shadows by directly drawing semi-transparent black squares to a passed ctx img object.
Parameters:
Name | Type | Description |
---|---|---|
maxsize |
number | Max distance of rendered strip |
y |
number | Y coordinate in world to start strip from |
ctx_img |
object | A 2d context to directly render shadows to. |
- Source:
cast_shadow(shadow)
Sets relavent shadow meta data for objects. Instead of returning, updates raw_data
Parameters:
Name | Type | Description |
---|---|---|
shadow |
Array.<number> | Object data to cast shadow |
- Source:
compileStaticBakedShadows()
Renders shadows out at an interval into a spritesheet
- Source:
Returns:
a static PNG datastream
compileStaticImage(objects, lighting)
Compiles an entire island object into a static raw PNG datastream. This can be downloaded as a PNG file, or rendered directly through the browser, instead of going through the canvas interface.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
objects |
boolean | true | If objects such as village structures and trees should be included |
lighting |
boolean | false | If the lighting layer should be included |
- Source:
Returns:
A static PNG datastream
compress(factor) → {Array.<number>}
Smart compress by scale factor. Smart meaning that it tends to generate cleaner, more solid borders between colour boundries, and respects and preserves priority elements.
Parameters:
Name | Type | Description |
---|---|---|
factor |
number | Scale factor |
- Source:
Returns:
A compressed noise map. See raw_data and gen_noise_map.
- Type
- Array.<number>
gen_ctx_colour(c, ctx_img)
Renders base layer island to a ctx object
Parameters:
Name | Type | Description |
---|---|---|
c |
number | colour to render |
ctx_img |
object | 2d canvas context to render colour strips to |
- Source:
gen_ctx_img()
Generates the base layer canvas element. Instead of returning, updates canvas_img
- Source:
gen_display_data(raw_data)
An optimization algorithm to convert 2d noise maps into colour separated arrays of rectangle verticies.
Parameters:
Name | Type | Description |
---|---|---|
raw_data |
Array.<number> | noise map to operate on. Allows the island to copy another islands noise map. |
- Source:
gen_island_data()
Wrapper algorithm to manipulate perlin noise maps into islands.
The real heart of the Island class.
Doesn't return, instead updates raw_data
- Source:
gen_obj(graphicStart, graphicShift, numObj, spreadX, spreadY, rangeMin, rangeMax, hashShift, originX, originY)
Generates a set number of "objects", sprites at locations. Instead of returning, updates objects
Parameters:
Name | Type | Description |
---|---|---|
graphicStart |
number | Index 0 of graphics to sample sprite from |
graphicShift |
number | Index n of graphics to sample sprite from |
numObj |
number | Number of objects to generate |
spreadX |
number | X axis spread value. How far from objects must be from other objects. If set to -1, an optimal value is calculated based on sprite and pixel size. |
spreadY |
number | Y axis spread value. How far from objects must be from other objects. If set to -1, an optimal value is calculated based on sprite and pixel size. |
rangeMin |
number | Minimum height value prospective object spawn coordinates must be |
rangeMax |
number | Maximum height value prospective object spawn coordinates must be |
hashShift |
number | Hash seed |
originX |
number | Origin x coordinate to spawn objects around |
originY |
number | Origin y coordinate to spawn objects around |
- Source:
gen_objects_img()
Generates a redrawable canvas object as a render layer for all objects. Objects such as villages, trees, buildings, sprites, anything image based coming from a file. This canvas is meant to be rendered as a layer over top of the base layer, and likely under shadow/lighting layers.
- Source:
saveBakedLighting(objects, lighting)
Downloads an the lighting as a spritesheet. Utilizes downloadStaticPNG and compileStaticBakedShadows
Parameters:
Name | Type | Description |
---|---|---|
objects |
boolean | If objects such as village structures and trees should be included |
lighting |
boolean | If the lighting layer should be included |
- Source:
saveImage(objects, lighting)
Downloads an image of the island. Utilizes downloadStaticPNG and compileStaticImage
Parameters:
Name | Type | Default | Description |
---|---|---|---|
objects |
boolean | true | If objects such as village structures and trees should be included |
lighting |
boolean | false | If the lighting layer should be included |
- Source: