Ask Your Question

How can I animate this in Jupyter Notebook? Any animation will do

asked 2023-11-25 14:42:04 +0100

Czev gravatar image

updated 2023-11-25 18:40:05 +0100

Please help to animate this:

def ModularColor(L):
    n = len(L)
    board = Graphics()

    for i in range(2*n):
        for j in range(2*n):
            k = (i+j)%n
            color = L[k]
            corners=[(j,i), (j+1,i), (j+1,i+1), (j,i+1)]
            chessboard=polygon2d(corners, axes=false, color=color,)
    return board

KULAYS=['dodgerblue', 'mediumseagreen', 'gold', 'orangered']
edit retag flag offensive close merge delete


What is it that you would like to animate? I only see one image.

John Palmieri gravatar imageJohn Palmieri ( 2023-11-25 18:41:09 +0100 )edit

Something like import itertools and then animate((ModularColor(list(L)) for L in itertools.permutations(KULAYS)))? The animate function takes a list of images and produces an animation. Is that what you're looking for?

John Palmieri gravatar imageJohn Palmieri ( 2023-11-25 18:44:35 +0100 )edit

that one works. thank you! now that i know that it can be animated, is it possible to animate it differently? like different movement?

Czev gravatar imageCzev ( 2023-11-27 07:36:25 +0100 )edit

My very first question was, "what is it that you would like to animate?" Of course it's possible to animate it differently, but without an example of what you want, I have no idea what to suggest. Anyway, I hope this is enough information to get you started.

John Palmieri gravatar imageJohn Palmieri ( 2023-11-27 18:07:26 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-11-27 18:05:37 +0100

The animate command will animate any sequence of plots. So choose the plots you want to display, in order, and plug that into animate. For example,

import itertools
KULAYS=['dodgerblue', 'mediumseagreen', 'gold', 'orangered']
[list(L) for L in itertools.permutations(KULAYS)]

will return the permutations of the colors in KULAYS in some order, and so

animate((ModularColor(list(L)) for L in itertools.permutations(KULAYS)))

will produce an animation with one "frame" for each different permutation.

If you want a different kind of animation, choose a different sequence of pictures for animate. See also the documentation.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2023-11-25 14:42:04 +0100

Seen: 81 times

Last updated: Nov 27 '23