Skip to main content

Simple Animation In Python

 ⚠️⚠️⚠️If you are unable to copy the code, then copy whole page.

Source code:

from matplotlib import animation, pyplot as plt
from matplotlib.axes import Axes
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.figure import Figure
import numpy as np
import numpy.typing as npt

LIMITS = (-50, 50)
class DrawAnimation:
    def __init__(self) -> None:
        self.fig:Figure=plt.figure(figsize=(20,6))
        self.ax=self.fig.add_subplot(111,projection=Axes3D.name)
        self.fig.subplots_adjust(top=1.1, bottom=-0.1)
        self.func_=lambda x, y: x*y**3-y*x**3

    
    def set_theme(self) -> None:
        self.fig.patch.set_facecolor('black')
        self.ax.set_facecolor('black')
        self.ax.get_yaxis().set_visible(False)
        self.ax.get_xaxis().set_visible(False)
        self.ax.set_axis_off()

    def get_color(self) -> npt.NDArray[np.float_]:
        return np.random.random(4)

    def animation_func(self, i) -> None:
        speed=1e-2
        width=100
        ani=width*np.sin(i*speed)**4
        render=np.linspace(-ani, ani, 10)
        x, y = np.meshgrid(render, render)
        pos = np.empty(x.shape + (2,))
        pos[:, :, 0] = x; pos[:, :, 1] = y
        z=np.array([self.func_(px, py) for px, py in zip(x, y)])
        self.ax.clear()
        self.set_theme()
        self.ax.contour(x, y, z, 50, cmap='binary')
        self.ax.view_init(60, 35)
        self.ax.plot_surface(x, y, z, rstride=1, cstride=1,
                cmap='viridis', edgecolor='none')
        plt.xlim(*LIMITS)
        plt.ylim(*LIMITS)

drawAnimation = DrawAnimation()
drawAnimation.set_theme()
ani_ = animation.FuncAnimation(
    drawAnimation.fig,
    drawAnimation.animation_func,
    interval=100
)

plt.show()

Thank you, all.


Comments

Popular posts from this blog

Make calculator in python

 Hello everyone, hope you all are fit and fine. ⚠️⚠️⚠️If you are unable to copy the code, then copy whole page. Source Code:      #Calculator def calculator():          print("\n Welcome to the Calculator:\n Programmed by Coder_of_Paradise")                   operation = input('''     Type of operations can be hold in this calculator     + for addition     - for substraction     * for multiplication     / for division     ** for power     Enter your choice ;     ''')        num1 = int(input("Enter your first number : "))          num2 = int(input("Enter your second number : "))          if operation == '+':         print(f"{num1}+{num2}={num1+num2}")              elif operation == '-':  ...

Beautiful square shape design

 What's up everyone, welcome again. Today we have a new design in python turtle module. Watch on YouTube: ⚠️⚠️If you are unable to copy the code, then copy whole page. Source Code: #SO HELLO EVERYONE #TODAY WE HAVE A NEW THING #WE HAD MAINLY USED FORWARD, BACKWARD, LEFT, RIGHT COMMAND OF TURTLE MODULE #SO PLEASE BE WITH ME TILL THE END OF THE VIDEO #SO LETS START"""" #please take screenshots import turtle window = turtle.Screen() window.bgcolor("blue") v = turtle.Turtle() v.speed(10) pc = v.pencolor fc = v.fillcolor ps= v.pensize f = v.forward b = v.backward l = v.left r = v.right #square v.fillcolor("black") v.begin_fill() ps(6) pc("red") b(150) f(300) l(90) f(300) l(90) f(300) l(90) f(300) v.end_fill() #digonals v.fillcolor("blue") v.begin_fill() ps(6) pc("red") l(135) f(420) b(210) l(90) f(210) b(420) f(210) #corner l(135) f(60) b(120) f(60) l(90) f(60) b(120) #join l(120) f(165) r(150) f(165) l(60) f(165) r(1...

Cool python turtle graphic

 Hello everyone, hope you all are fit and fine. ⚠️⚠️⚠️If you are unable to copy the code, then copy whole page. Watch on YouTube: Source Code: from turtle import* import colorsys speed(0) fd(170) he = 0.8 bgcolor("black") for i in range(200):       col=colorsys.hsv_to_rgb(he,1,1)     he+=0.004     fillcolor(col)     def triangle(a,b,c):         lt(120)         fd(a-i)         lt(120)         fd(b-i)         lt(90)         fd(c-i)     begin_fill()     triangle(200,200,200)     left(10)     left(20)     left(90)     triangle(200,200,200)     right(93)     end_fill()     hideturtle() done()     #it is going to be very cool  #design #please watch till end Thank you, all.