예제 #1
0
  def draw(self, position = [30, 30], size = [200,200]):
    
    #Convert rgba vector to string
    def coltostr(col):
      string_out = "rgba("
      for i in range(0,3):
        string_out = string_out + str(int(col[i])) + ","
      string_out = string_out + str(col[3]) + ")"
      return string_out
    
    for i in range(0, self.i_size):
      for j in range(0, self.j_size):
        #Set rgba value based on max value

        
        #Convert to color string "rgba(...)
        #Positive values are red, negative are blue
        #Values close to zero will be paler
        if self.array[i][j] >= 0 :
          alpha_value = 1.0 * self.array[i][j]/self.max()
          rgba_string = coltostr([255, 0, 0, alpha_value])
        else:
          alpha_value = 1.0 * self.array[i][j]/self.min()
          rgba_string = coltostr([0, 0, 255, alpha_value])
        
        #Draw box
        color(rgba_string)
        box(position[0] + j * size[0]/self.j_size,
            position[1] + i * size[1]/self.i_size,
            size[0]/self.j_size - 1,
            size[1]/self.i_size - 1)
예제 #2
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)
예제 #3
0
  def draw_debug(self, position = [30, 30], size = [200,200]):
    for i in range(0, self.i_size):
      for j in range(0, self.j_size):
        #Set rgba value based on max value

        
        #Convert to color string "rgba(...)
        #Positive values are red, negative are blue
        #Values close to zero will be paler
        if self.array[i][j] >= 0 :
          colour = "red"
        else:
          colour = "blue"
        
        #Draw box
        color(colour)
        box(position[0] + j * size[0]/self.j_size,
            position[1] + i * size[1]/self.i_size,
            size[0]/self.j_size - 1,
            size[1]/self.i_size - 1)
        
        #Draw text
        color("white")
        text(position[0] + j * size[0]/self.j_size,
            position[1] + i * size[1]/self.i_size,
            str(i) + str(j) + " " + str(self.array[i][j]))
예제 #4
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)
예제 #5
0
 def draw_polygons(self):
   color("red")
   polygon(self.top_detector)
   polygon(self.bottom_detector)
   color("blue")
   for i in self.polygons:
     fill_polygon(i)
def handle_message(message):
  if message["type"] == "reset":
    initialPlayer2()
  
  if message["type"] == "line":    
    color(message["color"])
    line(message["x1"], message["y1"], message["x2"], message["y2"])
예제 #7
0
def handle_frame():
  global x,y,vx,vy,ax,ay
  
  color("white")
  
  spot(x,y,8)
  vx = (vx*0.95) + ax
  vy = (vy*0.95) + ay + 0.1
  
  x = x + vx
  y = y + vy 
  
  color("blue")
  if x<=0 or x>=900:
    vx = -vx
    ax = (-0.8*ax)
  elif y<=0 or y>=1000:
    vy = -vy
    ay = (-0.8*ay)
  spot(x,y,8)
  
  

  
  
예제 #8
0
def draw_static_things():
  blue_top = [(0,0),
              (0,screen_height/10),
              (screen_width,screen_height/10),
              (screen_width,0)]
  color("blue")
  fill_polygon(blue_top)
예제 #9
0
def handle_frame():
  global x,y,vx,vy
  
  color("white")
  spot(x,y,8)
  
  rx = x - screen_width / 2
  ry = y - screen_height / 2
  
  magsq = rx**2 + ry**2
  if magsq != 0:
    # normalise
    mag = sqrt(magsq)
    rx /= mag
    ry /= mag
    
    # apply inverse square rule
    rx *= g/magsq
    ry *= g/magsq
    
    vx -= rx / m
    vy -= ry / m
  
  x = x + vx
  y = y + vy
  
  color("blue")
  drawship(x, y, 0)
예제 #10
0
def DrawGrid():
  global OffsetX, OffsetY
  OffsetX = 0
  OffsetY = 0
  color("#cccccc")
  box(StartingX - 2,StartingY - 2,SquareSize * WLimit + 8,SquareSize * HLimit +8)
  for x in range(0,HLimit):
    for y in range(0,WLimit):
      if VisibleArray[x][y]==0:
        DrawCoveredSquare()
      elif VisibleArray[x][y] == 1:
        DrawUncoveredSquare()
        if BombArray[x][y] > 0:
          BombNumber = BombArray[x][y]
          DrawNumber(x,y,BombNumber)
        elif BombArray[x][y] == -1:
          if x == lastx and y == lasty:
            DrawMine(x,y, "red")
          else:
            DrawMine(x,y, "black")
      elif VisibleArray[x][y] == 2:
        DrawFlag(x,y)
      OffsetY += SquareSize
    OffsetX += SquareSize
    OffsetY = 0
예제 #11
0
def initialPlayer1():
    reset()
    drawToolbar()
    text(10, 10, "Colour Palette:")
    for i in range(0, 8):
        color(palette[i])
        box((i * 25 + 10), 35, 25, 25)
예제 #12
0
def flag(i,j):
  color("red")
  tx = startx + size/2 + i * size
  ty = starty + size/2 + j * size
  spot(tx, ty, size/3)
  color("black")
  text(tx - size/10, ty - size/10, "F")
def handle_message(message):
    if message["type"] == "reset":
        initialPlayer2()

    if message["type"] == "line":
        color(message["color"])
        line(message["x1"], message["y1"], message["x2"], message["y2"])
예제 #14
0
def handle_mousedown(x,y,button):
  global lastx, lasty
  
  if button == "left" and 350 > x > 250 and 350 > y > 250:
    
    color("red")
    box(250, 250, 100, 100)
예제 #15
0
def handle_frame(): 
  global x,y,vx,vy,constant,n
  
  n = n + 1
  
  for i in range(0,len(x)):
      color("white")
      spot(x[i],y[i],2)
      
      vx[i] = vx[i] + constant[i]
      
      angle = math.atan2(-vy[i],vx[i]) + (math.pi / 2)
  
      fx =  1 * math.cos(angle)
      fy = -1 * math.sin(angle)
  
      vxa = vx[i] + fx
      vya = vy[i] + fy
  
      factor = math.sqrt(vx[i]**2 + vy[i]**2) / math.sqrt(vxa**2 + vya**2)
  
      vx[i] = vxa * factor
      vy[i] = vya * factor
  
  
      x[i] = x[i] + vx[i]
      y[i] = y[i] + vy[i]
  
  
      color("black")
      spot(x[i],y[i],2)
예제 #16
0
def handle_frame(): 
  global x,y,vx,vy,ax,ay
  
  color("white")
  
  spot(x,y,8)
  
    
  vx = vx + ax
  vy = vy + ay
  
  
  #gravity
  vy = vy + gravity
  apply_gravity()
  
  #friction
  vx = apply_friction(vx)
  vy = apply_friction(vy)
  

  
  
  x = x + vx
  y = y + vy
  
  color("blue")
  
  spot(x,y,8)
  
  
예제 #17
0
def DrawPalette(x,y, colors, w, h):
  for c in colors:
    color(c)
    box(x, y, w, h)
    y = y + h
 
     colors = ["black", "grey"]
예제 #18
0
def handle_frame():
  global x,y,vx,vy,ax,ay
  
  if 1000 < y:
    vy=-vy
  elif y < 1:
    vy=-vy
    
    
  if 910 < x:
    vx=-vx  
  elif x < 1:
    vx=-vx
  
  color("white")
  
  spot(x,y,8)
  vx = vx + ax
  vy = vy + ay
  
  x = x + vx
  y = y + vy
  
  color("blue")
  
  spot(x,y,8)
예제 #19
0
def findMines():
  global mine
  for i in range(0, 10):
    for j in range(0, 10):
      if get(mine, i, j) == 1:
        color('red')
        box(i*60,j*60,50,50)
예제 #20
0
def doSecond(): 
  global points
  points = points-1
  color("white")
  box(0,0,100,100)
  color("black")
  text(0,0,points)
예제 #21
0
 def draw_points(self,points):
   global hue
   color("hsl(%d,100%%,40%%)" % hue)
   hue = hue + 1
   line(points[0],points[1],points[2],points[3])
   line(points[2],points[3],points[4],points[5])
   line(points[4],points[5],points[0],points[1])
예제 #22
0
def DrawClear(x,y):
  color("white")
  box(x*34+182,y*34+202,32,32)
  color("Black")
  if check(x,y) > 0:
    text(x*34+192,y*34+207,check(x,y))
    flags[x][y] = 3
예제 #23
0
def handle_frame():
    global x, y, vx, vy, ax, ay

    color("white")

    spot(x, y, 8)
    vx = vx + ax
    vy = vy + ay

    x2 = x + vx
    y2 = y + vy

    if x2 < 0:
        x = -x2
        vx = -vx
    elif x2 > screen_width:
        x = screen_width * 2 - x2
        vx = -vx
    else:
        x = x2

    if y2 < 0:
        y = -y2
        vy = -vy
    elif y2 > screen_height:
        y = screen_height * 2 - y2
        vy = -vy
    else:
        y = y2

    color("blue")

    spot(x, y, 8)
예제 #24
0
def handle_mousemove(x,y,button):
  if button == "right":
    color("black")
    draw_to(x,y)
  elif button == "left":
    color("red")
    draw_to(x,y)
예제 #25
0
def handle_frame():
  global x,y,vx,vy,ax,ay
  
  color("white")
  
  spot(x,y,8)
  vx = (vx + ax)
  vy = vy + (ay + grav)
  while vx != 0:
   
  
    if vx<0:
      vx = vx+ mu
    else:
      vx = vx- mu
    
  
    x = x + vx 
    y = y + vy
  x = x + vx
  y = y + vy
  color("blue")
 
  spot(x,y,8)
  
  
예제 #26
0
def findMines():
    global mine
    for i in range(0, 10):
        for j in range(0, 10):
            if get(mine, i, j) == 1:
                color('red')
                box(i * 60, j * 60, 50, 50)
예제 #27
0
def handle_frame():
    global x, y, vx, vy

    color("white")
    spot(x, y, 8)

    rx = x - screen_width / 2
    ry = y - screen_height / 2

    magsq = rx**2 + ry**2
    if magsq != 0:
        # normalise
        mag = sqrt(magsq)
        rx /= mag
        ry /= mag

        # apply inverse square rule
        rx *= g / magsq
        ry *= g / magsq

        vx -= rx / m
        vy -= ry / m

    x = x + vx
    y = y + vy

    color("blue")
    drawship(x, y, 0)
예제 #28
0
def handle_frame():
  global x,y,vx,vy,ax,ay
  
  color("white")
  
  spot(x,y,8)
  vx = vx + ax
  vy = vy + ay
  
  x2 = x + vx
  y2 = y + vy
  
  if x2 < 0:
    x=-x2
    vx=-vx
  elif x2 > screen_width:
    x=screen_width*2-x2
    vx=-vx
  else:
    x=x2
    
    
  if y2 < 0:
    y=-y2
    vy=-vy
  elif y2 > screen_height:
    y=screen_height*2-y2
    vy=-vy
  else:
    y=y2
  
  color("blue")
  
  spot(x,y,8)
예제 #29
0
def draw_grid(x, y, size):
    for i in range(10):
        for j in range(10):
            box(x + i * size, y + j * size, size, size)
            color("lightblue")
            box(x + size / 10 + i * size, y + size / 10 + j * size,
                size / 10 * 8, size / 10 * 8)
            color("black")
예제 #30
0
def makegrid():
  for j in range(0, 10):
    for i in range(0, 10):
      if((i+j) % 2) !=1:
        color("black")
      else:
        color("blue")
      box(i*60, j*60, 50, 50)
예제 #31
0
def toggleFlag(i, j):
    if flags[i][j]:
        color("lightblue")
        box(xstart + size / 10 + i * size, ystart + size / 10 + j * size,
            size / 10 * 8, size / 10 * 8)
    else:
        image(xstart + size * i, ystart + size * j + size / 10 * 2 - 4,
              "misc/PirateFlag.png")
예제 #32
0
def makegrid():
    for j in range(0, 10):
        for i in range(0, 10):
            if ((i + j) % 2) != 1:
                color("black")
            else:
                color("blue")
            box(i * 60, j * 60, 50, 50)
예제 #33
0
def DrawFlag(x,y):
  global SquareSize
  DrawCoveredSquare()
  BoxSize = SquareSize/3
  color("gold")
  box(StartingX + SquareSize * x + SquareSize/2 - BoxSize/2,StartingY + SquareSize * y + SquareSize/2 - BoxSize/2, SquareSize/3,SquareSize/3)
  color("orange")
  rectangle(StartingX + SquareSize * x + SquareSize/2 - BoxSize/2,StartingY + SquareSize * y + SquareSize/2 - BoxSize/2, SquareSize/3,SquareSize/3)
예제 #34
0
def print_params(P):
  color("black")
  t = ["a", "b", "c"]
  t[0] = str(P.J)
  t[1] = str(P.T)
  t[2] = str(P.B)
  
  for i in range(0,3):
    text(690, 50 + (i+1) * 20, t[i])
예제 #35
0
def doSecond(): 
  global points
  points = points - 1
  color("white")
  box(0,screen_height - 100, 100, 100)
  color("black")
  if points < 0:
    points = 0
  text(10,screen_height - 30, ("Points: " + str(points)))
예제 #36
0
 def __init__(self):
   self.polygons = []
   self.top = []
   
   color("white")
   box(0,screen_height/10,screen_width,screen_height)
   
   self.create_polygons()
   self.draw_polygons()
예제 #37
0
def handle_mousemove(x,y,button):
  global lastx, lasty, hue
  
  if button == "left":
    line(lastx, lasty, x, y)
    lastx = x
    lasty = y
    color("hsl(%d,100%%,50%%)" % hue)
    hue += 1
예제 #38
0
def handle_message(message):
    global stopCount
    if message["type"] == "stop":
        reset()
        stopCount = "true"
        finishButtons()

    if message["type"] == "line":
        color(message["color"])
        line(message["x1"], message["y1"], message["x2"], message["y2"])
예제 #39
0
def handle_mousemove(x, y):
    global lastx, lasty, hue

    line(lastx or x, lasty or y, x, y)
    color("hsl(%d,100%%,50%%)" % hue)

    hue += 1

    lastx = x
    lasty = y
예제 #40
0
def stopButton():
    global stopMinY, stopMaxY, stopMinX, stopMaxX
    color("red")
    rectangle((screen_width - 180), screen_height - 40, 150, 30)
    text(screen_width - 85, screen_height - 35, "STOP")
    stopMinX = (screen_width - 180)
    stopMaxX = (screen_width - 30)
    stopMinY = (screen_height - 40)
    stopMaxY = (screen_height - 10)
    print stopMinX
예제 #41
0
def handle_mousemove(x,y):
  global lastx, lasty, hue
  
  line(lastx or x, lasty or y, x, y)
  color("hsl(%d,100%%,50%%)" % hue)
  
  hue += 1
  
  lastx = x
  lasty = y
예제 #42
0
def star(x, y, c, w, h, spines):
  
  color(c)
  
  angle = 0
  
  for i in range(0, spines):
    x0 = x + (w * cos(angle))
    y0 = y + (h * sin(angle))
    line(x, y, x0, y0)
    angle = angle + (2 * pi / spines)
예제 #43
0
def getSurroundingMines(x, y):
    surround = 0
    global mine
    for i in range(-1, 2):
        for j in range(-1, 2):
            if get(mine, x + i, y + j) == 1:
                surround = surround + 1
    color('black')
    if surround > 0:
        text(x * 60 + 17, y * 60 + 20, surround)
    return surround
예제 #44
0
 def star(self, 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)
예제 #45
0
def handle_mousemove(x, y, button):
    global lastx, lasty

    if button == "left":
        line(lastx, lasty, x, y)
        lastx = x
        lasty = y
    elif button == "right":
        color("red")
        line(lastx, lasty, x, y)
        lastx = x
        lasty = y
예제 #46
0
def elipses(x, y, c, size, size2):

    color(c)

    angle = 0

    for i in range(0, size2):
        x0 = x + (size * cos(angle))
        y0 = y + (size * sin(angle))

        line(x, y, x0, y0)

        angle = angle + (2 * pi / size2)
예제 #47
0
def handle_mousedown(x, y, button):

    global score
    boxX = floor(x / 60)
    boxY = floor(y / 60)
    if boxX < 10:
        if boxY < 10:
            if ingame == 1:
                if button == "left":
                    uncover(boxX, boxY)
                if button == "right" and get(mine, boxX, boxY) != 2:
                    color("green")
                    spot(boxX * 60 + 25, boxY * 60 + 25, 10)
예제 #48
0
def handle_mousemove(x, y, button):
    global lastx, lasty

    if button == "left":
        color("red")
    elif button == "right":
        color("blue")
    else:
        return

    line(lastx, lasty, x, y)
    lastx = x
    lasty = y
예제 #49
0
def handle_mousemove(x, y, button):
  ox = (x - 300) / 15
  oy = (y - 200) / 15
  
  if ox**2 + oy**2 > (50-20)**2:
    ratio = float(ox**2 + oy**2) / (50-20)**2
    ox /= ratio
    oy /= ratio
  
  color("white")
  spot(300, 200, 49)
  
  color("black")
  spot(300 + ox, 200 + oy, 20)
예제 #50
0
def handle_mousemove(x, y, button):
    global lastx, lasty

    if button == "left":
        color("blue")
        line(lastx, lasty, x, y)
        lastx = x
        lasty = y

    if button == "right":
        color("purple")
        line(lastx, lasty, x, y)
        lastx = x
        lasty = y
예제 #51
0
def handle_mousemove(x, y, button):
    global lastx, lasty
    if button == "left":
        color(chosen_color)
        line(lastx, lasty, x, y)
        send({
            "type": "line",
            "x1": lastx,
            "y1": lasty,
            "x2": x,
            "y2": y,
            "color": chosen_color
        })
        lastx = x
        lasty = y
예제 #52
0
def handle_frame():
    global x, y, vx, vy, ax, ay

    color("white")

    spot(x, y, 8)
    vx = (vx + ax)
    vy = (vy + ay)

    x = (x + vx)
    y = (y + vy)

    color("blue")

    spot(x, y, 8)
예제 #53
0
def handle_frame():
    global x, y, vx, vy, ax, ay

    color("blue")

    spot(x, y, 8)
    vx = vx + ax
    vy = vy + ay

    x = x + vx
    y = y + vy

    color("red")

    spot(x, y, 36)
예제 #54
0
def drawcircle(player, x, y, grid):

    color(player)

    xloc = 125 + (x * 80)
    yloc = 125 + (y * 80)

    spot(xloc, yloc, 37.5)

    grid[x][y] = player

    for i in range(8):
        print grid[i]

    return grid
예제 #55
0
def setgrid():

    x = 125
    y = 125
    color("white")

    for i in range(8):
        for j in range(8):
            spot(x, y, 37.5)
            x += 80
        x = 125
        y += 80

    grid = [[0 for j in range(8)] for i in range(8)]

    return grid
예제 #56
0
def handle_frame():
  global x,y,vx,vy,ax,ay
  
  color("white")
  
  spot(x,y,8)
  vx = vx + ax
  vy = vy + ay
  
  x = x + vx
  y = y + vy
  
  color("blue")
  
  if ay < 0.6:
    ay += (1 * 10 ** -3) #Gravity in -Y direction

  spot(x,y,8)
예제 #57
0
def handle_frame():
    global x, y, vx, vy, ax, ay

    color("white")

    spot(x, y, 8)
    vx = vx + ax
    vy = vy + ay + gravity

    drag = -vy * 0.005
    vy += drag

    x = x + vx
    y = y + vy

    do_explosion()

    color("blue")

    spot(x, y, 8)
예제 #58
0
def reveal(i, j):
    global flags
    global uncovered
    if flags[i][j]:
        return
    if mines[i][j] == -1:
        defeat()
    tx = xstart + size / 10 + i * size
    ty = ystart + size / 10 + j * size
    color("white")
    box(tx, ty, size / 10 * 8, size / 10 * 8)
    color("black")
    text(tx + size / 10 * 3, ty + size / 10 * 3, mines[i][j])
    uncovered += 1
    flags[i][j] = 2
    if mines[i][j] == 0:
        for offx in range(-1, 2):
            for offy in range(-1, 2):
                if i + offx >= 0 and i + offx <= 9 and j + offy >= 0 and j + offy <= 9:
                    reveal(i + offx, j + offy)