Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pendulum, cuma 1 bola, kalo yg lebih dari 1 apalagi yg pk efek damping / nge-per agk rumit, next time
- # joe, 03/01/2015
- import appuifw as A
- import graphics as G
- import math
- sin,cos=math.sin,math.cos
- class Pend2:
- def __init__(self):
- self.L=150 # length
- self.A=45 # angle
- self.AV=0.0 # angle velocity
- self.dt=0.3 # timestep ++
- def update(self,g):
- # 9.81 = gravitasi
- angleAccel=(-9.81/self.L)*sin(self.A)
- self.AV+=angleAccel*self.dt
- self.A+=self.AV*self.dt
- cX,cY=W/2,H/8
- ballX=cX+(sin(self.A)*self.L)
- ballY=cY+(cos(self.A)*self.L)
- g.line((0,cY,W,cY),0xffffff,width=2)
- g.line((cX,cY,ballX,ballY),0xffffff)
- g.point((cX,cY),0,width=4)
- g.ellipse((ballX-SIZE/2,ballY-SIZE/2,ballX+SIZE/2,ballY+SIZE/2),fill=0)
- class App:
- def __init__(self):
- self.run=0
- A.app.screen='full'
- self.c = A.Canvas(redraw_callback=self.redraw,event_callback=None)
- A.app.body=self.c
- A.app.exit_key_handler = self.stop
- def stop(self):
- self.run=0
- def redraw(self,x):
- if BG:
- self.c.blit(BG)
- def play(self):
- self.run=1
- while self.run:
- BG.clear((176,224,230))
- BG.text((5,H-8),u'Pendulum',0,'legend')
- pen.update(BG)
- self.redraw(0)
- A.e32.ao_sleep(1e-04)
- W,H=G.sysinfo.display_pixels()
- SIZE=20
- BG=G.Image.new((W,H))
- pen=Pend2()
- App().play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement