Methods
adjustCloudForElevation(cloud, currentCell, nextCell)
Adjusts the cloud's moisture level and mountain count based on the elevation of the current and next cell.
Parameters:
Name | Type | Description |
---|---|---|
cloud |
Object | The cloud object. |
currentCell |
Object | The current cell being processed. |
nextCell |
Object | The next cell to be processed. |
- Source:
adjustCloudForMountains(cloud, currentCell, nextCell)
Sets desert properties on cells based on the cloud's mountain count and the next cell's elevation.
Parameters:
Name | Type | Description |
---|---|---|
cloud |
Object | The cloud object. |
currentCell |
Object | The current cell being processed. |
nextCell |
Object | The next cell to be processed. |
- Source:
applyBrush(e, brushSize, brushType, brushHardness)
Applies a brush effect on the map based on the mouse event.
Parameters:
Name | Type | Description |
---|---|---|
e |
MouseEvent | The mouse event triggering the brush. |
brushSize |
number | The size of the brush. |
brushType |
string | The type of brush ("dropLand" or "raiseLand"). |
brushHardness |
number | The hardness of the brush, affecting the degree of elevation change. |
- Source:
asteroidStorm(num)
Simulates an asteroid storm by creating a specified number of asteroid impacts on the world map.
Parameters:
Name | Type | Description |
---|---|---|
num |
number | The number of asteroids to create. |
- Source:
beachable(cell) → {boolean}
Determines if a given cell is suitable to be a beach.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cell |
Object | The cell object to check.
Properties
|
- Source:
Returns:
- True if the cell is suitable to be a beach, false otherwise.
- Type
- boolean
biome(cell) → {string}
Determines the biome type of a given cell based on its properties and location.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cell |
Object | The cell object to determine the biome for.
Properties
|
- Source:
Returns:
- The biome type of the cell. Possible values are "beach", "lake", "river", "mountain", "arctic", "desert", "grass", or "ocean".
- Type
- string
cleanupAll()
Performs a comprehensive cleanup of the world by calling specific cleanup functions.
This function performs the following steps:
1. Cleans up the world by calling the `cleanupWorld` function.
2. Identifies and processes beach areas by calling the `getBeaches` function.
- Source:
cleanupStrayCells(cell, limit, newElevation, isWater) → {number}
Cleans up stray cells by adjusting their elevation based on the number of neighboring cells.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to check and potentially adjust. |
limit |
number | The elevation limit to compare against. |
newElevation |
number | The new elevation to set if the cell is determined to be stray. |
isWater |
boolean | Whether the cleanup is for water cells. |
- Source:
Returns:
The number of cells removed (1 if the cell was adjusted, otherwise 0).
- Type
- number
cleanupWorld()
Performs a comprehensive cleanup of the world map in a single loop.
Removes stray land, mountain, and water cells by adjusting their elevation
based on the number of neighboring cells of the same type.
- Source:
createAsteroid(size, x, y)
Creates an asteroid impact at the specified coordinates, modifying the terrain to reflect the impact.
Parameters:
Name | Type | Description |
---|---|---|
size |
number | The size (diameter) of the asteroid. |
x |
number | The x-coordinate of the impact point. |
y |
number | The y-coordinate of the impact point. |
- Source:
createBlankWorld()
Initializes a blank world with default settings, geographical points,
feature arrays, and populates the world map with cells.
- Source:
createCell(x, y) → {object}
Creates a cell at the specified coordinates and initializes its properties.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x-coordinate of the cell. |
y |
number | The y-coordinate of the cell. |
- Source:
Returns:
The created cell with initialized properties.
- Type
- object
createHSpreadLine()
Creates a horizontal spreading line across the world map.
The line starts from a random y-coordinate and progresses horizontally,
adjusting the y-coordinate randomly while ensuring it stays within vertical boundaries.
- Source:
createProvinceTerrain()
Creates the terrain types for each province based on various conditions.
Updates the province object with the appropriate terrain type.
- Source:
createSpreadingCenters()
Initializes spreading centers for tectonic activity.
Generates a random number of spreading centers based on the world's width
and distributes them across the width of the world.
- Source:
createSpreadingLine(center)
Creates a spreading line starting from a given center.
The line progresses vertically and adjusts the center randomly,
ensuring it stays within the map boundaries.
Parameters:
Name | Type | Description |
---|---|---|
center |
number | The starting x-coordinate for the spreading line. |
- Source:
createWinterSeverity()
Creates winter severity bias for each province based on their location.
Updates the severity attribute of each province in the world object.
- Source:
createWorld()
Creates the world by initializing a blank world, setting up spreading centers,
creating spreading lines, and generating horizontal spreading lines.
- Source:
drawArctic(cell)
Draws an arctic cell on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawBeach(cell)
Draws a beach cell on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawBookType(cell)
Draws a cell of "book" type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
- Source:
drawCell(x, y)
Draws a cell on the canvas based on the world's drawing type and the cell's properties.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x-coordinate of the cell. |
y |
number | The y-coordinate of the cell. |
- Source:
drawColorfulType(cell)
Draws a cell of "colorful" type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
- Source:
drawDesert(cell)
Draws a desert cell on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawGrass(cell)
Draws a grass cell on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawGrassBookType(cell)
Draws a grass cell of "book" type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
- Source:
drawHeightmapCell(x, y)
Draws a heightmap cell at the specified coordinates (x, y).
The function calculates the color value based on the cell's elevation and
adjusts it slightly for a more natural look. The cell is then drawn as a tiny pixel.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x-coordinate of the cell. |
y |
number | The y-coordinate of the cell. |
- Source:
drawHeightmapFromScratch()
Draws the heightmap from scratch by iterating over the world map and drawing each cell.
If the small map is available, it clears the canvas, fills it with a base color,
and then draws each cell. Otherwise, it sets the drawing type to 'heightmap' and redraws the world.
- Source:
drawHeightmapType(cell)
Draws a cell of "heightmap" type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
- Source:
drawInkMarsh(cell)
Draws an ink marsh symbol on the canvas at the cell's coordinates.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawInkMountain(cell)
Draws an ink mountain or hill symbol on the canvas at the cell's coordinates
based on the cell's elevation.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawInkTree(cell)
Draws an ink tree symbol on the canvas at the cell's coordinates.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawLake(cell)
Draws a lake cell on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawMountain(cell)
Draws a mountain cell on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawName(name, x, y)
Draws a name on the canvas at the specified coordinates.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name to be drawn. |
x |
number | The x-coordinate where the name will be drawn. |
y |
number | The y-coordinate where the name will be drawn. |
- Source:
drawOcean(cell)
Draws an ocean cell on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawPaperType(cell, r, g, b)
Draws a cell of "paper" type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
r |
number | The red color component. |
g |
number | The green color component. |
b |
number | The blue color component. |
- Source:
drawPapyrusType(cell, r, g, b)
Draws a cell of "papyrus" type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
r |
number | The red color component. |
g |
number | The green color component. |
b |
number | The blue color component. |
- Source:
drawParchmentType(cell, r, g, b)
Draws a cell of "parchment" type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
r |
number | The red color component. |
g |
number | The green color component. |
b |
number | The blue color component. |
- Source:
drawRivermapType(cell)
Draws a cell of "rivermap" type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
- Source:
drawSmallPixel(context, x, y, color)
Draws a small pixel on the canvas at the specified coordinates with the given color.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasRenderingContext2D | The canvas rendering context. |
x |
number | The x-coordinate where the pixel will be drawn. |
y |
number | The y-coordinate where the pixel will be drawn. |
color |
string | The color of the pixel. Defaults to black if not specified. |
- Source:
drawSpecialType(cell, type)
Draws a cell of a special mask type.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to draw. |
type |
string | The type of mask. |
- Source:
drawTinyPixel(context, x, y, color)
Draws a tiny pixel on the canvas at the specified coordinates with the given color.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasRenderingContext2D | The canvas rendering context. |
x |
number | The x-coordinate where the pixel will be drawn. |
y |
number | The y-coordinate where the pixel will be drawn. |
color |
string | The color of the pixel. Defaults to black if not specified. |
- Source:
drawTree(cell)
Draws a tree cell on the canvas.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell to be drawn. |
- Source:
drawWorld()
Draws the entire world map by clearing the canvas, setting its dimensions,
and iterating over each cell to draw it.
- Source:
getCorrectedColor(cell) → {number}
Corrects the color of a cell based on its elevation.
Parameters:
Name | Type | Description |
---|---|---|
cell |
Object | The cell object containing elevation information. |
- Source:
Returns:
The corrected color value.
- Type
- number
getDistance(x1, y1, x2, y2) → {number}
Calculates the Euclidean distance between two points (x1, y1) and (x2, y2).
Parameters:
Name | Type | Description |
---|---|---|
x1 |
number | The x-coordinate of the first point. |
y1 |
number | The y-coordinate of the first point. |
x2 |
number | The x-coordinate of the second point. |
y2 |
number | The y-coordinate of the second point. |
- Source:
Returns:
- The distance between the two points, floored to the nearest integer.
- Type
- number
getRGB(pixels, num) → {string|undefined}
Retrieves the RGB values at a specific pixel position in the ImageData object.
Parameters:
Name | Type | Description |
---|---|---|
pixels |
ImageData | The ImageData object containing pixel data. |
num |
number | The index of the pixel in the ImageData array. |
- Source:
Returns:
The RGB string or undefined if out of bounds.
- Type
- string | undefined
getRGBFromElevation(elevation) → {Object}
Calculates RGB values from the elevation.
Parameters:
Name | Type | Description |
---|---|---|
elevation |
number | The elevation of the cell. |
- Source:
Returns:
An object containing the r, g, and b values.
- Type
- Object
getRandomSequentialColorObject() → {Object|number|number|number}
Generates a sequential color object with unique RGB values.
The function increments the blue color value (`bCount`) each time it's called.
When `bCount` reaches 256, it resets to 0, and the green color value (`gCount`) is incremented.
This ensures a sequential generation of unique RGB color values.
- Source:
Returns:
-
An object containing the RGB color values.
- Type
- Object
-
return.r - The red color value, always set to 0.
- Type
- number
-
return.g - The green color value, incremented after blue reaches 256.
- Type
- number
-
return.b - The blue color value, incremented on each call until it reaches 256.
- Type
- number
initializeCloud(y) → {Object}
Initializes a cloud object with initial properties.
Parameters:
Name | Type | Description |
---|---|---|
y |
number | The y-coordinate of the row being processed. |
- Source:
Returns:
The initialized cloud object.
- Type
- Object
initializeFeatureArrays()
Initializes arrays to hold various features of the world such as maps, rivers,
mountains, forests, and other geographical and cultural elements.
- Source:
initializeWorldSettings()
Initializes the world settings such as drawing type, pixel size, tectonics,
height, and width.
- Source:
mapOutline(context, x, y, color, cell)
Draws an outline of a cell on the canvas at the specified coordinates with the given color.
The color is determined based on the cell's elevation.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasRenderingContext2D | The canvas rendering context. |
x |
number | The x-coordinate where the outline will be drawn. |
y |
number | The y-coordinate where the outline will be drawn. |
color |
string | The color of the outline. Defaults to a calculated color if not specified. |
cell |
Object | The cell object containing elevation information. |
- Source:
markDesertAreas(cloud, nextCell)
Marks areas as desert based on the cloud's moisture level and position within the desert points.
Parameters:
Name | Type | Description |
---|---|---|
cloud |
Object | The cloud object. |
nextCell |
Object | The next cell to be processed. |
- Source:
normalizeTypedArray(imageData) → {Array.<Array.<{r: number, g: number, b: number}>>}
Normalizes the given ImageData object into a 2D array of RGB objects.
Parameters:
Name | Type | Description |
---|---|---|
imageData |
ImageData | The ImageData object to normalize. |
- Source:
Returns:
A 2D array representing the RGB values of the image.
- Type
- Array.<Array.<{r: number, g: number, b: number}>>
populateWorldMap()
Populates the world map with cells. Each cell is initialized with default properties.
- Source:
rollMagma(newCell, oldCell)
Transfers magma from one cell to another.
Ensures that the magma levels between cells are balanced based on a random multiplier.
Parameters:
Name | Type | Description |
---|---|---|
newCell |
Object | The cell to which magma is transferred. |
oldCell |
Object | The cell from which magma is transferred. |
- Source:
setGeographicalPoints()
Sets geographical points such as the equator, steppe top and bottom,
frost points, and desert points based on the world's height.
- Source:
setMoisture()
Simulates the distribution of moisture across a world map.
Iterates through each row of the map, simulating the movement of a cloud that adjusts its moisture level based on the elevation of the cells it encounters.
The cloud's moisture level decreases when moving uphill and increases when moving downhill or over sea-level cells.
Tracks the number of mountains crossed and sets desert properties on cells based on moisture levels and position.
- Source:
spread()
Spreads magma from cells with magma to their adjacent cells.
Rolls magma from one cell to its neighboring cells based on random directions.
- Source:
spreadProcess(num)
Simulates the spreading process over a specified number of iterations.
Each iteration involves clearing rain, emitting magma from spreading centers,
spreading the magma, and setting moisture levels.
Parameters:
Name | Type | Description |
---|---|---|
num |
number | The number of iterations for the spreading process. |
- Source:
spreadingCenterEmits()
Emits magma from the spreading centers.
Increases the magma and elevation of cells in the spreading line by a random amount.
- Source:
spreadingCenterEmitsSmall()
Emits a small amount of magma from the spreading centers.
Increases the magma and elevation of cells in the spreading line by a small random amount.
- Source:
updateMoisture(cloud, currentCell, nextCell)
Updates the moisture level of the cloud based on the elevation difference between the current and next cell.
Parameters:
Name | Type | Description |
---|---|---|
cloud |
Object | The cloud object. |
currentCell |
Object | The current cell being processed. |
nextCell |
Object | The next cell to be processed. |
- Source:
wholeCanvasImage() → {ImageData}
Retrieves the image data from the entire canvas with fixed dimensions.
- Source:
Returns:
The image data object containing pixel information.
- Type
- ImageData
wholeImage() → {ImageData}
Retrieves the image data from the entire canvas based on the world's dimensions.
- Source:
Returns:
The image data object containing pixel information.
- Type
- ImageData
writeLandedTitles()
Generates the landed titles hierarchy for the world, including empires, kingdoms, duchies, counties, and provinces.
The function constructs a string representation of the landed titles in a hierarchical format,
including the RGB color values and the capitals for each level. This string is then converted
to a downloadable text file.
writeProvinceDefinitions()
Generates a CSV file containing province definitions and triggers a download.
The function iterates over all the provinces in the world, creating a CSV string
with the necessary details. It includes both land and ocean provinces, ensuring
that all areas are accounted for.
writeProvinceTerrain()
Writes the terrain data for each province to a downloadable file.
- Source:
writeTitleLocalization()
Generates the localization file for all titles in the world.
This function constructs a string containing the localized names for all titles
(empires, kingdoms, duchies, counties, and provinces) in the world in YAML format.
The string is then converted to a downloadable YAML file.
writeWinterSeverity()
Writes the winter severity bias for each province to a file.
The file is made available for download.
- Source:
xy(x, y) → {object|string}
Retrieves the cell at the specified coordinates from the world map.
Returns "edge" if the coordinates are out of bounds.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x-coordinate. |
y |
number | The y-coordinate. |
- Source:
Returns:
The cell at the specified coordinates or "edge" if out of bounds.
- Type
- object | string