Skip to content

Commit 5edce68

Browse files
boom
1 parent 9cf3221 commit 5edce68

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div align="center">
2+
<h1>falling sand simulator</h1>
3+
</div>
4+
An amazing sand similator in pure HTML, CSS and JS. No frameworks at all!
5+
Calm yourself watching colour changing sand fall softly down. Make stunning pyramids and colourful creations of sand. Play about with it.
6+
7+
Take a look at some examples:
8+
<img src="./README_FILES/colourfulsnow.png" style="max-width: 200px;">
9+
<img src="./README_FILES/pyramids.png" style="max-width: 200px;">
10+
<img src="./README_FILES/bigpyramid.png" style="max-width: 200px;">

README_FILES/bigpyramid.png

179 KB
Loading

README_FILES/colourfulsnow.png

42.7 KB
Loading

README_FILES/pyramids.png

178 KB
Loading

canvas.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,23 @@ function mouseDown(event) {
6464
function onMouseMove(event) {
6565
x = parseInt(event.offsetX / 4);
6666
y = parseInt(event.offsetY / 4);
67-
if (grid[y][x][0] != 1) {
68-
grid[y][x] = [1, hue];
69-
const randomNumber = Math.floor(Math.random() * 4) + 1;
70-
const randomNumber1 = Math.floor(Math.random() * 4) + 1;
71-
if (y != grid.length - 1 && (randomNumber == 1 || randomNumber1 == 1)) { grid[y + 1][x] = [1, hue]; }
72-
if (x != grid[y].length && (randomNumber == 2 || randomNumber1 == 2)) { grid[y][x + 1] = [1, hue]; }
73-
if (x != 0 && (randomNumber == 3 || randomNumber1 == 3)) { grid[y][x - 1] = [1, hue]; }
74-
if (y != 0 && (randomNumber == 4 || randomNumber1 == 4)) { grid[y - 1][x] = [1, hue]; }
75-
if (isDraw == false) {
76-
isDraw = true;
77-
document.getElementById("state").innerText = "Running";
78-
draw();
67+
try {
68+
if (grid[y][x][0] != 1) {
69+
grid[y][x] = [1, hue];
70+
const randomNumber = Math.floor(Math.random() * 4) + 1;
71+
const randomNumber1 = Math.floor(Math.random() * 4) + 1;
72+
if (y != grid.length - 1 && (randomNumber == 1 || randomNumber1 == 1)) { grid[y + 1][x] = [1, hue]; }
73+
if (x != grid[y].length && (randomNumber == 2 || randomNumber1 == 2)) { grid[y][x + 1] = [1, hue]; }
74+
if (x != 0 && (randomNumber == 3 || randomNumber1 == 3)) { grid[y][x - 1] = [1, hue]; }
75+
if (y != 0 && (randomNumber == 4 || randomNumber1 == 4)) { grid[y - 1][x] = [1, hue]; }
76+
if (isDraw == false) {
77+
isDraw = true;
78+
document.getElementById("state").innerText = "Running";
79+
draw();
80+
}
7981
}
82+
} catch (error) {
83+
8084
}
8185
}
8286
if (mouseUp == false) {

0 commit comments

Comments
 (0)