Skip to content

Instantly share code, notes, and snippets.

@ringodin
Created May 4, 2020 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ringodin/914816c70cac2e209ae358ab3d1de4e4 to your computer and use it in GitHub Desktop.
Save ringodin/914816c70cac2e209ae358ab3d1de4e4 to your computer and use it in GitHub Desktop.
This python code makes a 7 x 6 grid show up for Connect 4.
from pyglet import app
from pyglet import clock
from pyglet.window import Window
from pyglet.window import mouse
from pyglet.window import key
from pyglet import graphics
from pyglet import gl
from pyglet import text
from math import sin, cos, pi
cols = 7 # don't change this
rows = 6 # don't change this
col_width = row_height = 140 #change if you like
grid_color = (255, 0, 255, 0) #change color if you like
win_width = cols * col_width
win_height = rows * row_height
window = Window(win_width, win_height)
@window.event
def on_draw():
window.clear()
draw_grid()
def draw_grid():
for i in range(cols):
draw_line(i*row_height, 0, i*row_height, win_height, color = grid_color)
for i in range(rows):
draw_line(0, i*col_width, win_width, i*col_width, color = grid_color)
def draw_line(x1, y1, x2, y2, color = (255, 255, 255, 0)):
graphics.draw(2, gl.GL_LINES, ('v2i', (x1, y1, x2, y2)), ('c4B', color * 2) )
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment