Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ pub struct Universe {
}

impl Universe {
fn get_index(&self, row: u32, column: u32) -> usize {
(row * self.width + column) as usize
}

/// Get the dead and alive values of the entire universe.
pub fn get_cells(&self) -> &[Cell] {
&self.cells
Expand Down Expand Up @@ -126,6 +122,10 @@ impl Universe {
/// Public methods, exported to JavaScript.
#[wasm_bindgen]
impl Universe {
pub fn get_index(&self, row: u32, column: u32) -> usize {
(row * self.width + column) as usize
}

pub fn tick(&mut self) {
// let _timer = Timer::new("Universe::tick");

Expand Down
8 changes: 2 additions & 6 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ const drawGrid = () => {
ctx.stroke();
};

const getIndex = (row, column) => {
return row * width + column;
};

const drawCells = () => {
const cellsPtr = universe.cells();
const cells = new Uint8Array(memory.buffer, cellsPtr, width * height);
Expand All @@ -135,7 +131,7 @@ const drawCells = () => {
ctx.fillStyle = ALIVE_COLOR;
for (let row = 0; row < height; row++) {
for (let col = 0; col < width; col++) {
const idx = getIndex(row, col);
const idx = universe.get_index(row, col);
if (cells[idx] !== Cell.Alive) {
continue;
}
Expand All @@ -153,7 +149,7 @@ const drawCells = () => {
ctx.fillStyle = DEAD_COLOR;
for (let row = 0; row < height; row++) {
for (let col = 0; col < width; col++) {
const idx = getIndex(row, col);
const idx = universe.get_index(row, col);
if (cells[idx] !== Cell.Dead) {
continue;
}
Expand Down