Making connections between GCSE Computer Science and GCSE Maths is a great way to turbo-charge your learning in both subjects. There are so many areas where the same knowledge can come up in both. For example coordinates, variables, inequalities, formulas and many other topics. There is an article about calculating distance here, with a game that shows a fun application.
Building Python programs to explore ideas from Maths is a great way to practice your coding skills and deepen your knowledge of Maths at the same time.
It’s also very handy for teaching – once you have gained some skill using a Graphical User Interface such as turtle
or Tkinter
, you can fairly easily code up a game or demonstration program to help make learning more engaging and effective.
Below is a program that allows you to explore the symmetry of an equilateral triangle. There are some parts which are a little complex for GCSE Computer Science level (the Tkinter
buttons for example), but with a little work and learning, you will probably be able take parts of the code and use them for your own programs.
A Program to explore Triangle Symmetries with Python Turtle Graphics
This code can be found on my GitHub.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | import turtle import tkinter as tk screen = turtle.Screen() class Label(turtle.Turtle): def __init__(self, coordinates=None, screen=screen): turtle.Turtle.__init__(self) if coordinates is None: self.coordinates = [0, 0] else: self.coordinates = coordinates self.text = "" self.color("white") self.coordinates = coordinates self.hideturtle() self.penup() self.screen = screen def show(self, message, alignment="center", size=18): self.screen.tracer(0) self.clear() self.goto(self.coordinates) self.write( message, font=("Helvetica", size), align=alignment, ) self.screen.tracer(1) def show_labels(vertices): global label1, label2, label3 label1.show(vertices[0]) label2.show(vertices[1]) label3.show(vertices[2]) def clear_labels(): global label1, label2, label3 label1.clear() label2.clear() label3.clear() def reset(): global vertices vertices = ["A", "B", "C"] show_labels(vertices) def rotate_clockwise(): global vertices temp = vertices[-1] for i in range(len(vertices) - 1, 0, -1): vertices[i] = vertices[i - 1] vertices[0] = temp update_rotation("clockwise") def rotate_anticlockwise(): global vertices temp = vertices[0] for i in range(len(vertices) - 1): vertices[i] = vertices[i + 1] vertices[-1] = temp update_rotation("anticlockwise") def reflect_A(): global vertices b_pos = vertices.index("B") c_pos = vertices.index("C") vertices[b_pos], vertices[c_pos] = ( vertices[c_pos], vertices[b_pos], ) update_reflection() def reflect_B(): global vertices a_pos = vertices.index("A") c_pos = vertices.index("C") vertices[a_pos], vertices[c_pos] = ( vertices[c_pos], vertices[a_pos], ) update_reflection() def reflect_C(): global vertices a_pos = vertices.index("A") b_pos = vertices.index("B") vertices[a_pos], vertices[b_pos] = ( vertices[b_pos], vertices[a_pos], ) update_reflection() def update_rotation(direction): global triangle clear_labels() if direction == "clockwise": triangle.right(120) else: triangle.left(120) show_labels(vertices) def update_reflection(): global triangle clear_labels() show_labels(vertices) def make_button(canvas, text, command): return tk.Button( canvas.master, font=("Helvetica", 12), text=text, background="hotpink", foreground="white", bd=0, command=command, ) def create_button(canvas, x, y, text, command): canvas.create_window( x, y, window=make_button(canvas, text, command) ) if __name__ == "__main__": screen.setup(500, 600) screen.title("Symmetries of an Equilateral Triangle") screen.bgcolor("blue") canvas = screen.getcanvas() label1 = Label([-85, -55]) label2 = Label([0, 75]) label3 = Label([85, -55]) triangle = turtle.Turtle("triangle") triangle.shapesize(120 / 20) triangle.color("hotpink") triangle.right(30) canvas = screen.getcanvas() create_button(canvas, 0, -250, "Reset", reset) create_button( canvas, 0, -150, "Rotate 120° clockwise", rotate_clockwise, ) create_button( canvas, 0, -200, "Rotate 120° anticlockwise", rotate_anticlockwise, ) create_button( canvas, 0, 100, "Reflect about perp. bisector of BC", reflect_A, ) create_button( canvas, 0, 150, "Reflect about perp. bisector of AC", reflect_B, ) create_button( canvas, 0, 200, "Reflect about perp. bisector of AB", reflect_C, ) vertices = ["A", "B", "C"] show_labels(vertices) turtle.done() |
If you need any help understanding the code or have any questions or comments, please let me know in the comments section below.