Skip to content

Commit

Permalink
boom
Browse files Browse the repository at this point in the history
  • Loading branch information
BobdaProgrammer committed May 25, 2024
1 parent 9cf3221 commit 5edce68
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div align="center">
<h1>falling sand simulator</h1>
</div>
An amazing sand similator in pure HTML, CSS and JS. No frameworks at all!
Calm yourself watching colour changing sand fall softly down. Make stunning pyramids and colourful creations of sand. Play about with it.

Take a look at some examples:
<img src="./README_FILES/colourfulsnow.png" style="max-width: 200px;">
<img src="./README_FILES/pyramids.png" style="max-width: 200px;">
<img src="./README_FILES/bigpyramid.png" style="max-width: 200px;">
Binary file added README_FILES/bigpyramid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README_FILES/colourfulsnow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README_FILES/pyramids.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 16 additions & 12 deletions canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,23 @@ function mouseDown(event) {
function onMouseMove(event) {
x = parseInt(event.offsetX / 4);
y = parseInt(event.offsetY / 4);
if (grid[y][x][0] != 1) {
grid[y][x] = [1, hue];
const randomNumber = Math.floor(Math.random() * 4) + 1;
const randomNumber1 = Math.floor(Math.random() * 4) + 1;
if (y != grid.length - 1 && (randomNumber == 1 || randomNumber1 == 1)) { grid[y + 1][x] = [1, hue]; }
if (x != grid[y].length && (randomNumber == 2 || randomNumber1 == 2)) { grid[y][x + 1] = [1, hue]; }
if (x != 0 && (randomNumber == 3 || randomNumber1 == 3)) { grid[y][x - 1] = [1, hue]; }
if (y != 0 && (randomNumber == 4 || randomNumber1 == 4)) { grid[y - 1][x] = [1, hue]; }
if (isDraw == false) {
isDraw = true;
document.getElementById("state").innerText = "Running";
draw();
try {
if (grid[y][x][0] != 1) {
grid[y][x] = [1, hue];
const randomNumber = Math.floor(Math.random() * 4) + 1;
const randomNumber1 = Math.floor(Math.random() * 4) + 1;
if (y != grid.length - 1 && (randomNumber == 1 || randomNumber1 == 1)) { grid[y + 1][x] = [1, hue]; }
if (x != grid[y].length && (randomNumber == 2 || randomNumber1 == 2)) { grid[y][x + 1] = [1, hue]; }
if (x != 0 && (randomNumber == 3 || randomNumber1 == 3)) { grid[y][x - 1] = [1, hue]; }
if (y != 0 && (randomNumber == 4 || randomNumber1 == 4)) { grid[y - 1][x] = [1, hue]; }
if (isDraw == false) {
isDraw = true;
document.getElementById("state").innerText = "Running";
draw();
}
}
} catch (error) {

}
}
if (mouseUp == false) {
Expand Down

0 comments on commit 5edce68

Please sign in to comment.