LCB Powder Simulator is an efficient, fully native JS powder simulation that runs on the Canvas 2d API and CDEJS.
A quick and simple Web page to test out the simulation without installing anything!
Link: https://louis-charlesbiron.github.io/LCB_Powder_Sim
- Coming soon!
- Toggleable transparent app background for cool effect :)
- Allows for a fullscreen experience
- More accessible UI (because bigger)
- Runs on NeutralinoJS
- Coming soon!
- A Nice little distraction in the top right of your browser
- More compact UI
For those who know how to code a bit and want have more control over the simulation, here are the NPM and native browser build releases as well as Documentation bellow!
- Coming soon!
- Coming soon!
This section explains what are the available functions and types to control certain aspect of the simulation.
The Simulation class is the core of the simulation and manages all rendering and world manipulation (except for physics).
- CVS -> A CDEJS
Canvasinstance. - readyCB? -> A callback ran once the simulation is started.
(simulation)=>{} - worldStartSettings? -> An object defining the simulation start settings. (Defaults to
DEFAULT_WORLD_START_SETTINGS) - userSettings? -> An object defining the user settings. (Defaults to
DEFAULT_USER_SETTINGS) - colorSettings? -> An object defining the color settings. (Defaults to
DEFAULT_COLOR_SETTINGS)
pixels-> The array containing all materials (might not be directly available when using workers)backStepSavingMaxCount-> The amount of back step saved (Defaults toDEFAULT_BACK_STEP_SAVING_COUNT)isMouseWithinSimulation-> Whether the mouse is inside the simulation bounding boxisRunning-> Whether the simulation is currently runningselectedMaterial-> The material used by default for world manipulation (Defaults toMATERIALS.SAND)brushType-> The shape used to draw materials on the simulation with mouse (Defaults toBRUSH_TYPES.PIXEL)sidePriority-> The side prioritised first by the physics (Defaults toSIDE_PRIORITIES.RANDOM)loopExtra-> A callback called on each rendered frame (Defaults tonull)stepExtra-> A callback called on each physics step (Defaults tonull)
WorldStartSettings:
autoStart-> Whether the simulation automatically starts once instanciated. (Defaults to true)usesWebWorkers-> Whether the physics calculations are offloaded to a worker thread. (RECOMMENDED) (Defaults to true)aimedFPS-> The desired frame per seconds. (Defaults to60) (Putnullfor V-Sync)zoom-> The base zoom value. (Defaults to1)
Note: The following world start settings are only work when autoSimulationSizing is not set.
cameraCenterPos-> The camera center position. (Defaults to the center of the map)mapWidth-> The base width of the map. (Defaults toMapGrid.DEFAULT_MAP_WIDTH)mapHeight-> The base height of the map. (Defaults toMapGrid.DEFAULT_MAP_HEIGHT)mapPixelSize-> The base size of the map pixels. (Defaults toMapGrid.DEFAULT_MAP_PIXEL_SIZE)
UserSettings:
autoSimulationSizing-> If a number, automatically resizes the simulation based the provided number, as pixel size. Disabled otherwise.dragAndZoomCanvasEnabled-> Whether the user can use left click to move around and wheel to zoom (Defaults to true)warningsDisabled-> Hides warning messages from console (Defaults to false)showBorder-> If true, displays the bounding box of the simulation (Defaults to true)showGrid-> If true, displays a grid over the simulation to delimit pixels (Defaults to true)zoomInIncrement/zoomOutIncrement-> Defines the increment value for zooming in/out (Defaults to0.25/-0.2)minZoomThreshold/maxZoomThreshold-> Defines the min/max zoom threshold values (Defaults to0.1/Infinity)smoothDrawingEnabled-> Whether to fill gaps between mouse event for smoother drawing (Defaults to true)visualEffectsEnabled-> Whether to display some visual effect (Defaults to true) [MAYBE AFFECT PERFORMANCE]
ColorSettings: This object allows the color customization of the grid and materials.
grid,border-> The color of the grid and border of the map.[r,g,b,a]AIR,SAND,WATER, ... -> The color of each material. (The key must be in UPPERCASE)[r,g,b,a]
The MapGrid class is mostly used internally to handle the simulation world space / dimensions.
It still provides informative world functions such as getLocalMapPixel, getAdjacency, indexToMapPos, mapPosToIndex as well as the mapWidth / mapHeight in both local and global pixels.
This section will go over pretty much all available functions to control the simulation.
readyCB-> A callback ran once the simulation is started.(simulation)=>{}(Defined in the Simulation's constructor)
This can be used to update map properties / import a world as soon as the simulation is started.
widthThe new width of the map (local px)heightThe new height of the map (local px)
- updateMapPixelSize(pixelSize?) -> Updates the map pixel size. (Defaults to MapGrid.DEFAULT_PIXEL_SIZE)
pixelSizeThe new map pixel size (global px)
- autoFitSize(pixelSize?, globalWidth?, globalHeight?) ->Updates map size and pixel size automatically based on the optimal fit for the provided sizes.
pixelSizeThe desired map pixel size (global px) (Defaults toDEFAULT_MAP_RESOLUTIONS.DEFAULT)globalWidthThe width to cover (global px) (Defaults to the canvas width)globalHeightThe height to cover (global px) (Defaults to the canvas height)
sidePriorityThe new side priority. One ofSIDE_PRIORITIES. (Defaults toSIDE_PRIORITIES.RANDOM)
- updatePhysicsUnitType -> Updates whether the physics calculations are offloaded to a worker thread.
usesWebWorkersWhether an other thread is used. (Defaults totrue)
forceIf true, forces the start even if simulation is already running.
materialThe materials to select. One ofMATERIALS
- updateBrushType(brushType) -> Updates the shape used to draw materials on the simulation with mouse.
brushTypeThe brush type to use -> One ofBRUSH_TYPES
colorSettingsThe colors to update
- placePixel(mapPos, material?) (Similarly placePixelAtCoords, placePixelAtIndex) -> Places a pixel on the map.
mapPosThe map position of the pixel ([x,y])materialThe material used, one ofMATERIALS. (Defaults to the selected material)
- placePixelsWithBrush(x, y, brushType?) -> Places pixels at the specified coordinates, according to the provided brush pattern.
xThe X value of the center positionsyThe Y value of the center positionsbrushTypeThe brush type used, one ofBRUSH_TYPES. (Defaults to the current brush type)
materialThe material used, one ofMATERIALS. (Defaults to the selected material)
pos1The top-left pos of the area ([leftX, topY])pos2The bottom-right pos of the area ([rightX, bottomY])materialThe material used, one ofMATERIALS. (Defaults to the selected material)
mapDataThe save data. (String,Uint16Array,Object)- Either a string in the format given by the function
exportAsText() - Or a
Uint16Arraycontaining the material value for each index - Or an
Objectcontaining the material value for each index{"index": material}
- Either a string in the format given by the function
useSaveSizes?Whether to resize the map size and pixel size to the save's values
disableCompactingWhether to disable the text compacting (not recommended for large maps) (Defaults tofalse)callbackIf using web workers, use this callback to retrieve the return value(stringValue)=>{...}
mapPosThe map pos ([x,y])
- updateImgMapFromPixels(force?) -> Updates the display image map according to the pixels array (Basically, renders a frame)
forceIf true, disables optimization and forces every pixel to get redrawn (mostly used internally)
There are multiple material enums available each describing different properties:
AIR-> Represents an empty pixel.SAND-> Falls in air and liquids, forms pile of itself.WATER-> Falls in air, spreads horizonally once grounded.STONE-> A solid block that stands still, and doesn't interact.GRAVEL-> Falls in air in liquids, but doesn't form pile of itself.INVERTED_WATER-> Water, but with inverted gravity.CONTAMINANT-> Acts like water, but spreads in other liquids.LAVA-> Acts like water, but slowed down. Transforms into stone when in contact with liquids. Slowly melts away some other materials.ELECTRICITY-> TODO. Can interact with some materials.COPPER-> Similar to stone, but can get lit by electricity.
TRANSPIERCEABLE-> A group of materials some other can fall through. (AIR, WATER, INVERTED_WATER, CONTAMINANT)LIQUIDS-> A group of liquids. (WATER, INVERTED_WATER, CONTAMINANT)CONTAMINABLE-> A group of materials that can be contaminated. (WATER, INVERTED_WATER)MELTABLE-> A group of materials that can be melted. (SAND, GRAVEL)
EMPTY-> No statesCOPPER:LIT-> Represents lit copperORIGIN-> Represents lit copper in direct contact with electricityDISABLED-> Represents unlit copper
All brushes available are given in the BRUSH_TYPES enum:
PIXEL-> Draws a single pixel.VERTICAL_CROSS-> Draws pixels in a+symbol.LINE3-> Draws pixels in a|symbol.ROW3-> Draws pixels in a-symbol.BIG_DOT-> Draws pixels in a fat dot symbol.X3-> Draws pixels in a 3x3 square.X5-> Draws pixels in a 5x5 square.X15-> Draws pixels in a 15x15 square.X25-> Draws pixels in a 25x25 square.X55-> Draws pixels in a 55x55 square.X99-> Draws pixels in a 99x99 square.
Made by Louis-Charles Biron !
Every line of code and documentation in this repository was written by hand with passion!

