0% found this document useful (0 votes)
19 views2 pages

Code 4

The document contains a Python script that simulates the trajectory of a projectile using Matplotlib. It calculates the motion based on an initial velocity and angle, animating the path and displaying an image of a ball. The animation is saved as a GIF file named 'animasi_bola.gif'.

Uploaded by

FATURRAHMAN 98
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Code 4

The document contains a Python script that simulates the trajectory of a projectile using Matplotlib. It calculates the motion based on an initial velocity and angle, animating the path and displaying an image of a ball. The animation is saved as a GIF file named 'animasi_bola.gif'.

Uploaded by

FATURRAHMAN 98
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NAMA : Muhammad febrian faturrahman

KLS : IK-5

NIM : 0701242114

CODE SIMULASI 4

import [Link] as plt


from [Link] import FuncAnimation, PillowWriter
import [Link] as mpimg
import [Link] as transforms
import math
def hitung_lintasan(alfa, t):
Vo = 50
g = 10
cosa = [Link](alfa * [Link] / 180)
sina = [Link](alfa * [Link] / 180)
x = Vo * cosa * t
y = Vo * sina * t - 0.5 * g * t**2
return x, y
def PhysProb():
fig, ax = [Link]()
[Link](xlim=(-20, 300), ylim=(-20, 160))
ax.set_aspect(1)
[Link]('off')
Vo = 50
alfa = 75
g = 10
tmax = 2 * Vo * [Link](alfa * [Link] / 180) / g
n_frames = 100
t_values = [i * tmax / n_frames for i in range(n_frames)]
x_vals = []
y_vals = []
for t in t_values:
x, y = hitung_lintasan(alfa, t)
x_vals.append(x)
y_vals.append(y)
garis, = [Link]([], [], color='blue')
# Load gambar PNG sekali saja
img = [Link]('[Link]') # Pastikan file ini ada
def init():
garis.set_data([], [])
return garis,
def update(frame):

[Link]()
[Link](xlim=(-20, 300), ylim=(-20, 160))
ax.set_aspect(1)
[Link]('off')
[Link](x_vals[:frame+1], y_vals[:frame+1], color='blue')
x = x_vals[frame]
y = y_vals[frame]
# Sudut rotasi (dalam derajat)
total_rotasi = 360
sudut = frame / (n_frames - 1) * total_rotasi
# Buat transformasi rotasi dan translasi
trans_data = transforms.Affine2D().rotate_deg_around(x, y, sudut).translate(0, 0) +
[Link]
# Tampilkan gambar sebagai pengganti pemukul
[Link](img, extent=[x-40, x+40, y-30, y+30], transform=trans_data)
anim = FuncAnimation(fig, update, frames=n_frames, init_func=init, interval=100)
[Link]("animasi_bola.gif", writer=PillowWriter(fps=10))
[Link]()
PhysProb()

You might also like