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
def draw(): global max_twist age = now() - start if mouse_x is not None: m_a = (mouse_x / float(screen_width) - 0.5) * 2 * real_max_twist max_twist = m_a else: m_a = cos(age / 2.) * max_twist * exp(-age / 20) color("black") box(0, 0, screen_width, screen_height) for i in range(0, num_triangles): size = min_size + (max_size - min_size) * float(i) / num_triangles size = max_size - size size *= (sin(now() + pulse_offset[i]) * pulse_magnitude + 1) l = min_l + (max_l - min_l) * float(i) / num_triangles tri = make_triangle( screen_width / 2., screen_height / 2., size, i * m_a + sin(now() + rot_pulse_offset[i]) * pulse_magnitude) color("hsl(230,100%," + str(round(l)) + "%)") fill_polygon(tri) color("hsl(230,100%," + str(round(l - 10)) + "%)") polygon(tri)
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)
def DrawPalette(x,y, colors, w, h): for c in colors: color(c) box(x, y, w, h) y = y + h colors = ["black", "grey"]
def doSecond(): global points points = points-1 color("white") box(0,0,100,100) color("black") text(0,0,points)
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)
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)
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)
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
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)
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]))
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)
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)
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)
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")
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)
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")
def __init__(self): self.polygons = [] self.top = [] color("white") box(0,screen_height/10,screen_width,screen_height) self.create_polygons() self.draw_polygons()
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)))
def handle_frame(): global car1, car2, leftPressed, rightPressed, upPressed, downPressed, aPressed, sPressed, dPressed, wPressed, explosions, explosionCount color("white") box(0, 0, screen_width, screen_height) color("red") if leftPressed: car1.change_orientation(4) elif rightPressed: car1.change_orientation(-4) elif upPressed: car1.Acceleration += 0.01 if car1.Acceleration > 0.05: car1.Acceleration = 0.05 elif downPressed: if car1.Acceleration == 0: if car1.Acceleration < -0.05: car1.Acceleration = -0.05 else: car1.Acceleration -= 0.01 if aPressed: car2.change_orientation(4) elif dPressed: car2.change_orientation(-4) elif wPressed: car2.Acceleration += 0.01 if car2.Acceleration > 0.05: car2.Acceleration = 0.05 elif sPressed: if car2.Acceleration == 0: if car2.Acceleration < -0.05: car2.Acceleration = -0.05 else: car2.Acceleration -= 0.01 car1.update_speed() car2.update_speed() testCollisions() car1.draw_car("Foo") car2.draw_car("Bar") for i in range(0, explosionCount): if explosions[i] != None: if explosions[i].draw(): explosions[i] = None # for i in range (0, len(otherCars)): #Draw connected players cars # otherCars[i].draw() #Draw the map color("green") rectangle(outerWallX, outerWallY, outerWallWidth, outerWallHeight)
def DrawBomb(x,y): color("red") box(x*34+182,y*34+202,32,32) centrex = 199 + 34 * x centrey = 219 + 34 * y color("black") spot(centrex,centrey,10)
def drawGrid(x,y,s,data): counter = 0 n = len(data) for i in xrange(0,n): for j in xrange(0,n): if data[i][j] == 0: color("Black") else: color("white") box(x + i*1.5*s,y + j*1.5*s,s,s) counter += 1
def draw_spins(render_spin_changed, N): global P initial_offset = [30,30] square_size = [500/s.side_length,500/s.side_length] for i in range(0, N): if(render_spin_changed[i][2] == 1): color(P.UpColour) else: color(P.DownColour) #Draw boxes box(render_spin_changed[i][0]*square_size[0] + initial_offset[0], render_spin_changed[i][1]*square_size[1] + initial_offset[1], square_size[0]-1, square_size[0]-1)
def handle_frame(): global car1 #Sets the scope of "car1" to global, so can be used anywhere within this program car1.update_speed() #Calls the update_speed() method to update the speed of the car color("white") #Sets the colour of each element to white, as to clear the screen box(0, 0, 10000, 10000) #Draws as new white box over the entire screen, as to clear the screen car1.draw_car("Foo")
def draw_lattice(s): global P initial_offset = [30,30] square_size = [500/s.side_length,500/s.side_length] for i in range(0, s.side_length): for j in range(0, s.side_length): if(s.Array[i][j] == 1): color(P.UpColour) else: color(P.DownColour) #Draw boxes box(i*square_size[0] + initial_offset[0], j*square_size[1] + initial_offset[1], square_size[0]-1, square_size[0]-1)
def handle_frame(): global x,y,vx,vy,ax,ay color("white") box(0,0,screen_width,screen_height) color("black") spot(x, y, 20) vx = (vx+ax)*0.97 vy = vy + ay +0.12 if vy > 10: vy =10 x = x + vx y = y + vy
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)
def drawGrid(): font("100px arial") text(250,55, "Connect 4") color("blue") box(offset_x,offset_y,700,700) x=offset_x + 49 y=offset_y +49 for i in range(0,7): for j in range(0,7): color("white") spot(x+i*100,y+j*100,35) color("black")
def draw(): m_a = sin(age() / 1.) * 2 * pi * 2. / num_triangles color("white") box(0, 0, screen_width, screen_height) for i in range(0, 0 + num_triangles): size = min_size + (max_size - min_size) * float(i) / num_triangles l = min_l + (max_l - min_l) * float(i) / num_triangles tri = make_triangle(screen_width / 2., screen_height / 2., max_size - size, i * m_a) color("hsl(0,100%," + str(round(l)) + "%)") fill_polygon(tri) color("hsl(0,100%," + str(round(l - min_l)) + "%)") polygon(tri)
def draw(Num_1,Num_2): if Winner == 3: image(850,50,"http://i.imgur.com/0zoXV5h.png") color("White") box(840,120,500,200) color("Black") text(850,125, "Player 1: %d" % Num_1) text(1050,125, "Player 2: %d" % Num_2) image(850,155,"animals/Diplodocus.png") image(1050,180,"animals/Stegosaurus.png") x = 25 y = 25 color("green") box(25,25,800,800) color("black") for i in range(0,9): line(x,y,x,(y+800)) x += 100 x = 25 for j in range(0,9): line(x,y,(x+800),y) y += 100 for a in range(0,8): for b in range(0,8): if Grid[a][b] == 1: y1 = a x1 = b y1 *= 100 y1 += 30 x1 *= 100 x1 += 30 image(x1,y1,"animals/Diplodocus.png") elif Grid[a][b] == 2: y1 = a x1 = b y1 *= 100 y1 += 55 x1 *= 100 x1 += 35 image(x1,y1,"animals/Stegosaurus.png")
def draw(Num_1,Num_2): if Winner == 3: image(450,50,"http://i.imgur.com/0zoXV5h.png") text(450,150, "Player 1: (%d)" % Num_1) text(450,250, "Player 2: (%d)" % Num_2) x = 25 y = 25 color("green") box(25,25,400,400) color("black") for i in range(0,9): line(x,y,x,(y+400)) x += 50 x = 25 for j in range(0,9): line(x,y,(x+400),y) y += 50 for a in range(0,8): for b in range(0,8): if Grid[a][b] == 1: y1 = a x1 = b y1 *= 125 y1 += 15 y1 /= 2.0 x1 *= 125 x1 += 15 x1 /= 2.0 image(x1,y1,"http://i.imgur.com/Ef7rj15.png") elif Grid[a][b] == 2: y1 = a x1 = b y1 *= 125 y1 += 15 y1 /= 2.0 x1 *= 125 x1 += 5 x1 /= 2 image(x1,y1,"http://i.imgur.com/mTw75jg.png")
def draw(): m_a = sin(age()/1.) * 2*pi * 2. / num_triangles color("white") box(0,0,screen_width,screen_height) for i in range(0, 0+num_triangles): size = min_size + (max_size - min_size) * float(i) / num_triangles l = min_l + (max_l - min_l) * float(i) / num_triangles tri = make_triangle(screen_width/2., screen_height/2., max_size-size, i*m_a) color("hsl(0,100%," + str(round(l)) + "%)") fill_polygon(tri) color("hsl(0,100%," + str(round(l-min_l)) + "%)") polygon(tri)
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 DrawPalette(x,y, colors, w, h): for c in colors: if c == "rainbow": color("blue") box(x,y, w/3, h) color("red") box(x+h/3, y, w/3, h) color("limegreen") box(x+2*h/3, y, w/3, h) else: color(c) box(x, y, w, h) y = y + h
def draw(): color("blue") box(offset_x,offset_y,cell_size * cells_x,cell_size * cells_y) width = 20 height = 8 for i in range(0,cells_x): for j in range(0,cells_y): if boardArray [j][i] == 0: color("white") elif boardArray[j][i] == 1: color("red") elif boardArray[j][i] == 2: color("yellow") spot(offset_x + i * cell_size + cell_size/2, offset_y + j * cell_size + cell_size/2, cell_size *0.4) check_winner(boardArray)
def DrawPalette(x, y, colors, w, h): for c in colors: if c == "rainbow": color("blue") box(x, y, w / 3, h) color("red") box(x + h / 3, y, w / 3, h) color("limegreen") box(x + 2 * h / 3, y, w / 3, h) else: color(c) box(x, y, w, h) y = y + h
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)
def Num_of_Values(): global Winner Num_0 = 0 Num_1 = 0 Num_2 = 0 for a in range(0,8): for b in range(0,8): c = Grid[a][b] if c == 0: Num_0 += 1 elif c == 1: Num_1 += 1 elif c == 2: Num_2 += 1 if Num_0 == 0: if Num_1 > Num_2: Winner = 1 elif Num_1 == Num_2: Winner = 0 elif Num_2 > Num_1: Winner = 2 if Winner == 1 or Winner == 2: color("White") box(26,26,399,399) color("Red") text(75,195,"Game over. The winner was player (%d)" % Winner) text(75,215,"To restart, run again.") else: color("White") box(26,26,399,399) color("Red") text(75,195,"Game over. Both players got the same score.") text(75,215,"To restart, run again.") return elif Num_1 == 0: color("White") box(26,26,399,399) color("Red") text(75,195,"Game over. The winner was player 2.") text(75,215,"To restart, run again.") return elif Num_2 == 0: color("White") box(26,26,399,399) color("Red") text(75,195,"Game over. The winner was player 1.") text(75,215,"To restart, run again.")
def drawToolbar(): tools = ["line","bold","circle","bird","stars","italics","triangle","hearts","eraser"] text (screen_width - 300, 10, "Toolbar:") rectangle(screen_width - 300,35,25,25) line(screen_width - 286, 40, screen_width - 286, 52) rectangle(screen_width - 275,35,25,25) box (screen_width - 264, 37, 5, 20) rectangle(screen_width - 250,35,25,25) spot (screen_width - 238, 47, 8) rectangle(screen_width - 225,35,25,25) text(screen_width - 219, 38, "B") rectangle(screen_width - 200,35,25,25) text(screen_width - 193, 38, "*") rectangle(screen_width - 175,35,25,25) text(screen_width - 165, 38, "/") rectangle(screen_width - 150,35,25,25) text(screen_width - 145, 38, "T") rectangle(screen_width - 125,35,25,25) text(screen_width - 120, 38, "H") rectangle(screen_width - 100,35,25,25) text(screen_width - 95, 38, "X")
def draw_mag_square(col1, col2, M): pos = [600, 200] size = [100,150] color("white") box(pos[0], pos[1], size[0]+30, size[1]) f_up = 0.5*(M+1) f_down = 1 - f_up color(col1) box(pos[0], pos[1], size[0]*0.5, size[1]*f_up) color(col2) box(pos[0]+size[0]*0.5+20, pos[1], size[0]*0.5, size[1]*f_down)
def Drawemptysquare(x,y): color('white') box(x, y, 30, 30)
from tealight.art import (color, line, spot, circle, box, image, text, background) color("purple") spot(300, 200, 40) circle(300, 200, 50) box(250, 275, 100, 100)
from tealight.art import (color, line, spot, circle, box, image, text, background) color("blue") spot(300, 200, 25) circle(300, 200, 50) box(250, 250, 100, 100)
from tealight.art import (color, line, spot, circle, box, image, text, background) for x in range(0, 54): for y in range(0, 39): if y > x * x: color("red") elif y > x: color("green") elif y * y < x: color("yellow") else: color("blue") box(x * 10, y * 10, 10, 10)
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): global lastx, lasty, hue
from tealight.art import (color, line, spot, circle, box, image, text, background) color("blue") spot(300, 200, 25) circle(300, 200, 50) box(250, 400, 100, 100)
from tealight.art import (color, line, spot, circle, box, image, text, background) color("blue") box(50, 50, 725, 725) 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 def drawcircle(player, x, y, grid): color(player) xloc = 125 + (x * 80) yloc = 125 + (y * 80)
from tealight.art import (color, line, spot, circle, box, image, text, background) color("blue") spot(300, 200, 20) circle(300, 200, 50) box(250, 150, 100, 100)
def uncover(boxX, boxY): global score global ingame global mine if get(mine, boxX, boxY) == 1: color('red') box(boxX * 60, boxY * 60, 50, 50) ingame = 0 color("white") box(0, 600, 500, 50) color("black") text(0, 600, "Final score: " + str(score)) text(500, 600, "You Lost!") findMines() if get(mine, boxX, boxY) == 0: color('white') box(boxX * 60, boxY * 60, 50, 50) setbox(mine, boxX, boxY, 2) end = getSurroundingMines(boxX, boxY) score = getscore() color("white") box(0, 600, 500, 50) color("black") text(0, 600, "Score: " + str(score)) if score == 85: score = 100 ingame = 0 color("white") box(0, 600, 500, 50) color("black") text(0, 600, "Final score: " + str(score)) text(500, 600, "You WIN!") if end == 0: if boxX < 9: if boxY < 9: if boxX > 0: if boxY > 0: uncover(boxX + 1, boxY) uncover(boxX - 1, boxY) uncover(boxX, boxY + 1) uncover(boxX, boxY - 1) if boxX < 9: if boxY == 9: if boxX > 0: uncover(boxX + 1, boxY) uncover(boxX - 1, boxY) uncover(boxX, boxY - 1) if boxX < 9: if boxY == 0: if boxX > 0: uncover(boxX + 1, boxY) uncover(boxX - 1, boxY) uncover(boxX, boxY + 1) if boxY < 9: if boxX == 9: if boxY > 0: uncover(boxX + 1, boxY) uncover(boxX - 1, boxY) uncover(boxX, boxY - 1) if boxY < 9: if boxX == 0: if boxY > 0: uncover(boxX, boxY + 1) uncover(boxX, boxY - 1) uncover(boxX + 1, boxY) if boxX == 0: if boxY == 9: uncover(boxX, boxY - 1) uncover(boxX + 1, boxY) if boxX == 9: if boxY == 0: uncover(boxX, boxY + 1) uncover(boxX - 1, boxY) if boxX == 0: if boxY == 0: uncover(boxX, boxY + 1) uncover(boxX + 1, boxY) if boxX == 9: if boxY == 9: uncover(boxX, boxY - 1) uncover(boxX - 1, boxY)
def initialPlayer2(): color("white") box(0, 0, screen_width, screen_height) color("black")
def reset(): color("white") box(0, 0, screen_width, screen_height) color("black")
import random from random import randrange from math import floor from tealight.art import (color, line, spot, circle, box, image, text, background) score = 0 ingame = 1 color('white') box(0, 0, 1000, 1000) color("black") text(0, 600, "Score: " + str(score)) #this makes the grid 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) #this gets the information about a box from the corresponding list def get(A, x, y): position = (11 * (y)) + x return A[position] #this sets the information about a box to the corresponding lis
from tealight.art import (color, line, spot, circle, box, image, text, background) color("blue") spot(300, 200, 20) circle(300, 200, 50) box(250.5, 300, 5000, 100)
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)
from tealight.art import (color, line, spot, circle, box, image, text, background) color("blue") spot(100,200,50) circle(300,200,50) box(450,150,100,100)
print "A new file!" from tealight.art import (color, line, spot, circle, box, image, text, background) from tealight import * color("black") box(0,0,1000,1200) color("white") box(180,200,546,546) x = 182 y = 202 for Ycounter in range(0,16): for Xcounter in range(0,16): color("grey") box(x,y,32,32) x = x + 34 y = y + 34 x = 182 color("black") spot(231,354,10) color("white") spot(227,349,2) color("black") line(231,342,231,339)
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)