示例#1
0
def handle_mousemove(x,y,button):
  if button == "left":
    color("cyan")
    circle(x,y,10)
  if button == "right":
    color("random")
    circle(x,y,5)
示例#2
0
def handle_mousemove(x,y):
  global lastx, lasty, hue
  
  line(lastx or x, lasty or y, x, y)
  circle(lastx or x, lasty or y, x)
  
  #color("hsl(%d,100%%,50%%)" % hue)
  color("rgba(400,9,0,0.7)" % hue)
  
  box(lastx or x, lasty or y, x, y)
  
  #spot(lastx or x, lasty or y, x)
  #color("hsl(%d,100%%,50%%)" % hue)
  
  hue += 1
 
  
  lastx = x
  lasty = y
def handle_frame():
  global mx,my, gamestate, sr, sb, shiftx, shifty, dshiftx, dshifty, gameover, player, aimrad, ffwd, counter
  
  counter=(counter+1)%20
  
  if ffwd==0 or counter==0:  
    color("black")
    box(0,0,screen_width,screen_height)
  
  vsum=0
  shiftx=(shiftx+dshiftx)%screen_width
  shifty=(shifty+dshifty)%screen_height
  mx=mmx-shiftx
  my=mmy-shifty
  
  if ffwd==0 or counter==0:
    color("white")
    circle(cx+shiftx,cy+shifty,2*radius)
    circle(cx+screen_width+shiftx,cy+shifty,2*radius)
    circle(cx+shiftx-screen_width,cy+shifty,2*radius)
    circle(cx+shiftx,cy+shifty+screen_height,2*radius)
    circle(cx+shiftx,cy+shifty-screen_height,2*radius)
    circle(cx+shiftx+screen_width,cy+shifty+screen_height,2*radius)
    circle(cx+shiftx+screen_width,cy+shifty-screen_height,2*radius)
    circle(cx+shiftx-screen_width,cy+shifty+screen_height,2*radius)
    circle(cx+shiftx-screen_width,cy+shifty-screen_height,2*radius)
    color("rgba(255,0,0,1)")
    text(cx+shiftx-6,cy+shifty-24,sr)
    text(cx+shiftx+screen_width-6,cy+shifty-24,sr)
    text(cx+shiftx-screen_width-6,cy+shifty-24,sr)
    text(cx+shiftx-6,cy+shifty+screen_height-24,sr)
    text(cx+shiftx-6,cy+shifty-screen_height-24,sr)
    text(cx+shiftx+screen_width-6,cy+shifty+screen_height-24,sr)
    text(cx+shiftx+screen_width-6,cy+shifty-screen_height-24,sr)
    text(cx+shiftx-screen_width-6,cy+shifty+screen_height-24,sr)
    text(cx+shiftx-screen_width-6,cy+shifty-screen_height-24,sr)
    
    color("rgba(0,0,255,1)") 
    text(cx+shiftx-6,cy+shifty,sb)
    text(cx+shiftx+screen_width-6,cy+shifty,sb)
    text(cx+shiftx-screen_width-6,cy+shifty,sb)
    text(cx+shiftx-6,cy+shifty+screen_height,sb)
    text(cx+shiftx-6,cy+shifty-screen_height,sb)
    text(cx+shiftx+screen_width-6,cy+shifty+screen_height,sb)
    text(cx+shiftx+screen_width-6,cy+shifty-screen_height,sb)
    text(cx+shiftx-screen_width-6,cy+shifty+screen_height,sb)
    text(cx+shiftx-screen_width-6,cy+shifty-screen_height,sb)
  
    a1=mx-a[d*(n-1)]
    a2=my-a[d*(n-1)+1]
    if a1>screen_width/2:
      a1=-screen_width+a1
    elif a1<-screen_width/2:
      a1=screen_width+a1
    if a2>screen_height/2:
      a2=-screen_height+a2
    elif a2<-screen_height/2:
      a2=screen_height+a2
    aa=a1*a1+a2*a2
    a1=a1*aimrad/sqrt(aa)
    a2=a2*aimrad/sqrt(aa)
    if gamestate==0 and aa<aimrad**2:
      if player==0:
        color("rgba(255,0,0,1)")
      elif player==1:
        color("rgba(0,0,255,1)")
      line(a[d*(n-1)]+shiftx,a[d*(n-1)+1]+shifty,a[d*(n-1)]+shiftx+a1,a[d*(n-1)+1]+shifty+a2)
      line(a[d*(n-1)]+shiftx+screen_width,a[d*(n-1)+1]+shifty,a[d*(n-1)]+shiftx+screen_width+a1,a[d*(n-1)+1]+shifty+a2)
      line(a[d*(n-1)]+shiftx-screen_width,a[d*(n-1)+1]+shifty,a[d*(n-1)]+shiftx-screen_width+a1,a[d*(n-1)+1]+shifty+a2)
      line(a[d*(n-1)]+shiftx,a[d*(n-1)+1]+shifty+screen_height,a[d*(n-1)]+shiftx+a1,a[d*(n-1)+1]+shifty+screen_height+a2)
      line(a[d*(n-1)]+shiftx,a[d*(n-1)+1]+shifty-screen_height,a[d*(n-1)]+shiftx+a1,a[d*(n-1)+1]+shifty-screen_height+a2)
      
      line(a[d*(n-1)]+shiftx+screen_width,a[d*(n-1)+1]+shifty+screen_height,a[d*(n-1)]+shiftx+screen_width+a1,a[d*(n-1)+1]+shifty+screen_height+a2)
      line(a[d*(n-1)]+shiftx+screen_width,a[d*(n-1)+1]+shifty-screen_height,a[d*(n-1)]+shiftx+screen_width+a1,a[d*(n-1)+1]+shifty-screen_height+a2)
      line(a[d*(n-1)]+shiftx-screen_width,a[d*(n-1)+1]+shifty+screen_height,a[d*(n-1)]+shiftx-screen_width+a1,a[d*(n-1)+1]+shifty+screen_height+a2)
      line(a[d*(n-1)]+shiftx-screen_width,a[d*(n-1)+1]+shifty-screen_height,a[d*(n-1)]+shiftx-screen_width+a1,a[d*(n-1)+1]+shifty-screen_height+a2)

  for i in range (0,n):
    if a[d*i+7]!=1:
      a[d*i]=a[d*i]+a[d*i+2]
      a[d*i+1]=a[d*i+1]+a[d*i+3]
      vv=sqrt(a[d*i+2]**2+a[d*i+3]**2)
      if vv!=0:
        a[d*i+2]=a[d*i+2]*(1-mu/vv)
        a[d*i+3]=a[d*i+3]*(1-mu/vv)
      
      
      k1=int(a[d*i+1]/screen_height)
      k2=a[d*i+1]%screen_height
      
      a[d*i]=(a[d*i]%screen_width)*(-1)**k1
      a[d*i+1]=k2
      a[d*i+2]=a[d*i+2]*(-1)**k1
      
      vsum=vsum+vv
      
      #Collisions   
      for j in range (i+1,n):
        if a[d*j+7]!=1:
          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:
              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)
          n1=(a[d*i]-a[d*j]-screen_width)
          n2=(a[d*i+1]-a[d*j+1])
          nn=n1*n1+n2*n2
          if nn<4*radius*radius:
            if nn !=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)
          n1=(a[d*i]-a[d*j]+screen_width)
          n2=(a[d*i+1]-a[d*j+1])
          nn=n1*n1+n2*n2
          if nn<4*radius*radius:
            if nn !=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)
        
          n1=(a[d*i]-a[d*j])
          n2=(a[d*i+1]-a[d*j+1]+screen_height)
          nn=n1*n1+n2*n2
          if nn<4*radius*radius:
            if nn !=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)
          n1=(a[d*i]-a[d*j])
          n2=(a[d*i+1]-a[d*j+1]-screen_height)
          nn=n1*n1+n2*n2
          if nn<4*radius*radius:
            if nn !=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)
        
      #Pocket
      if (a[d*i]-cx)**2+(a[d*i+1]-cy)**2<4*radius**2 and i!=n-1:
        a[d*i+7]=1
        if i<(n/2)-1:
          sr=sr+1
        elif i<n-2:
          sb=sb+1
        else:
          if gameover==0:
            gameover=1
            if player==0:
              if sb==n/2-1:
                print("Blue wins.")
              else:
                print("Red wins.")
            if player==1:
              if sr==n/2-1:
                print("Red wins.")
              else:
                print("Blue wins.")
              
      if ffwd==0 or counter==0:
        c=[a[d*i+4],a[d*i+5],a[d*i+6],1]
        colstring = ctorgba(c)
        color(colstring)
        spot(a[d*i]+shiftx,a[d*i+1]+shifty,radius)
        spot(a[d*i]+shiftx+screen_width,a[d*i+1]+shifty,radius)
        spot(a[d*i]+shiftx-screen_width,a[d*i+1]+shifty,radius)
        spot(a[d*i]+shiftx,a[d*i+1]+shifty+screen_height,radius)
        spot(a[d*i]+shiftx,a[d*i+1]+shifty-screen_height,radius)
        spot(a[d*i]+shiftx+screen_width,a[d*i+1]+shifty+screen_height,radius)
        spot(a[d*i]+shiftx+screen_width,a[d*i+1]+shifty-screen_height,radius)
        spot(a[d*i]+shiftx-screen_width,a[d*i+1]+shifty+screen_height,radius)
        spot(a[d*i]+shiftx-screen_width,a[d*i+1]+shifty-screen_height,radius)
  
  
  if vsum>0.1:
    gamestate=1
  else:
    gamestate=0
    for i in range(0,n):
      a[d*i+2]=0
      a[d*i+3]=0
示例#4
0
from tealight.art import (color, line, spot, circle, box, image, text, background)

from math import sin, cos, pi

def circle(x, y, c, size, spines):
  
  color(c)
  
  angle = 0
  
  for i in range(0, spines):
    x0 = x + (size * cos(angle))
    y0 = y + (size * sin(angle))
    
    line(x, y, x0, y0)
    
    angle = angle + (2 * pi / spines)

circle(300, 300, "teal", 100, 50)
circle(600, 400, "violet", 200, 100)
circle(450, 200, "gold", 125, 30)
示例#5
0
def handle_mousemove(x, y, button):
    if button == "left":
        color("red")
        circle(x, y, 10)
示例#6
0
from tealight.art import (color, line, spot, circle, box, image, text, background)

color("blue")
box(150,150,100,100)

color("white")

spot(200,200,25)
circle(200,200,50)
示例#7
0
def handle_mousedown(x,y,b):
  print b
  spot(x,y,10)
  color("hsl(%d,100%%,50%%)" % int(random()*255))
  circle(x,y,10)
示例#8
0
from tealight.art import (color, line, spot, circle, box, image, text,
                          background)

color("blue")

spot(300, 200, 50)
circle(300, 200, 50)
box(250, 300, 100, 100)
示例#9
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!")
示例#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)
示例#11
0
from tealight.art import (color, line, spot, circle, box, image, text, background)

from tealight.art import (screenWidth, screenHeight)

from math import *

print "This is art mode!"


print screenWidth
print screenHeight

spot(0,10,20)

for i in range(10,screenWidth,20):
  for j in range(10,screenHeight,20):
    circle(i,j,10)

def handle_mousemove(x,y):
  if hypot((x+10)%20,(y+10)%20)<=20:
    spot((x//20)*20+10,(y//20)*20+10,10)
示例#12
0
from tealight.art import (color, line, spot, circle, box, image, text, background)
 
background("paper.jpg")  
color("green")

spot(200,500,50) 

color("blue")
circle(300,500,40)

color("red")
box(100,200,500,300)

示例#13
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)
  
示例#14
0
from tealight.art import (color, line, spot, circle, box, image, text, background)

color("blue")

spot(100,200,20)
circle(100,200,10)
box(70,230,50,50)
示例#15
0
def handle_mousemove(x,y,button):
  if button == "left":
    color("red")
    circle(x,y,50)
示例#16
0
from tealight.art import (color, line, spot, circle, box, image, text, background)

from math import sin, cos, pi

def circle(x, y, width, height):
  
  color("red")

circle(300, 300, 100, 50,)
circle(300, 400, 200, 100,)
circle(450, 200, 125, 30,)
示例#17
0
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!")
示例#18
0
                          background)

from tealight.art import (screen_width, screen_height)

print "This is art mode!"

print screen_width
print screen_height

background("paper.jpg")

line(0, 0, screen_width, screen_height)

spot(200, 300, 20)

circle(300, 200, 20)

box(500, 500, 60, 60)

image(200, 200, "bird.png")

line(560, 0, 560, 495)

text(600, 100, "Hello Tealight!")

lastx = None
lasty = None
hue = 0


def handle_mousemove(x, y):
示例#19
0
from github.daviesian.logo.lib import lib_func

print lib_func()

print "This is art mode!"

print screen_width
print screen_height

background("paper.jpg")

line(0,0,screen_width, screen_height)

spot(200,300, 20)

circle(300,200, 20)

box(500, 500, 60, 60)

image(200,200,"bird.png")

line(560,0,560,495)

text(600, 100, "Hello Tealight!")

lastx = None
lasty = None
hue = 0

def handle_mousemove(x,y):
  global lastx, lasty, hue
示例#20
0
def handle_mousemove(x,y,button):
  if button == "left":
    color("blue")
    circle(x,y,10)
示例#21
0
from tealight.art import (color, line, spot, circle, box, image, text, background)

color("blue")

spot(300,200,30)
box(251,150,100,100)
circle(300,200,50)


x,y,size
示例#22
0
from tealight.art import (color, line, spot, circle, box, image, text,
                          background)

from math import sin, cos, pi


def circle(x, y, width, height):

    color("red")


circle(
    300,
    300,
    100,
    50,
)
circle(
    300,
    400,
    200,
    100,
)
circle(
    450,
    200,
    125,
    30,
)