Skip to main content

Image

WLJS
Execution environment
Supports dynamics

Represents a raster image and plots the list of pixel's colors to a canvas used in notebooks

Image[{row1_List, row2_List...}]

where each row is a list of pixel colors. The color format can be

  • gray-scale 0. - 1.
  • RGB {255,255,255}

Examples

Direct

Show multiple iterations of a cellular automaton as a binary image

Image[CellularAutomaton[30, {{1}, 0}, 40]]

A random noise

Image[Table[RandomInteger[{0,1}], {i, 200}, {j, 350}]]

adding a color

Image[Table[RandomInteger[{0,255}, 3], {i, 200}, {j, 350}]]

Indirect

One can also use Rasterize function to show any expressions as an image

x + y // Rasterize

Dynamics

It does support dynamic variables. For example

Puffer = {{1, 4}, {2, 5}, {3, 1}, {3, 5}, {4, 2}, {4, 3}, {4, 4}, {4, 
5}, {8, 1}, {9, 2}, {9, 3}, {10, 3}, {11, 3}, {12, 2}, {15,
1}, {15, 4}, {16, 5}, {17, 1}, {17, 5}, {18, 2}, {18, 3}, {18,
4}, {18, 5}};
board = CellularAutomaton["GameOfLife", {SparseArray[Puffer -> 1], 0}, {{500}}] // First;
Image[board // Offload]

and now we can run the simulation with a desired speed

task = SetInterval[board = CellularAutomaton["GameOfLife", board, {{1}}] // First,
50
];

SetTimeout[TaskRemove[task], 5000];