from visual import *
from random import uniform
display(center=(0,2,0),background=(1,1,1), autoscale=False, range=4.5,
width=600, height=600, forward=(-.4,-.3,-1)) #arah kamera
distant_light(direction=(1,1,1), color=color.red)
silinder = cylinder(radius=2, length=4, opacity=.3)
silinder.rotate(angle=pi/2, axis=(0,0,1),origin=(0,0,0))
bola = sphere(color=color.green,radius=.2)
bola.y = 0
bola.x = 0
bola.z = 1
v = vector(2,0,0)
dt = 1./16
r = bola.pos
rc = silinder.radius
def pantul():
global r,v
if mag(r)>=rc:
r = 1.9*norm(r)
vp = (dot(v,norm(r)))*norm(r)
vr = v-vp
v = vr - vp
def proses():
global r,v
a = vector(0,0,0)
v += a*dt
r += v*dt
bola.pos = r
pantul()
while 1:
rate(7)
proses()
.
No comments:
Post a Comment