def circle(x, y, radius, color): iterations = 20 s = sin(2*pi / iterations) c = cos(2*pi / iterations) dx, dy = radius, 0 glColor4f(*color) glBegin(GL_TRIANGLE_FAN) glVertex2f(x, y) for i in range(iterations+1): glVertex2f(x+dx, y+dy) dx, dy = (dx*c - dy*s), (dy*c + dx*s) glEnd()
def draw_rect(x, y, width, height): gl.glBegin(gl.GL_QUADS) gl.glVertex2f(x, y) gl.glVertex2f(x + width, y) gl.glVertex2f(x + width, y + height) gl.glVertex2f(x, y + height) gl.glEnd()
def on_draw(): # clears the background with the background color gl.glClearColor(*background) gl.glClear(gl.GL_COLOR_BUFFER_BIT) # draw in a loop boundary = winsize - 100 gap = (winsize - boundary) / 2 i_width = boundary / len(rgb1) i_height = boundary / 2 # the first line for idx, rgb in enumerate(rgb1): gl.glColor3f(*rgb) gl.glBegin( gl.GL_QUADS ) # start drawing a rectangle in counter-clockwise (CCW) order gl.glVertex2f(gap + idx * i_width, gap + i_height) # bottom left point gl.glVertex2f(gap + (idx + 1) * i_width, gap + i_height) # bottom right point gl.glVertex2f(gap + (idx + 1) * i_width, gap + boundary) # top right point gl.glVertex2f(gap + idx * i_width, gap + boundary) # top left point gl.glEnd() label = pyglet.text.Label(str(color1[idx]), font_size=7, x=gap + idx * i_width, y=gap + boundary + 20) label.draw() # # # the second line for idx, rgb in enumerate(rgb2): gl.glColor3f(*rgb) gl.glBegin( gl.GL_QUADS ) # start drawing a rectangle in counter-clockwise (CCW) order gl.glVertex2f(gap + idx * i_width, gap) # bottom left point gl.glVertex2f(gap + (idx + 1) * i_width, gap) # bottom right point gl.glVertex2f(gap + (idx + 1) * i_width, gap + i_height) # top right point gl.glVertex2f(gap + idx * i_width, gap + i_height) # top left point gl.glEnd() label = pyglet.text.Label(str(color2[idx]), font_size=7, x=gap + idx * i_width, y=gap - 20) label.draw()