Friday, May 30, 2014

Bouncing Ball using Python on iPhone

Here the code

I use Pythonista on iOS



class MyScene (Scene):
  def setup(self):
    self.x=10.
    self.y=10.
    self.vx=137.
    self.vy=153.
    self.dt=1/64
    pass
  def draw(self):
    background(1,1,1)
    fill(0,1,0)
    if(self.x>=self.size.w)or(self.x<=0):
      self.vx*=-1
    if(self.y>=self.size.h)or(self.y<=0):
      self.vy*=-1
    
    self.x+=self.vx*self.dt
    self.y+=self.vy*self.dt

    ellipse(self.x,self.y,10,10)

run(MyScene())