Skip to content

Instantly share code, notes, and snippets.

@sjdonado
Created May 8, 2023 18:55
Show Gist options
  • Save sjdonado/7bc69d063192a725552d4fd28ac103be to your computer and use it in GitHub Desktop.
Save sjdonado/7bc69d063192a725552d4fd28ac103be to your computer and use it in GitHub Desktop.
Tower of Hanoi in P5.js + WASM - Dev.to
if (isMovingHorizontallly) {
if (animation.currentMove.start < animation.currentMove.end) {
refreshCanvas(p5);
drawDiskByCoordinates(
p5,
animation.currentDisk,
animation.currentMove.start,
draw.topMargin,
);
animation.currentMove.start += game.speed;
if (animation.currentMove.start >= animation.currentMove.end) {
animation.currentMove.start = animation.currentMove.end;
animation.currentMove.down = draw.topMargin;
}
}
if (animation.currentMove.start > animation.currentMove.end) {
refreshCanvas(p5);
drawDiskByCoordinates(
p5,
animation.currentDisk,
animation.currentMove.start,
draw.topMargin,
);
animation.currentMove.start -= game.speed;
if (animation.currentMove.start <= animation.currentMove.end) {
animation.currentMove.start = animation.currentMove.end;
animation.currentMove.down = draw.topMargin;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment