Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea for Game of Life #1

Open
kai17kai opened this issue Jun 22, 2021 · 2 comments
Open

Idea for Game of Life #1

kai17kai opened this issue Jun 22, 2021 · 2 comments

Comments

@kai17kai
Copy link

Something I did when I create the Game of Life was a drag and click thing. I noticed that you didn't add this feature to the Game of Life on your website. Github, for some odd reason, doesn't support .js files so here is the code.

`let drag = false, moved = false;

canvas.onmouseup = (event) => {
drag = moved;
let x = (event.clientX-rect.left)(canvas.width/rect.width);
let y = (event.clientY-rect.top)
(canvas.height/rect.height);
let col = Math.floor(x/cell_width);
let row = Math.floor(y/cell_width);
if (!drag) {
grid[row][col][0] ^= 1;
} else {
grid[row][col][0] = 1;
drag = false;
}
moved = false;
save_grid();
clear();
grid_to_canvas();
}

canvas.onmousedown = () => {
generations = 0;
print_generations();
stop();
drag = true;
}

canvas.onmousemove = (e) => {
if (drag) {
moved = true;
let x = (e.clientX - rect.left) * (canvas.width / rect.width);
let y = (e.clientY - rect.top) * (canvas.height / rect.height);
x = Math.floor(x / cell_width);
y = Math.floor(y / cell_width);
grid[y][x][0] = 1;
save_grid();
clear();
grid_to_canvas();
}
}`

@boris-volkov
Copy link
Owner

boris-volkov commented Jun 24, 2021 via email

@kai17kai
Copy link
Author

kai17kai commented Jun 24, 2021

I only meant for the error to happen with the downloadable games because one of the games is only built for mac and windows at the moment. I will need to fix that but thank you for telling me that.

Also, the background is from Prisha so give credit to her for the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants