Beispiel #1
0
def newGameInit(statusGame: list):
    draw_state(GAME_STATE, X_POS, Y_POS, WIDTH)
    for index in range(len(statusGame)):
        statusGame[index] = None
    time.sleep(3)
    canvas.clear()
    draw_state(GAME_STATE, X_POS, Y_POS, WIDTH)
Beispiel #2
0
def draw_state(statusList: list, x_pos=50, y_pos=50, width=250):
    canvas.clear()
    height = width  # высота поля равно ширине
    widKl = width // 3  # ширина клетки
    x = widKl // 2 + x_pos  # начальные координата середины клетки
    y = x
    index = 0  # индекс списка
    # отрисовка линий
    canvas.line_width(2)
    canvas.set_color('Grey')
    for n in [1, 2]:
        canvas.move_to(n * widKl + x_pos, 0 + y_pos)
        canvas.line_to(n * widKl + x_pos, height + y_pos)
        canvas.move_to(0 + x_pos, n * widKl + y_pos)
        canvas.line_to(width + x_pos, n * widKl + y_pos)

    canvas.line_width(5)
    for i in range(3):
        for j in range(3):
            el = statusList[index]
            index += 1
            # расчет координат середины текущей клетки
            _x = x + widKl * j
            _y = y + widKl * i
            if el is not None:
                if el == 'o':
                    canvas.set_color('Green')
                    canvas.circle(_x, _y, width * 0.1)
                if el == 'x':
                    canvas.set_color('Blue')
                    wNol = width * 0.1
                    canvas.move_to(_x - wNol, _y + wNol)
                    canvas.line_to(_x + wNol, _y - wNol)
                    canvas.move_to(_x - wNol, _y - wNol)
                    canvas.line_to(_x + wNol, _y + wNol)
def main():
    console.clear()
    canvas.clear()
    multiplier = 0.6
    WIDTH = 1920
    HEIGHT = 1080
    camera = Vector(0, 0, -1)
    objects = [
        Sphere(Point(0, 0, 1.0), 0.3, Color.from_hex("#F24F00")),
        Sphere(Point(0.2, 0, 0.4), 0.1, Color.from_hex("#224F00")),
        Sphere(Point(-0.25, 0.0, 0.4), 0.1, Color.from_hex("#1f8fd8")),
        Sphere(Point(0.4, -0.9, 1.7), 0.6, Color.from_hex("#d80cac")),
        Sphere(Point(-0.4, -0.9, 1.7), 0.6, Color.from_hex("#d8b63e"))
    ]
    scene = Scene(camera, objects, WIDTH, HEIGHT)
    engine = RenderEngine()
    image = engine.render(scene, 10)
def draw():
  #ceci est la fonction qui gere l'ecran
  global bits
  canvas.clear()
  canvas.fill_rect(0,0,500,500)
  
  left = 80
  top = 30
  canvas.draw_line((0,30+top),(500,30+top),4,'Blue')  
  cl2 = 'Yellow'
  
  canvas.draw_text("ENTREES",(left-30,25+top),24,cl2)
  canvas.draw_text("SORTIES",(left+250,25+top),24,cl2)
  equ = bits['A']*bits['B']
  canvas.draw_circle((left, 50+top), 10, 2, 'Blue', color(str(bits['A'])))
  canvas.draw_circle((left, 80+top), 10, 2, 'Blue', color(str(bits['B'])))
 
  canvas.draw_circle((left+250, 50+top), 10, 2, 'Blue', color(str(equ)))
  
  canvas.draw_text("A: "+str(bits['A']),(left+15,58+top),24,cl2)
  canvas.draw_text("B: "+str(bits['B']),(left+15,88+top),24,cl2)
  canvas.draw_text("L: "+str(equ),(left+265,58+top),24,cl2)
 
  canvas.draw_line((0,290+top),(100,290+top),3,'Red')
  canvas.draw_line((200,290+top),(150,290+top),3,'Blue')
  canvas.draw_line((500,290+top),(250,290+top),3,'Blue') 
  
  canvas.draw_circle((420, 290+top), 30, 2, 'Blue', color(str(equ)))
  
  canvas.draw_text("A",(115,270+top),24,cl2)
  canvas.draw_text("B",(215,270+top),24,cl2)
  canvas.draw_text("L",(410,240+top),24,cl2)
  
  if bits['A'] == 0:
    canvas.draw_line((100,290+top),(150,270+top),3,'Orange')
  else:
    canvas.draw_line((100,290+top),(150,290+top),3,'Orange')
    
  if bits['B'] == 0:
    canvas.draw_line((200,290+top),(250,270+top),3,'Orange')
  else:
    canvas.draw_line((200,290+top),(250,290+top),3,'Orange')
  
  """
Beispiel #5
0
def draw_menu(x, y, width):
    canvas.clear()
    global MENU
    global initMenu
    height = width
    if initMenu:
        canvas.fill_style('Black')
        canvas.fill_rect(x, y, width + 2, height + 2)
        canvas.fill_style('Grey')
        canvas.fill_rect(x, y, width, height)
        for el in MENU:
            button(el[0], el[1], el[2], el[3], el[4])
    else:
        initMenu = True
        count = len(MENU)
        for i in range(count):
            MENU[i][1] = x + (width - width * 0.8) / 2
            MENU[i][2] = y + (i + 1) * height / (count +
                                                 1) - width * 0.8 * 0.2 / 2
            MENU[i][3] = width * 0.8
            MENU[i][4] = width * 0.8 * 0.2
Beispiel #6
0
def message(caption, x, y, width):
    canvas.clear()
    height = width * 0.2
    canvas.fill_style('Black')
    canvas.fill_rect(x, y - height / 2, width + 2, height + 2)
    canvas.fill_style('Grey')
    canvas.fill_rect(x, y - height / 2, width, height)
    if caption == 'YOU WIN':
        color1 = 'DarkBlue'
        color2 = 'DeepSkyBlue'
    elif caption == 'YOU LOST':
        color1 = 'DarkRed'
        color2 = 'Red'
    else:
        color1 = 'Black'
        color2 = 'Green'
    canvas.fill_style(color1)
    canvas.fill_text(caption, x + width // 2 + 2, y + height * 0.3 + 2,
                     'Tahoma', width // 6, 'center')
    canvas.fill_style(color2)
    canvas.fill_text(caption, x + width // 2, y + height * 0.3, 'Tahoma',
                     width // 6, 'center')
Beispiel #7
0
    def render(self):
        self.time += 1
        canvas.clear()
        canvas.draw_image(images[self.fond.name], self.fond.center, self.fond.size, (470, 150), self.fond.size2, 0)
        canvas.draw_image(
            images[self.ball.info.name],
            self.ball.info.center,
            self.ball.info.size,
            self.ball.pos,
            self.ball.info.size2,
            self.ball.angle,
        )
        canvas.draw_line((500, 146), (400, 146), 3, "Red")
        canvas.draw_text("Score: " + str(self.ball.get_score()), (370, 46), 30, "Orange")
        c = self.get_kb()
        if c == "38":
            self.ball.shooting = True
            self.ball.shoot()
        if c == None:
            self.ball.shooting = False

        self.ball.update()
Beispiel #8
0
def render():
  global jeu, count, partie, timer
  canvas.clear()
  
  canvas.draw_image(echiquier, (175,171),(350,342),(250,250),(500,500),0)
 
  board = str(jeu.board).split()
 
  j = 0
  for ligne in board:
    i = 0
    for c in ligne:
      i += 1
      if c<> ".":
        x = ML+i*(W-2*ML)/8 - 25
        y = MT+j*(W-2*MT)/8 + 12
        p = pieces[c]
        
        canvas.draw_image(pions,
                         (
						 pions_center[0]+p[1]*pions_size[0],
                         pions_center[1]+p[0]*pions_size[1]),
                         pions_size,
                         (x,y),
                         pions_size2,
                         0
        )
    j += 1  
  
  
  
  if count < len(partie):
    canvas.draw_text(partie[count],(20,20),24,'Blue')
    jeu.move(partie[count])
    jeu.advance()
  
  count += 1
Beispiel #9
0
def render():
  global count, timer,a,b, points, lining
  canvas.clear()
  
  c = get_kb()
 
  if c == '37':
    #canvas.draw_text(250,250,"<-")
    lining = False
  if c == '39':
    #canvas.draw_text(250,250,"<-")
    lining = True
    
  ms = get_mouse()
  if len(ms) > 0:
    if not (ms in points):
      points.append(ms)
      count += 1
    for p in points:
      canvas.draw_circle(p[0],p[1],2)
  if lining:
    for i in range(len(points)-1):
      canvas.draw_line(points[i+1][0],points[i+1][1],
                       points[i][0],points[i][1])
Beispiel #10
0
    finally:
        canvas.restore_gstate()


screenHeight = 512
circleHeight = 128

colorBlue = (0, 0, 1)
colorGreen = (0, 1, 0)
colorRed = (1, 0, 0)


def coloredCircle(inColor, inX, inY):
    canvas.set_fill_color(*inColor)
    canvas.fill_ellipse(inX, inY, circleHeight, circleHeight)


canvas.clear()
canvas.set_size(screenHeight * 1.42, screenHeight)

with privateGstate():  # Save and then restore the canvas.gstate
    canvas.rotate(89)  # Text on an angle.
    canvas.draw_text('Green on top -->', 154, 0, 'Helvetica', 36)
canvas.draw_text('<-- Red and Blue on bottom', 282, 52, 'Helvetica', 36)

x = 20 + circleHeight
coloredCircle(colorRed, 10, 10)  # Red circle appears at bottom.
with flippedDisplay():  # Change origin to topLeft instead of bottomLeft.
    coloredCircle(colorGreen, x, 10)  # Green circle appears at top.
coloredCircle(colorBlue, x, 10)  # Blue circle appears at bottom.
Beispiel #11
0
 def render(self):
 
   #global errors, mot, to_find, msg , end_game
 
   canvas.clear()
 
   if self.msg <> None:
     canvas.draw_text(200,250,self.msg)
 
   if self.end_game:
     canvas.add_button(26*18,0,18,18,"@")
   
   c = self.get_mouse()
   if c <> None:
     #une lettre est cliquee mouse_handler
     #canvas.draw_text(200,250,c)
     self.mouse_handler(c)
   
 
   w = 18
   for i in range(26):
     canvas.add_button(i*w,0,18,18,chr(65+i))
 
 
   n = len(self.mot)
   p = (500 * 2) / ( 3*n + 1 )
   e = p / 2
   
   for i in range(len(self.mot)):
     if self.mot[i] in self.to_find:
       canvas.draw_line((i+1)*e+(i)*p,80,(i+1)*(e+p),80)
     else:
       a = (i+1)*e+(i)*p
       b = (i+1)*(e+p)
       canvas.draw_text((a+b)/2 - e/2 , 70, self.mot[i])
 
 
   if (self.errors > 1):
     canvas.draw_line(100,400,200,400)
   if (self.errors >= 2):
     canvas.draw_line(100,400,200,400)  
   if (self.errors >= 3):
     canvas.draw_line(150,400,150,150)
   if (self.errors >= 4):
     canvas.draw_line(150,150,300,150)
   if (self.errors >= 5):
     canvas.draw_line(225,150,150,230)
   if (self.errors >= 6):
     canvas.draw_line(300,150,300,180)
   if (self.errors >= 7):
     canvas.draw_circle(300,200,20)
   if (self.errors >= 8):
     canvas.draw_line(300,220,300,300)
   if (self.errors >= 9):
     canvas.draw_line(300,300,330,360)
   if (self.errors >= 10):
     canvas.draw_line(300,300,270,360)
   if (self.errors >= 11):
     canvas.draw_line(300,240,330,300)
   if (self.errors >= 12):
     canvas.draw_line(300,240,270,300)
Beispiel #12
0
import document
import canvas

canvas.clear()

count = 0
a = 250
b = 250
points = []
lining = True

def debug(info):
  console = document.getElementById("output")
  console.innerHTML = ""
  console.innerHTML = str(info)
  
def get_mouse():
  mouse = document.getElementById("mouse").innerHTML
  if mouse == 'mouse ...':
    return []
  else:
    return mouse.split(':')
def get_kb():
  kb = document.getElementById("editor").value
  debug(kb)
  if kb == '':
    return ""
  else:
    return kb
 
def render():
Beispiel #13
0
  def render(self):
    global a_missile, lives, score
    
          
    if lives == 0:
      canvas.draw_text("YOU LOOSE :(",(200,230),30,"Red")
      return
    
    self.time += 1
    wtime = (self.time / 4) % WIDTH
    
    canvas.clear()
    canvas.draw_image(self.fond.get_image(),self.fond.center,self.fond.size,(250,250),self.fond.size2,0)
    canvas.draw_image(self.debris.get_image(), self.debris.get_center(), self.debris.get_size(), (wtime - WIDTH / 2, HEIGHT / 2), (WIDTH, HEIGHT),0)
    canvas.draw_image(self.debris.get_image(), self.debris.get_center(), self.debris.get_size(), (wtime + WIDTH / 2, HEIGHT / 2), (WIDTH, HEIGHT),0)

    canvas.draw_image(self.ship.info.image,self.ship.info.center,self.ship.info.size,self.ship.pos,self.ship.info.size2,self.ship.angle)
    #canvas.draw_circle(self.ship.pos[0],self.ship.pos[1],self.ship.radius)
    canvas.draw_image(self.a_missile.info.image,self.a_missile.info.center,self.a_missile.info.size,self.a_missile.pos,self.a_missile.info.size2,self.a_missile.angle)  
   
    
    if self.a_rock.exploded:
      if (wtime) % 24 == 0:
        self.a_rock.exploded = False
        x = random.randrange(0,2)
        y = random.randrange(0,HEIGHT)
        x = x * WIDTH
        self.a_rock.set_pos(x,y)
        if x == 0:
          vx = 1
        else:
          vx = -1
        vy = 1
        self.a_rock.set_vit(vx,vy)
      #self.a_rock.exploded = False
      canvas.draw_image(self.a_rock_exploded.info.image,
                        (self.a_rock_exploded.info.center[0]
                         +((wtime) % 24)*self.a_rock_exploded.info.size[0],
                         self.a_rock_exploded.info.center[1]),
                        self.a_rock_exploded.info.size,
                        self.a_rock.pos,
                        self.a_rock_exploded.info.size,
                        0)  

    else:
      canvas.draw_image(self.a_rock.info.image,self.a_rock.info.center,self.a_rock.info.size,self.a_rock.pos,self.a_rock.info.size2,self.a_rock.angle)  
    canvas.draw_text("lives: "+str(lives)+" score: "+str(score),(320,30),24,'Orange')
    
    #canvas.draw_circle(self.a_rock.pos[0],self.a_rock.pos[1],self.a_rock.radius)
    
    c = self.get_kb()
    if c == '32':
      self.ship.shoot(self.a_missile)
    if c == '37':
      self.ship.dec_angle()
    if c == '39':
      self.ship.inc_angle()
    if c == '38' and (self.time % 10 == 0):
      self.ship.set_thrust(True)
    if c == None:
      self.ship.stop_angle()
      self.ship.set_thrust(False)
      
    self.ship.update()
    self.a_missile.update()
    self.a_rock.update()
    self.check_collision()
Beispiel #14
0
def clear():
    canvas.clear()