Beispiel #1
0
def handle_frame():
  global P
  sleep(P.SleepTime)
  
  clear_values()
  if keys["q"] == 1:
    P.T = P.T + 0.05
  if keys["a"] == 1:
    P.T = P.T - 0.05
  if keys["w"] == 1:
    P.B = P.B + 0.05
  if keys["s"] == 1:
    P.B = P.B - 0.05
  if toggle_keys["e"] == 1:
    P.T = P.T + 0.002
  if toggle_keys["d"] == 1:
    P.T = P.T - 0.002
  
  for i in range(0,P.MetSteps):
    s.MetropolisAlg2()
  print_params(P)
  print_magnetisation(s)
  draw_mag_square(ColourString1, ColourString2, s.Magnetisation())
  
  G.AddPoint(P.T, s.Magnetisation(), P.B )
  
  #Needed to keep lattice up to date
  global frame_count
  frame_count = frame_count + 1
  
  if(frame_count % 30):
    draw_lattice(s)
Beispiel #2
0
def handle_frame():
  sleep(30)  
  global phi, theta, alpha, dphi, dtheta, dalpha
  
  phi=phi+dphi
  theta=theta+dtheta
  alpha=alpha+dalpha
    
    

  color("white")
  box(0,0,screen_width,screen_height)
  color("black")
  linethree(-100,-100,-100,100,-100,-100)
  linethree(100,-100,-100,100,-100,100)
  linethree(100,-100,100,-100,-100,100)
  linethree(-100,-100,-100,-100,-100,100)
  linethree(-100,100,-100,100,100,-100)
  linethree(100,100,-100,100,100,100)
  linethree(100,100,100,-100,100,100)
  linethree(-100,100,-100,-100,100,100)
  linethree(-100,-100,-100,-100,100,-100)
  linethree(-100,-100,100,-100,100,100)
  linethree(100,-100,100,100,100,100)
  linethree(100,-100,-100,100,100,-100)
Beispiel #3
0
def handle_frame():
    global last_frame
    if age() - last_frame < 1. / 30.:
        print "dropping frame"
        return

    draw()

    last_frame = age()
    sleep(1000. / 30.)
Beispiel #4
0
def handle_frame():
    global last_frame
    if now() - last_frame < 1. / 30.:
        #print "dropping frame"
        return

    draw()

    last_frame = now()
    sleep(1000. / 30. - 10)
def handle_frame():
  global last_frame
  if age() - last_frame < 1./30.:
    print "dropping frame"
    return
  
  draw()
  
  last_frame = age()
  sleep(1000./30.)
    
Beispiel #6
0
def handle_frame():
  global m_a
  
  color("white")
  box(0,0,screen_width,screen_height)
  
  for i in range(0,25,1):
    color("hsl(0,100%," + str(i*4) + "%)")
    fill_triangle(200,200,200-i*6,2*i*m_a)
  
    color("hsl(0,100%," + str(i*4-20) + "%)")
    triangle(200,200,200-i*6,2*i*m_a)
    
  m_a += 0.002
  
  sleep(30)
Beispiel #7
0
def handle_frame():
  global sr, sb, gameend, e3, redcount, bluecount
  if gameend==0:
    
    sleep(20)
    color("white")
    box(0,0,screen_width,screen_height)
    color("black")
    circle(screen_width/2,screen_height/2,domain+radius)
    color("rgba(255,0,0,1)")
    circle(screen_width/2-domain/2,screen_height/2,hipporadius)
    color("rgba(255,0,255,1)")
    circle(screen_width/2,screen_height/2-domain/2,hipporadius)
    color("rgba(255,100,0,1)")
    circle(screen_width/2,screen_height/2+domain/2,hipporadius)
    color("rgba(0,0,255,1)")
    circle(screen_width/2+domain/2,screen_height/2,hipporadius)
    
    for i in range (0,4*n+1):
      #a[d*i+8]=-a[d*i]/1000
      #a[d*i+9]=-a[d*i+1]/1000
      a[d*i]=a[d*i]+a[d*i+2]
      a[d*i+1]=a[d*i+1]+a[d*i+3]
      
      
      a1=a[d*i]-screen_width/2
      a2=a[d*i+1]-screen_height/2
      aa=sqrt(a1*a1+a2*a2)
      a[d*i+8]=-mu*a[d*i+2]-g*a1/aa
      a[d*i+9]=-mu*a[d*i+3]-g*a2/aa
    
      a[d*i+2]=a[d*i+2]*1+a[d*i+8]
      a[d*i+3]=a[d*i+3]*1+a[d*i+9]
     
    
    for i in range (0,4*n+1):
      c=[a[d*i+4],a[d*i+5],a[d*i+6],1]
      colstring = ctorgba(c)
      color(colstring)
      spot(a[d*i],a[d*i+1],radius)
    if i==4*n:
      color("white")
      text(a[d*i]-3,a[d*i+1]-11,"!")
    for i in range (0,4*n+1):
      for j in range (i+1,4*n+1):
        n1=(a[d*i]-a[d*j])
        n2=(a[d*i+1]-a[d*j+1])
        nn=n1*n1+n2*n2
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        v2x=a[d*j+2]
        v2y=a[d*j+3]
        if nn<4*radius*radius:
          if nn !=0:
            if a[d*i+7]==0 and a[d*i+7]==0:
              a[d*i+2]=((n2*n2-e*n1*n1)*v1x-(1+e)*n1*n2*v1y)/nn
              a[d*i+3]=(-(1+e)*n1*n2*v1x+(n1*n1-e*n2*n2)*v1y)/nn
              a[d*j+2]=((n2*n2-n1*n1)*v2x-2*n1*n2*v2y)/nn
              a[d*j+3]=(-2*n1*n2*v2x+(n1*n1-n2*n2)*v2y)/nn
              a[d*i]=a[d*i]+(0+radius-sqrt(nn)/2)*n1/sqrt(nn)
              a[d*i+1]=a[d*i+1]+(0+radius-sqrt(nn)/2)*n2/sqrt(nn)
              a[d*j]=a[d*j]-(0+radius-sqrt(nn)/2)*n1/sqrt(nn)
              a[d*j+1]=a[d*j+1]-(0+radius-sqrt(nn)/2)*n2/sqrt(nn)
              a[d*i+7]=0
              a[d*j+7]=0
      if a[d*i+7]!=0:
        a[d*i+7]=a[d*i+7]-1
    #print(i,domain*domain,(a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2))
              
      if (a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2)>domain*domain and a[d*i]<screen_width:
        #print(i)
        n1=-(a[d*i]-screen_width/2)
        n2=-(a[d*i+1]-screen_height/2)
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        nn=n1*n1+n2*n2
        a[d*i+2]=((n2*n2-e2*n1*n1)*v1x-(1+e2)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e2)*n1*n2*v1x+(n1*n1-e2*n2*n2)*v1y)/nn
        a[d*i]=a[d*i]+(0-domain+sqrt(nn))*n1/sqrt(nn)
        a[d*i+1]=a[d*i+1]+(0-domain+sqrt(nn))*n2/sqrt(nn)
      hcx=a[d*i]-screen_width/2+domain/2
      hcy=a[d*i+1]-screen_height/2
      if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo1==1:
        n1=hcx
        n2=hcy
        nn=n1*n1+n2*n2
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        a[d*i+2]=((n2*n2-e3*n1*n1)*v1x-(1+e3)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e3)*n1*n2*v1x+(n1*n1-e3*n2*n2)*v1y)/nn
        a[d*i]=a[d*i]+(0+radius+hipporadius-sqrt(nn))*n1/sqrt(nn)
        a[d*i+1]=a[d*i+1]+(0+radius+hipporadius-sqrt(nn))*n2/sqrt(nn)
      if (a[d*i]-screen_width/2+domain/2)*(a[d*i]-screen_width/2+domain/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2)<hipporadius*hipporadius and hippo1==1:
        a[d*i]=screen_width+100
        a[d*i+1]=screen_height+100
        a[d*i+2]=0
        a[d*i+3]=0
        team=int(i/n)
        if team==0:
          sr=sr-1
          bluecount=bluecount-1
        elif team==1:
          sr=sr-1
          bluecount=bluecount-1
        elif team==2:
          sr=sr+3
          redcount=redcount-1
        elif team==3:
          sr=sr-1
          redcount=redcount-1
        elif team==4:
          sr=-100
          gameend=1
          print("Blue team wins!")
      hcx=a[d*i]-screen_width/2
      hcy=a[d*i+1]-screen_height/2+domain/2
      if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo2==1:
        n1=hcx
        n2=hcy
        nn=n1*n1+n2*n2
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        a[d*i+2]=((n2*n2-e3*n1*n1)*v1x-(1+e3)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e3)*n1*n2*v1x+(n1*n1-e3*n2*n2)*v1y)/nn
        a[d*i]=a[d*i]+(0+radius+hipporadius-sqrt(nn))*n1/sqrt(nn)
        a[d*i+1]=a[d*i+1]+(0+radius+hipporadius-sqrt(nn))*n2/sqrt(nn)
      if (a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2+domain/2)*(a[d*i+1]-screen_height/2+domain/2)<hipporadius*hipporadius and hippo2==1:
        a[d*i]=1000000
        a[d*i+1]=1000000
        a[d*i+2]=0
        a[d*i+3]=0
        team=int(i/n)
        if team==0:
          sr=sr
          bluecount=bluecount-1
        elif team==1:
          sb=sb+1
          bluecount=bluecount-1
        elif team==2:
          sr=sr
          redcount=redcount-1
        elif team==3:
          sr=sr
          redcount=redcount-1
        elif team==4:
          sb=-100
          gameend=1
          print("Red team wins!")
          
      hcx=a[d*i]-screen_width/2
      hcy=a[d*i+1]-screen_height/2-domain/2
      if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo3==1:
        n1=hcx
        n2=hcy
        nn=n1*n1+n2*n2
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        a[d*i+2]=((n2*n2-e3*n1*n1)*v1x-(1+e3)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e3)*n1*n2*v1x+(n1*n1-e3*n2*n2)*v1y)/nn
        a[d*i]=a[d*i]+(0+radius+hipporadius-sqrt(nn))*n1/sqrt(nn)
        a[d*i+1]=a[d*i+1]+(0+radius+hipporadius-sqrt(nn))*n2/sqrt(nn)
      if (a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2-domain/2)*(a[d*i+1]-screen_height/2-domain/2)<hipporadius*hipporadius and hippo3==1:
        a[d*i]=1000000
        a[d*i+1]=1000000
        a[d*i+2]=0
        a[d*i+3]=0
        team=int(i/n)
        if team==0:
          sr=sr
          bluecount=bluecount-1
        elif team==1:
          sr=sr
          bluecount=bluecount-1
        elif team==2:
          sr=sr
          redcount=redcount-1
        elif team==3:
          sr=sr+1
          redcount=redcount-1
        elif team==4:
          sr=-100
          gameend=1
          print("Blue team wins!")
      hcx=a[d*i]-screen_width/2-domain/2
      hcy=a[d*i+1]-screen_height/2
      if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo4==1:
        n1=hcx
        n2=hcy
        nn=n1*n1+n2*n2
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        a[d*i+2]=((n2*n2-e3*n1*n1)*v1x-(1+e3)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e3)*n1*n2*v1x+(n1*n1-e3*n2*n2)*v1y)/nn
        a[d*i]=a[d*i]+(0+radius+hipporadius-sqrt(nn))*n1/sqrt(nn)
        a[d*i+1]=a[d*i+1]+(0+radius+hipporadius-sqrt(nn))*n2/sqrt(nn)
        
      if (a[d*i]-screen_width/2-domain/2)*(a[d*i]-screen_width/2-domain/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2)<hipporadius*hipporadius and hippo4==1:
        a[d*i]=1000000
        a[d*i+1]=1000000
        a[d*i+2]=0
        a[d*i+3]=0
        team=int(i/n)
        if team==0:
          sb=sb+3
          bluecount=bluecount-1
        elif team==1:
          sb=sb-1
          bluecount=bluecount-1
        elif team==2:
          sb=sb-1
          redcount=redcount-1
        elif team==3:
          sb=sb-1
          redcount=redcount-1
        elif team==4:
          sb=-100
          gameend=1
          print("Red team wins!")
    
    if hippo1==1:
      color("rgba(255,0,0,1)")
      spot(screen_width/2-domain/2,screen_height/2,hipporadius)
      color("white")
      spot(screen_width/2-domain/2+hipporadius/3,screen_height/2+hipporadius/3,hipporadius/5)
      spot(screen_width/2-domain/2+hipporadius/3,screen_height/2-hipporadius/3,hipporadius/5)
      color("black")
      spot(screen_width/2-domain/2+1.2*hipporadius/3,screen_height/2+hipporadius/3,hipporadius/10)
      spot(screen_width/2-domain/2+1.2*hipporadius/3,screen_height/2-hipporadius/3,hipporadius/10)
    if hippo2==1:
      color("rgba(255,0,255,1)")
      spot(screen_width/2,screen_height/2-domain/2,hipporadius)
      color("white")
      spot(screen_width/2+hipporadius/3,screen_height/2-domain/2+hipporadius/3,hipporadius/5)
      spot(screen_width/2-hipporadius/3,screen_height/2-domain/2+hipporadius/3,hipporadius/5)
      color("black")
      spot(screen_width/2+hipporadius/3,screen_height/2-domain/2+1.2*hipporadius/3,hipporadius/10)
      spot(screen_width/2-hipporadius/3,screen_height/2-domain/2+1.2*hipporadius/3,hipporadius/10)
    if hippo3==1:
      color("rgba(255,100,0,1)")
      spot(screen_width/2,screen_height/2+domain/2,hipporadius)
      color("white")
      spot(screen_width/2-hipporadius/3,screen_height/2+domain/2-hipporadius/3,hipporadius/5)
      spot(screen_width/2+hipporadius/3,screen_height/2+domain/2-hipporadius/3,hipporadius/5)
      color("black")
      spot(screen_width/2-hipporadius/3,screen_height/2+domain/2-1.2*hipporadius/3,hipporadius/10)
      spot(screen_width/2+hipporadius/3,screen_height/2+domain/2-1.2*hipporadius/3,hipporadius/10)
    if hippo4==1:
      color("rgba(0,0,255,1)")
      spot(screen_width/2+domain/2,screen_height/2,hipporadius)
      color("white")
      spot(screen_width/2+domain/2-hipporadius/3,screen_height/2+hipporadius/3,hipporadius/5)
      spot(screen_width/2+domain/2-hipporadius/3,screen_height/2-hipporadius/3,hipporadius/5)
      color("black")
      spot(screen_width/2+domain/2-1.2*hipporadius/3,screen_height/2+hipporadius/3,hipporadius/10)
      spot(screen_width/2+domain/2-1.2*hipporadius/3,screen_height/2-hipporadius/3,hipporadius/10)
 
    color("red")  
    text(10,screen_height-24,sr)
    color("blue")
    text(screen_width-100,10,sb)
    
    if redcount==0 or bluecount==0:
      gameend=1
      if sr>sb:
        print("Red team wins!")
      elif sb>sr:
        print("Blue team wins!")
      else:
        print("Draw!")
Beispiel #8
0





# Car stats
acc = 0.3
max_speed = 10
turn_speed = 0.07
friction = 0.05

# Bounce stats
side_bounce = -2

sleep(100)

player_won = 0

lap1 = 1
lap2 = 1
time = 0

car_x = 200
car_y = 160
car_v = 0
car_a = 0
direction = 0
spin = 0

car_x2 = 200
def handle_frame():
  global balls, sr, sb, gameend, e3, redcount, bluecount, hippo1, hippo2, hippo3, hippo4
  if gameend==0:
    
    sleep(20)
    color("white")
    box(0,0,screen_width,screen_height)
    color("black")
    circle(screen_width/2,screen_height/2,domain+radius)
    color("rgba(255,0,0,1)")
    circle(screen_width/2-domain/2,screen_height/2,hipporadius)
    color("rgba(255,0,255,1)")
    circle(screen_width/2,screen_height/2-domain/2,hipporadius)
    color("rgba(255,100,0,1)")
    circle(screen_width/2,screen_height/2+domain/2,hipporadius)
    color("rgba(0,0,255,1)")
    circle(screen_width/2+domain/2,screen_height/2,hipporadius)
    
    for ball in balls:
      #a[d*i+8]=-a[d*i]/1000
      #a[d*i+9]=-a[d*i+1]/1000
      ball.position = ball.position + ball.velocity
    
      
      # TODO: Acceleration
      #a1=a[d*i]-screen_width/2
      #a2=a[d*i+1]-screen_height/2
      #aa=sqrt(a1*a1+a2*a2)
      #a[d*i+8]=-mu*a[d*i+2]-g*a1/aa
      #a[d*i+9]=-mu*a[d*i+3]-g*a2/aa
      #if a[d*i]<screen_width:
      #  a[d*i+2]=a[d*i+2]*1+a[d*i+8]
      #  a[d*i+3]=a[d*i+3]*1+a[d*i+9]
     
    
    
    for i in range (0,len(balls)):
      for j in range (i+1,len(balls)):
        
        normal = balls[i].position - balls[j].position
        
        nn=normal.mod()
        
        if nn<2*radius:
          if nn !=0:
            
            # rotate so colission along x
            tangent=Vector(-normal.y,normal.x)
            
            v3 = Vector(normal * balls[i].velocity,
                        tangent * balls[i].velocity)
            v4 = Vector(normal * balls[j].velocity,
                        tangent * balls[j].velocity)
            
            
            
            v5x=0.5*((1-e)*v3.x+(1+e)*v4.x)
            v6x=0.5*((1-e)*v4.x+(1+e)*v3.x)
            
            balls[i].velocity = \
                  Vector((normal.x*v5x-normal.y*v3.y)/nn**2,
                         (normal.y*v5x+normal.x*v3.y)/nn**2)
            balls[j].velocity = \
                  Vector((normal.x*v6x-normal.y*v4.y)/nn**2,
                         (normal.y*v6x+normal.x*v4.y)/nn**2)
           
            
             
            
            balls[i].position += normal.scale((2*radius-nn) / (2 * nn))
            balls[j].position += normal.scale(-(2*radius-nn) / (2 * nn))
            
            
      
              
      #if (a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2)>domain*domain and a[d*i]<screen_width:
        #print(i)
      #  n1=-(a[d*i]-screen_width/2)
      #  n2=-(a[d*i+1]-screen_height/2)
      #  v1x=a[d*i+2]
      #  v1y=a[d*i+3]
      #  nn=n1*n1+n2*n2
      #  a[d*i+2]=((n2*n2-e2*n1*n1)*v1x-(1+e2)*n1*n2*v1y)/nn
      #  a[d*i+3]=(-(1+e2)*n1*n2*v1x+(n1*n1-e2*n2*n2)*v1y)/nn
      #  a[d*i]=a[d*i]+(1-domain+sqrt(nn))*n1/sqrt(nn)
      #  a[d*i+1]=a[d*i+1]+(1-domain+sqrt(nn))*n2/sqrt(nn)
      
      
      
      #hcx=a[d*i]-screen_width/2+domain/2
      #hcy=a[d*i+1]-screen_height/2
      #if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo1>1:
      #  print(i)
      #  a[d*i+2]=nom*a[d*i+2]
      #  a[d*i+3]=nom*a[d*i+3]
        
      #if hippo1>1:
      #  hippo1=hippo1-1
      #if hippo2==2:
      #  hippo2=1
      #if hippo3==2:
      #  hippo3=1
      #if hippo4==2:
      #  hippo4=1
      #if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo1>0:
      #  n1=hcx
      #  n2=hcy
      #  nn=n1*n1+n2*n2
      #  v1x=a[d*i+2]
      #  v1y=a[d*i+3]
      #  a[d*i+2]=((n2*n2-e3*n1*n1)*v1x-(1+e3)*n1*n2*v1y)/nn
      #  a[d*i+3]=(-(1+e3)*n1*n2*v1x+(n1*n1-e3*n2*n2)*v1y)/nn
      #  a[d*i]=a[d*i]+(0+radius+hipporadius-sqrt(nn))*n1/sqrt(nn)
      #  a[d*i+1]=a[d*i+1]+(0+radius+hipporadius-sqrt(nn))*n2/sqrt(nn)
      #if (a[d*i]-screen_width/2+domain/2)*(a[d*i]-screen_width/2+domain/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2)<hipporadius*hipporadius and hippo1==1:
      #  a[d*i]=screen_width+100
      #  a[d*i+1]=screen_height+100
      #  a[d*i+2]=0
      #  a[d*i+3]=0
      #  team=int(i/n)
      #  if team==0:
      #    sr=sr-1
      #    bluecount=bluecount-1
      #  elif team==1:
      #    sr=sr-1
      #    bluecount=bluecount-1
      #  elif team==2:
      #    sr=sr+3
      #    redcount=redcount-1
      #  elif team==3:
      #    sr=sr-1
      #    redcount=redcount-1
      #  elif team==4:
      #    sr=-100
      #    gameend=1
      #    print("Blue team wins!")
      #hcx=a[d*i]-screen_width/2
      #hcy=a[d*i+1]-screen_height/2+domain/2
      #if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo2==1:
      #  n1=hcx
      #  n2=hcy
      #  nn=n1*n1+n2*n2
      #  v1x=a[d*i+2]
      #  v1y=a[d*i+3]
      #  a[d*i+2]=((n2*n2-e3*n1*n1)*v1x-(1+e3)*n1*n2*v1y)/nn
      #  a[d*i+3]=(-(1+e3)*n1*n2*v1x+(n1*n1-e3*n2*n2)*v1y)/nn
      #  a[d*i]=a[d*i]+(0+radius+hipporadius-sqrt(nn))*n1/sqrt(nn)
      #  a[d*i+1]=a[d*i+1]+(0+radius+hipporadius-sqrt(nn))*n2/sqrt(nn)
      #if (a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2+domain/2)*(a[d*i+1]-screen_height/2+domain/2)<hipporadius*hipporadius and hippo2==1:
      #  a[d*i]=1000000
      #  a[d*i+1]=1000000
      #  a[d*i+2]=0
      #  a[d*i+3]=0
      #  team=int(i/n)
      #  if team==0:
      #    sr=sr
      #    bluecount=bluecount-1
      #  elif team==1:
      #    sb=sb+1
      #    bluecount=bluecount-1
      #  elif team==2:
      #    sr=sr
      #    redcount=redcount-1
      #  elif team==3:
      #    sr=sr
      #    redcount=redcount-1
      #  elif team==4:
      #    sb=-100
      #    gameend=1
      #    print("Red team wins!")
      #    
      #hcx=a[d*i]-screen_width/2
      #hcy=a[d*i+1]-screen_height/2-domain/2
      #if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo3==1:
      #  n1=hcx
      #  n2=hcy
      #  nn=n1*n1+n2*n2
      #  v1x=a[d*i+2]
      #  v1y=a[d*i+3]
      #  a[d*i+2]=((n2*n2-e3*n1*n1)*v1x-(1+e3)*n1*n2*v1y)/nn
      #  a[d*i+3]=(-(1+e3)*n1*n2*v1x+(n1*n1-e3*n2*n2)*v1y)/nn
      #  a[d*i]=a[d*i]+(0+radius+hipporadius-sqrt(nn))*n1/sqrt(nn)
      #  a[d*i+1]=a[d*i+1]+(0+radius+hipporadius-sqrt(nn))*n2/sqrt(nn)
      #if (a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2-domain/2)*(a[d*i+1]-screen_height/2-domain/2)<hipporadius*hipporadius and hippo3==1:
      #  a[d*i]=1000000
      #  a[d*i+1]=1000000
      #  a[d*i+2]=0
      #  a[d*i+3]=0
      #  team=int(i/n)
      #  if team==0:
      #    sr=sr
      #    bluecount=bluecount-1
      #  elif team==1:
      #    sr=sr
      #    bluecount=bluecount-1
      #  elif team==2:
      #    sr=sr
      #    redcount=redcount-1
      #  elif team==3:
      #    sr=sr+1
      #    redcount=redcount-1
      #  elif team==4:
      #    sr=-100
      #    gameend=1
      #    print("Blue team wins!")
      #hcx=a[d*i]-screen_width/2-domain/2
      #hcy=a[d*i+1]-screen_height/2
      #if hcx*hcx+hcy*hcy>hipporadius*hipporadius and hcx*hcx+hcy*hcy<(hipporadius+radius)*(hipporadius+radius) and hippo4==1:
      #  n1=hcx
      #  n2=hcy
      #  nn=n1*n1+n2*n2
      #  v1x=a[d*i+2]
      #  v1y=a[d*i+3]
      #  a[d*i+2]=((n2*n2-e3*n1*n1)*v1x-(1+e3)*n1*n2*v1y)/nn
      #  a[d*i+3]=(-(1+e3)*n1*n2*v1x+(n1*n1-e3*n2*n2)*v1y)/nn
      #  a[d*i]=a[d*i]+(0+radius+hipporadius-sqrt(nn))*n1/sqrt(nn)
      #  a[d*i+1]=a[d*i+1]+(0+radius+hipporadius-sqrt(nn))*n2/sqrt(nn)
      #  
      #if (a[d*i]-screen_width/2-domain/2)*(a[d*i]-screen_width/2-domain/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2)<hipporadius*hipporadius and hippo4==1:
      #  a[d*i]=1000000
      #  a[d*i+1]=1000000
      #  a[d*i+2]=0
      #  a[d*i+3]=0
      #  team=int(i/n)
      #  if team==0:
      #    sb=sb+3
      #    bluecount=bluecount-1
      #  elif team==1:
      #    sb=sb-1
      #    bluecount=bluecount-1
      #  elif team==2:
      #    sb=sb-1
      #    redcount=redcount-1
      #  elif team==3:
      #    sb=sb-1
      #    redcount=redcount-1
      #  elif team==4:
      #    sb=-100
      #    gameend=1
      #    print("Red team wins!")
    for i, ball in enumerate(balls):
      color(ctorgba(ball.colour))
      spot(ball.position.x, ball.position.y, radius)
    if i==4*n:
      color("white")
      text(ball.position.x-3, ball.position.y-12,"!")
    if hippo1==1:
      color("rgba(255,0,0,1)")
      spot(screen_width/2-domain/2,screen_height/2,hipporadius)
      color("white")
      spot(screen_width/2-domain/2+hipporadius/3,screen_height/2+hipporadius/3,hipporadius/5)
      spot(screen_width/2-domain/2+hipporadius/3,screen_height/2-hipporadius/3,hipporadius/5)
      color("black")
      spot(screen_width/2-domain/2+1.2*hipporadius/3,screen_height/2+hipporadius/3,hipporadius/10)
      spot(screen_width/2-domain/2+1.2*hipporadius/3,screen_height/2-hipporadius/3,hipporadius/10)
    if hippo2==1:
      color("rgba(255,0,255,1)")
      spot(screen_width/2,screen_height/2-domain/2,hipporadius)
      color("white")
      spot(screen_width/2+hipporadius/3,screen_height/2-domain/2+hipporadius/3,hipporadius/5)
      spot(screen_width/2-hipporadius/3,screen_height/2-domain/2+hipporadius/3,hipporadius/5)
      color("black")
      spot(screen_width/2+hipporadius/3,screen_height/2-domain/2+1.2*hipporadius/3,hipporadius/10)
      spot(screen_width/2-hipporadius/3,screen_height/2-domain/2+1.2*hipporadius/3,hipporadius/10)
    if hippo3==1:
      color("rgba(255,100,0,1)")
      spot(screen_width/2,screen_height/2+domain/2,hipporadius)
      color("white")
      spot(screen_width/2-hipporadius/3,screen_height/2+domain/2-hipporadius/3,hipporadius/5)
      spot(screen_width/2+hipporadius/3,screen_height/2+domain/2-hipporadius/3,hipporadius/5)
      color("black")
      spot(screen_width/2-hipporadius/3,screen_height/2+domain/2-1.2*hipporadius/3,hipporadius/10)
      spot(screen_width/2+hipporadius/3,screen_height/2+domain/2-1.2*hipporadius/3,hipporadius/10)
    if hippo4==1:
      color("rgba(0,0,255,1)")
      spot(screen_width/2+domain/2,screen_height/2,hipporadius)
      color("white")
      spot(screen_width/2+domain/2-hipporadius/3,screen_height/2+hipporadius/3,hipporadius/5)
      spot(screen_width/2+domain/2-hipporadius/3,screen_height/2-hipporadius/3,hipporadius/5)
      color("black")
      spot(screen_width/2+domain/2-1.2*hipporadius/3,screen_height/2+hipporadius/3,hipporadius/10)
      spot(screen_width/2+domain/2-1.2*hipporadius/3,screen_height/2-hipporadius/3,hipporadius/10)
 
    color("red")  
    text(10,10,sr)
    color("blue")
    text(screen_width-100,10,sb)
    
    if redcount==0 or bluecount==0:
      gameend=1
      if sr>sb:
        print("Red team wins!")
      elif sb>sr:
        print("Blue team wins!")
      else:
        print("Draw!")
Beispiel #10
0
def handle_frame():
    
  sleep(20)
  color("white")
  box(0,0,screen_width,screen_height)
  color("black")
  circle(screen_width/2,screen_height/2,domain+radius)
  for i in range (0,n):
    #a[d*i+8]=-a[d*i]/1000
    #a[d*i+9]=-a[d*i+1]/1000
    a[d*i]=a[d*i]+a[d*i+2]
    a[d*i+1]=a[d*i+1]+a[d*i+3]
    
    a1=a[d*i]-screen_width/2
    a2=a[d*i+1]-screen_height/2
    aa=sqrt(a1*a1+a2*a2)
    a[d*i+8]=-mu*a[d*i+2]-g*a1/aa
    a[d*i+9]=-mu*a[d*i+3]-g*a2/aa
    
    #a[d*i+8]=-mu*a[d*i+2]
    #a[d*i+9]=-mu*a[d*i+3]+g
   
    
    a[d*i+2]=a[d*i+2]*1+a[d*i+8]
    a[d*i+3]=a[d*i+3]*1+a[d*i+9]
   
 
    for j in range (i+1,n):
      n1=(a[d*i]-a[d*j])
      n2=(a[d*i+1]-a[d*j+1])
      nn=n1*n1+n2*n2
      if nn<4*radius*radius:
        if nn !=0:
          if a[d*i+7]==0 and a[d*i+7]==0:
            v1x=a[d*i+2]
            v1y=a[d*i+3]
            v2x=a[d*j+2]
            v2y=a[d*j+3]
      
            v3x=n1*v1x+n2*v1y
            v3y=-n2*v1x+n1*v1y
            v4x=n1*v2x+n2*v2y
            v4y=-n2*v2x+n1*v2y
            
            v5x=0.5*((1-e)*v3x+(1+e)*v4x)
            v6x=0.5*((1-e)*v4x+(1+e)*v3x)
            
            v7x=(n1*v5x-n2*v3y)/nn
            v7y=(n2*v5x+n1*v3y)/nn
            v8x=(n1*v6x-n2*v4y)/nn
            v8y=(n2*v6x+n1*v4y)/nn
            a[d*i+2]=v7x
            a[d*i+3]=v7y
            a[d*j+2]=v8x
            a[d*j+3]=v8y
              
            
            a[d*i]=a[d*i]+(0+radius-sqrt(nn)/2)*n1/sqrt(nn)
            a[d*i+1]=a[d*i+1]+(0+radius-sqrt(nn)/2)*n2/sqrt(nn)
            a[d*j]=a[d*j]-(0+radius-sqrt(nn)/2)*n1/sqrt(nn)
            a[d*j+1]=a[d*j+1]-(0+radius-sqrt(nn)/2)*n2/sqrt(nn)
            a[d*i+7]=0
            a[d*j+7]=0
    if a[d*i+7]!=0:
      a[d*i+7]=a[d*i+7]-1
  #print(i,domain*domain,(a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2))
            
    if (a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2)>domain*domain and a[d*i]<screen_width:
      #print(i)
      n1=-(a[d*i]-screen_width/2)
      n2=-(a[d*i+1]-screen_height/2)
      v1x=a[d*i+2]
      v1y=a[d*i+3]
      nn=n1*n1+n2*n2
      a[d*i+2]=((n2*n2-e2*n1*n1)*v1x-(1+e2)*n1*n2*v1y)/nn
      a[d*i+3]=(-(1+e2)*n1*n2*v1x+(n1*n1-e2*n2*n2)*v1y)/nn
      a[d*i]=a[d*i]+(1-domain+sqrt(nn))*n1/sqrt(nn)
      a[d*i+1]=a[d*i+1]+(1-domain+sqrt(nn))*n2/sqrt(nn)
    
    c=[a[d*i+4],a[d*i+5],a[d*i+6],1]
    colstring = ctorgba(c)
    color(colstring)
    spot(a[d*i],a[d*i+1],radius)
Beispiel #11
0
def handle_frame():
  global mx,my 
  sleep(20)
  color("white")
  box(0,0,screen_width,screen_height)
  color("black")
  circle(cx,cy,2*radius)
  
  for i in range (0,n):
    #a[d*i+8]=-a[d*i]/1000
    #a[d*i+9]=-a[d*i+1]/1000
    a[d*i]=a[d*i]+a[d*i+2]
    a[d*i+1]=a[d*i+1]+a[d*i+3]
    
    a[d*i]=a[d*i]%screen_width
    a[d*i+1]=a[d*i+1]%screen_height
    
    a1=a[d*i]-screen_width/2
    a2=a[d*i+1]-screen_height/2
    aa=sqrt(a1*a1+a2*a2)
    #a[d*i+8]=-mu*a[d*i+2]-g*a1/aa
    #a[d*i+9]=-mu*a[d*i+3]-g*a2/aa
    
    #a[d*i+8]=-mu*a[d*i+2]
    #a[d*i+9]=-mu*a[d*i+3]+g
   
    
    a[d*i+2]=a[d*i+2]*1+a[d*i+8]
    a[d*i+3]=a[d*i+3]*1+a[d*i+9]
   
 
    for j in range (i+1,n):
      n1=(a[d*i]-a[d*j])
      n2=(a[d*i+1]-a[d*j+1])
      nn=n1*n1+n2*n2
      if nn<4*radius*radius:
        if nn !=0:
          if a[d*i+7]==0 and a[d*i+7]==0:
            v1x=a[d*i+2]
            v1y=a[d*i+3]
            v2x=a[d*j+2]
            v2y=a[d*j+3]
      
            v3x=n1*v1x+n2*v1y
            v3y=-n2*v1x+n1*v1y
            v4x=n1*v2x+n2*v2y
            v4y=-n2*v2x+n1*v2y
            
            v5x=0.5*((1-e)*v3x+(1+e)*v4x)
            v6x=0.5*((1-e)*v4x+(1+e)*v3x)
            
            v7x=(n1*v5x-n2*v3y)/nn
            v7y=(n2*v5x+n1*v3y)/nn
            v8x=(n1*v6x-n2*v4y)/nn
            v8y=(n2*v6x+n1*v4y)/nn
            a[d*i+2]=v7x
            a[d*i+3]=v7y
            a[d*j+2]=v8x
            a[d*j+3]=v8y
              
            
            a[d*i]=a[d*i]+(0+radius-sqrt(nn)/2)*n1/sqrt(nn)
            a[d*i+1]=a[d*i+1]+(0+radius-sqrt(nn)/2)*n2/sqrt(nn)
            a[d*j]=a[d*j]-(0+radius-sqrt(nn)/2)*n1/sqrt(nn)
            a[d*j+1]=a[d*j+1]-(0+radius-sqrt(nn)/2)*n2/sqrt(nn)
            a[d*i+7]=0
            a[d*j+7]=0
            
            #c1=int((a[d*i+4]+a[d*j+4])/2)
            #c2=int((a[d*i+5]+a[d*j+5])/2)
            #c3=int((a[d*i+6]+a[d*j+6])/2)
            #a[d*i+4]=c1
            #a[d*i+5]=c2
            #a[d*i+6]=c3
            #a[d*j+4]=c1
            #a[d*j+5]=c2
            #a[d*j+6]=c3
    if a[d*i+7]!=0:
      a[d*i+7]=a[d*i+7]-1
  #print(i,domain*domain,(a[d*i]-screen_width/2)*(a[d*i]-screen_width/2)+(a[d*i+1]-screen_height/2)*(a[d*i+1]-screen_height/2))
    if 0==1:        
      if a[d*i]<radius:
        #print(i)
        n1=1
        n2=0
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        nn=n1*n1+n2*n2
        a[d*i+2]=((n2*n2-e2*n1*n1)*v1x-(1+e2)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e2)*n1*n2*v1x+(n1*n1-e2*n2*n2)*v1y)/nn
        a[d*i]=radius
        a[d*i+1]=a[d*i+1]
        
      if a[d*i]>screen_width-radius:
        #print(i)
        n1=-1
        n2=0
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        nn=n1*n1+n2*n2
        a[d*i+2]=((n2*n2-e2*n1*n1)*v1x-(1+e2)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e2)*n1*n2*v1x+(n1*n1-e2*n2*n2)*v1y)/nn
        a[d*i]=screen_width-radius
        a[d*i+1]=a[d*i+1]
      
      if a[d*i+1]<radius:
        #print(i)r
        n1=0
        n2=1
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        nn=n1*n1+n2*n2
        a[d*i+2]=((n2*n2-e2*n1*n1)*v1x-(1+e2)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e2)*n1*n2*v1x+(n1*n1-e2*n2*n2)*v1y)/nn
        a[d*i]=a[d*i]
        a[d*i+1]=radius
        
      if a[d*i+1]>screen_height-radius:
        #print(i)r
        n1=0
        n2=-1
        v1x=a[d*i+2]
        v1y=a[d*i+3]
        nn=n1*n1+n2*n2
        a[d*i+2]=((n2*n2-e2*n1*n1)*v1x-(1+e2)*n1*n2*v1y)/nn
        a[d*i+3]=(-(1+e2)*n1*n2*v1x+(n1*n1-e2*n2*n2)*v1y)/nn
        a[d*i]=a[d*i]
        a[d*i+1]=screen_height-radius
      
    if (a[d*i]-cx)**2+(a[d*i+1]-cy)**2<4*radius**2 and i!=n-1:
      print("Ding!")
            
    v=min(100*int(sqrt(a[d*i+2]**2+a[d*i+3]**2)),255)
    #c=[v,256-v,0,1]
    c=[a[d*i+4],a[d*i+5],a[d*i+6],1]
    colstring = ctorgba(c)
    color(colstring)
    spot(a[d*i],a[d*i+1],radius)
  color("rbga(0,0,0,0)")
  line(a[d*(n-1)],a[d*(n-1)+1],mx,my)