Graphics and Animation software recommendations

Click For Summary
To create an animation of a knight moving on a chessboard using Python, one can generate frames using libraries like Matplotlib and then compile them into a video with ffmpeg. For interactive graphics, options like Pygame or GlowScript are recommended, as they allow for more dynamic visualizations. The discussion also highlights the use of Python libraries such as chess and chess.svg to render chess positions, which can be converted to images for display. Integrating these animations into a web page requires knowledge of HTML and JavaScript, as web browsers primarily support these languages for dynamic content. Overall, the conversation emphasizes the need to understand how various software components work together to achieve the desired animation.
  • #31
Sorry no time to do something custom but here is an example of what can be easily achieved:
https://chessboardjs.com/examples/3004

Note that the only code that has been written to achieve that is what follows, everything else is in the libraries.
JavaScript:
var board = Chessboard('myBoard', 'start')

$('#move1Btn').on('click', function () {
  board.move('e2-e4')
})

$('#move2Btn').on('click', function () {
  board.move('d2-d4', 'g8-f6')
})

$('#startPositionBtn').on('click', board.start)
 
Computer science news on Phys.org
  • #32
PeroK said:
That's the plan: to learn HTML and JavaScript next. Started that today.

Excellent! The chessboard module I linked uses some modern concepts that you may not encounter for a while so I drafted something for you to crib as a head start below. Note that this is not going to work in Internet Explorer.



JavaScript:
// We are using ES6 imports so this needs to be inside script type="module" -
// this is handled automatically in CodePen.
import { Chessboard } from "https://cdn.jsdelivr.net/npm/cm-chessboard@3/src/cm-chessboard/Chessboard.js";
// Note we have also loaded the following module which creates the Chess global.
// https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.11.0/chess.min.js

// Set up a 'game' in FEN.
const game = new Chess("8/8/8/8/8/8/8/1N6 w - - 0 1");

// Some moves in PGN.
const moves = "b1-c3,c3-a2,a2-c1,c1-b3,b3-a1,a1-c2,c2-a3,a3-b2".split(",");

// Select DOM element as a target.
const el = document.querySelector("#board");
// Set the sprites to use for pieces (the default doesn't work when loading from a CDN).
const url =
  "https://cdn.jsdelivr.net/npm/cm-chessboard@3/assets/images/chessboard-sprite-staunty.svg";

// Create the board.
const board = new Chessboard(el, {
  sprite: { url },
  // Move more slowly (default 300ms).
  animationDuration: 1000
});

// Log a move into the DOM.
function logMove(move) {
  document.querySelector("#moves").innerHTML += ` ${move.slice(-2)}`;
}

// Mark a move on the board.
function markMove(move) {
  board.addMarker(move.slice(-2));
}

// This function is declared asynchronous so we can use 'await'.
async function play() {
  // Log the initial position;
  document.querySelector("#moves").innerHTML = moves[0].substring(0, 2);

  // Set up the board then mark the initial position.
  await board.setPosition(game.fen());
  board.addMarker(moves[0].substring(0, 2));

  // Iterate through the moves.
  for (let i = 0; i < moves.length; ++i) {
    const move = moves[i];
    logMove(move);

    // Try to execute the move.
    if (!game.move(move, { sloppy: true })) {
      // Log an illegal move and stop playing.
      document.querySelector("#moves").innerHTML += " Illegal move";
      break;
    }
    // The move was successful so execute the move on the board and mark the square.
    // Note that setPosition() returns a Promise that is resolved when the move is
    // complete, so wait for it before continuing.
    await board.setPosition(game.fen());
    markMove(move);

    // Reset the game from the displayed board otherwise it will be black's turn!
    game.load(board.getPosition() + " w - - 0 1");
  }
}

// Wait for a bit before we start moving things around.
const timer = setTimeout(play, 2000);
 
  • Like
Likes PeroK

Similar threads

Replies
4
Views
2K
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
3K
  • · Replies 70 ·
3
Replies
70
Views
5K
Replies
7
Views
3K
  • · Replies 29 ·
Replies
29
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 380 ·
13
Replies
380
Views
29K