Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

11th grade-all tasks

2151 views
Kernel: Python 3 (Anaconda)
import numpy as np from matplotlib import pyplot as plt import matplotlib.patches as patches from matplotlib import animation from IPython.display import HTML
fig = plt.figure() fig.set_size_inches(12,2) d=50 x1, x2 = -10, d v1 = 5 a = 0 v2 = 9 dt = 0.1 a1 = 0 ax = plt.axes(xlim=(-10, 200), ylim=(-4, 20)) t1 = plt.text(-x1, 0., "train1", size=10, bbox=dict(boxstyle="round", ec=(1., 0.5, 0.5), fc=(1., 0, 0), ) ) t2 = plt.text(x2, 0., "train2", size=10, bbox=dict(boxstyle="round", ec=(0., 1, 0.5), fc=(0.,1, 0), ) ) plt.plot([0, 200],[0, 0], lw =2 ,c = 'k') def init(): return [t1, t2] def animate(i): global x1, x2, v1, a v1 += a * dt x1 += v1 * dt x2 += v2 *dt t1.set_x(x1) t2.set_x(x2) return [t1,t2]
Image in a Jupyter notebook
d=50 x1, x2 = -10, d v1 = 10 a = -0.25 v2 = 5 dt = 0.1 a1 = 0 anim = animation.FuncAnimation(fig, animate, init_func=init, frames=200, interval=20, blit=True) HTML(anim.to_html5_video())
WARNING: Some output was deleted.