├── FUNDING.yml ├── __pycache__ ├── ui.cpython-39.pyc ├── line.cpython-39.pyc ├── main.cpython-39.pyc ├── event.cpython-39.pyc ├── constants.cpython-39.pyc ├── updateUI.cpython-39.pyc └── parameters.cpython-39.pyc ├── constants.py ├── event.py ├── main.spec ├── README.md ├── line.py ├── parameters.py ├── ui.py └── main.py /FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: auctux 2 | ko_fi: auctux 3 | -------------------------------------------------------------------------------- /__pycache__/ui.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/Visualization-basic-Trigonometry/HEAD/__pycache__/ui.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/line.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/Visualization-basic-Trigonometry/HEAD/__pycache__/line.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/main.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/Visualization-basic-Trigonometry/HEAD/__pycache__/main.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/event.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/Visualization-basic-Trigonometry/HEAD/__pycache__/event.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/constants.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/Visualization-basic-Trigonometry/HEAD/__pycache__/constants.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/updateUI.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/Visualization-basic-Trigonometry/HEAD/__pycache__/updateUI.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/parameters.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Josephbakulikira/Visualization-basic-Trigonometry/HEAD/__pycache__/parameters.cpython-39.pyc -------------------------------------------------------------------------------- /constants.py: -------------------------------------------------------------------------------- 1 | Width, Height = 1920, 1080 2 | size = (Width, Height) 3 | speed = 0.8 4 | 5 | #rgb colors 6 | YaxisColor = (172,231,252) 7 | XaxisColor = (247,206,176) 8 | OriginColor = (50, 50, 50) 9 | 10 | SinColor = (214,45,32) 11 | CosColor = (0,87,231) 12 | TanColor = (0,135,68) 13 | CtanColor = (255,167,0) 14 | SecColor = (61,30,109) 15 | CscColor = (255,85,136) 16 | valueColor = (255, 255, 255) 17 | strokeGraph = 2 18 | 19 | XwaveColor = (251,54,64) 20 | YwaveColor = (0,90,141) 21 | TanGraphColor = (200,117,0) 22 | SecFunctionColor = (31,0,89) 23 | CscFunctionColor = (225,55,106) 24 | 25 | limit = 1000 26 | -------------------------------------------------------------------------------- /event.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | 3 | def HandleEvent(clicked, pause, showUI, showValues): 4 | running = True 5 | for event in pygame.event.get(): 6 | if event.type == pygame.QUIT: 7 | running = False 8 | if event.type == pygame.MOUSEBUTTONUP: 9 | clicked = True 10 | if event.type == pygame.KEYUP: 11 | if event.key == pygame.K_ESCAPE: 12 | running = False 13 | if event.key == pygame.K_p: 14 | pause = not pause 15 | if event.key == pygame.K_SPACE: 16 | showUI = not showUI 17 | if event.key == pygame.K_s: 18 | showValues = not showValues 19 | return running, clicked, pause, showUI, showValues 20 | -------------------------------------------------------------------------------- /main.spec: -------------------------------------------------------------------------------- 1 | # -*- mode: python ; coding: utf-8 -*- 2 | 3 | 4 | block_cipher = None 5 | 6 | 7 | a = Analysis(['main.py'], 8 | pathex=['D:\\PROJECTS\\Trigonometry'], 9 | binaries=[], 10 | datas=[], 11 | hiddenimports=[], 12 | hookspath=[], 13 | runtime_hooks=[], 14 | excludes=[], 15 | win_no_prefer_redirects=False, 16 | win_private_assemblies=False, 17 | cipher=block_cipher, 18 | noarchive=False) 19 | pyz = PYZ(a.pure, a.zipped_data, 20 | cipher=block_cipher) 21 | exe = EXE(pyz, 22 | a.scripts, 23 | a.binaries, 24 | a.zipfiles, 25 | a.datas, 26 | [], 27 | name='main', 28 | debug=False, 29 | bootloader_ignore_signals=False, 30 | strip=False, 31 | upx=True, 32 | upx_exclude=[], 33 | runtime_tmpdir=None, 34 | console=False ) 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Visualization-basic-Trigonometry 3 | #### Youtube Channel: http://www.youtube.com/channel/UCjPk9YDheKst1FlAf_KSpyA?sub_confirmation=1 4 | --- 5 | 6 | ### commands 7 | "Space" to toggle the parameter panel 8 | "P" to pause the program 9 | "S" to show values 10 | "ESC" to close the program 11 | --- 12 | ### overview 13 | ![Screenshot (128)](https://user-images.githubusercontent.com/48150537/122634658-0db1ee00-d0fd-11eb-9b36-74553089a80f.png) 14 | 15 | --- 16 | ### parameter panel 17 | ![Screenshot (129)](https://user-images.githubusercontent.com/48150537/122634650-f541d380-d0fc-11eb-978b-750fe23939c7.png) 18 | --- 19 | ![Screenshot (118)](https://user-images.githubusercontent.com/48150537/122188097-422f6b00-cead-11eb-9073-394f48e630e8.png) 20 | ![Screenshot (130)](https://user-images.githubusercontent.com/48150537/122634767-e576bf00-d0fd-11eb-9f67-c0e12b76da5e.png) 21 | ![ezgif com-gif-maker (2)](https://user-images.githubusercontent.com/48150537/121996722-c1963f00-cdc6-11eb-9e46-3cb11e52f6ed.gif) 22 | 23 | --- 24 | this code is a mess 25 | #### enjoy the spaghetti code 🍝 26 | -------------------------------------------------------------------------------- /line.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | 3 | class Line: 4 | def __init__(self, pointA, pointB, color, stroke=5, text=None, textPosition="Top"): 5 | self.pointA = [int(i) for i in pointA] 6 | self.pointB = [int(i) for i in pointB] 7 | self.color = color 8 | self.text = text 9 | self.textPosition = textPosition 10 | self.stroke = stroke 11 | self.font = 'freesansbold.ttf' 12 | self.fontSize = 18 13 | self.textColor = color 14 | 15 | def Show(self, screen): 16 | #get mid point of a segment 17 | x = (self.pointA[0] + self.pointB[0])//2 18 | y = (self.pointA[1] + self.pointB[1])//2 19 | 20 | if self.textPosition == "Top": 21 | y -= self.stroke * 6 22 | elif self.textPosition == "Bottom": 23 | y += self.stroke * 6 24 | elif self.textPosition == "Right": 25 | x += self.stroke * 6 26 | else: 27 | x -= self.stroke * 6 28 | font = pygame.font.Font(self.font, self.fontSize) 29 | text = font.render(self.text, True, self.textColor) 30 | textRect = text.get_rect() 31 | textRect.center = (x, y) 32 | try: 33 | pygame.draw.line(screen, self.color, self.pointA, self.pointB, self.stroke) 34 | screen.blit(text, textRect) 35 | except Exception as e: 36 | print("An exception occurred: ", e) 37 | -------------------------------------------------------------------------------- /parameters.py: -------------------------------------------------------------------------------- 1 | from ui import * 2 | 3 | #circle 4 | radius = 200 5 | circleStroke = 3 6 | angleArc = 100 7 | 8 | waveOffset = radius 9 | temp = waveOffset 10 | 11 | # toggles 12 | Dark = True 13 | projection = False 14 | showAxis = True 15 | showPoint = True 16 | showLine = True 17 | showOrigin = True 18 | showCos = True 19 | showSin = True 20 | showTan = False 21 | showCtan = False 22 | showSec = False 23 | showCsc = False 24 | showTheta = False 25 | showXwave = False 26 | showYwave = False 27 | showTanGraph = False 28 | showSecFunction = False 29 | showCscFunction = False 30 | showValues = False 31 | showUI = False 32 | offsetWaves = False 33 | pause = False 34 | # ui parameters 35 | 36 | panel = Panel( position = (Width-380, 50), w= 360, h= 1000, color=(0, 0, 0), alpha=100) 37 | 38 | UItoggle = TextUI("Press 'SPACE' to show parameter panel", (Width-280, 120), (55, 220, 55)) 39 | UItoggle.fontSize = 18 40 | 41 | SinText = TextUI( "Sin :", (Width-350, 100), (255, 255, 255), "topleft") 42 | CosText = TextUI( "Cos :", (Width-350, 140), (255, 255, 255), "topleft") 43 | TanText = TextUI( "Tangent :", (Width-350, 180), (255, 255, 255), "topleft") 44 | CoText = TextUI( "Cotangent :", (Width-350, 220), (255, 255, 255), "topleft") 45 | SecText = TextUI( "Secante :", (Width-350, 260), (255, 255, 255), "topleft") 46 | CosecText = TextUI("cosecante :", (Width-350, 300), (255, 255, 255), "topleft") 47 | SinWaveText = TextUI("SinWave :", (Width-350, 340), (255, 255, 255), "topleft") 48 | CosWaveText = TextUI("CosineWave :", (Width-350, 380), (255, 255, 255), "topleft") 49 | TanGraphText = TextUI("Tan Graph :", (Width-350, 420), (255, 255, 255), "topleft") 50 | SecFunctionText = TextUI("Sec fn :", (Width-350, 460), (255, 255, 255), "topleft") 51 | CscFuncitonText = TextUI("Csc fn :", (Width-350, 500), (255, 255, 255), "topleft") 52 | WOffsetText = TextUI("Offset Waves :",(Width-350, 540), (255, 255, 255), "topleft") 53 | AngleText = TextUI("θ :", (Width-350, 580), (255, 255, 255), "topleft") 54 | LineText = TextUI("Radius Line :", (Width-350, 620), (255, 255, 255), "topleft") 55 | PressSpaceText = TextUI("Press 'P' To Pause ", (Width-200, 700), (135, 120, 205), "center") 56 | RadiusText = TextUI("Radius :", (Width-350, 750), (255, 255, 255), "topleft") 57 | SpeedText = TextUI("speed :", (Width-350, 800), (255, 255, 255), "topleft") 58 | 59 | 60 | #ValuesText 61 | radius_value = TextUI("radius: 0", (100, 130), (255, 255, 255), "topleft") 62 | Theta_value=TextUI("θ : 0", (100, 160), (255, 255, 255), "topleft") 63 | sin_value = TextUI("sinθ : 0", (100, 190), (255, 255, 255), "topleft") 64 | cos_value = TextUI("cosθ : 0", (100, 220), (255, 255, 255), "topleft") 65 | tan_value = TextUI("tanθ : 0", (100, 250), (255, 255, 255), "topleft") 66 | ctn_value = TextUI("cotanθ: 0", (100, 280), (255, 255, 255), "topleft") 67 | sec_value = TextUI("secθ : 0", (100, 310), (255, 255, 255), "topleft") 68 | csc_value = TextUI("cscθ : 0", (100, 340), (255, 255, 255), "topleft") 69 | 70 | DarkText = TextUI("Dark Theme :", (Width-350, 970), (255, 255, 255), "topleft") 71 | ValuesText = TextUI("Press 'S' to show values", (Width-200, 860), (135, 120, 205), "center") 72 | projectionText = TextUI("Projection :", (Width-350, 920), (255, 255, 255), "topleft") 73 | #toggles 74 | SinToggle = ToggleButton((Width-200, 100), 20, 20, showSin) 75 | CosToggle = ToggleButton((Width-200, 140), 20, 20, showCos) 76 | TanToggle = ToggleButton((Width-200, 180), 20, 20, showTan) 77 | CoToggle = ToggleButton((Width-200, 220), 20, 20, showCtan) 78 | SecToggle = ToggleButton((Width-200, 260), 20, 20, showSec) 79 | CscToggle = ToggleButton((Width-200, 300), 20, 20, showCsc) 80 | SinWaveToggle = ToggleButton((Width-200, 340), 20, 20, showXwave) 81 | CosWaveToggle = ToggleButton((Width-200, 380), 20, 20, showYwave) 82 | TanGraphToggle = ToggleButton((Width-200, 420), 20, 20, showTanGraph) 83 | SecFnToggle = ToggleButton((Width-200, 460), 20, 20, showSecFunction) 84 | CscFnToggle = ToggleButton((Width-200, 500), 20, 20, showCscFunction) 85 | 86 | OffsetToggle = ToggleButton((Width-200, 540), 20, 20, offsetWaves) 87 | AngleToggle = ToggleButton((Width-200, 580), 20, 20, showTheta) 88 | LineToggle = ToggleButton((Width-200, 620), 20, 20, showLine) 89 | DarkToggle = ToggleButton((Width-200, 970), 20, 20, Dark) 90 | ProjectionToggle = ToggleButton((Width-200, 920), 20, 20, projection) 91 | 92 | 93 | RadiusSlider = Slider(Width-250, 755, radius, 50, 600, 200, 10) 94 | speedSlider = Slider(Width-250, 805, speed, 50, 600, 200, 10, 5) 95 | -------------------------------------------------------------------------------- /ui.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from constants import * 3 | 4 | def translate(value, min1, max1, min2, max2): 5 | return min2 + (max2-min2)*((value-min1)/(max1-min1)) 6 | 7 | class Button: 8 | def __init__(self, text, position = (Width-230, 600) , w = 100, h= 50, border=10, color = (0, 0, 0), borderColor = (64, 123, 158)): 9 | self.text = text 10 | self.position = position 11 | self.w = w 12 | self.h = h 13 | self.border = border 14 | self.temp = color 15 | self.color = color 16 | self.borderColor = borderColor 17 | self.font = 'freesansbold.ttf' 18 | self.fontSize = 25 19 | self.textColor = (255, 255, 255) 20 | self.state = False 21 | self.action = None 22 | 23 | def HandleMouse(self, HoverColor = (100, 100, 100)): 24 | m = pygame.mouse.get_pos() 25 | self.state = False 26 | if m[0] >= self.position[0] and m[0] <= self.position[0] + self.w: 27 | if m[1] >= self.position[1] and m[1] <= self.position[1] + self.h: 28 | self.color = HoverColor 29 | if pygame.mouse.get_pressed()[0]: 30 | self.color = (200, 200, 200) 31 | if self.action == None: 32 | self.state = True 33 | else: 34 | self.color = self.temp 35 | else: 36 | self.color = self.temp 37 | 38 | 39 | def Render(self, screen): 40 | self.HandleMouse() 41 | font = pygame.font.Font(self.font, self.fontSize) 42 | text = font.render(self.text, True, self.textColor) 43 | textRect = text.get_rect() 44 | textRect.center = (self.position[0]+self.w//2, self.position[1]+self.h//2) 45 | if self.border > 0: 46 | pygame.draw.rect(screen, self.borderColor, pygame.Rect(self.position[0] - self.border//2, self.position[1] - self.border//2, self.w + self.border, self.h + self.border)) 47 | pygame.draw.rect(screen, self.color, pygame.Rect(self.position[0], self.position[1], self.w, self.h)) 48 | 49 | screen.blit(text, textRect) 50 | 51 | class Panel: 52 | def __init__(self, position = (Width-350, 100), w= 345, h= 500, color=(8, 3, 12), alpha=128): 53 | self.position = position 54 | self.w = w 55 | self.h = h 56 | self.color = color 57 | self.alpha = alpha 58 | 59 | def Render(self, screen): 60 | s = pygame.Surface((self.w, self.h)) 61 | s.set_alpha(self.alpha) 62 | s.fill(self.color) 63 | screen.blit(s, (self.position[0], self.position[1])) 64 | #pygame.draw.rect(screen, self.color, pygame.Rect(self.position[0], self.position[1], self.w, self.h)) 65 | 66 | class ToggleButton: 67 | def __init__(self, position= ((Width-200, 400)), w = 30, h=30, state=False, color=(40, 40, 10), activeColor=(240, 140, 60)): 68 | self.position = position 69 | self.w = w 70 | self.h = h 71 | self.clicked = False 72 | self.state = state 73 | self.temp = (activeColor, color) 74 | self.activeColor = activeColor 75 | self.color = color 76 | 77 | def HandleMouse(self, HoverColor = (150, 120, 40)): 78 | m = pygame.mouse.get_pos() 79 | 80 | if m[0] >= self.position[0] and m[0] <= self.position[0] + self.w: 81 | if m[1] >= self.position[1] and m[1] <= self.position[1] + self.h: 82 | self.color = HoverColor 83 | self.activeColor = HoverColor 84 | if self.clicked: 85 | self.state = not self.state 86 | self.color = (255, 255, 255) 87 | else: 88 | self.color = self.temp[1] 89 | self.activeColor =self.temp[0] 90 | else: 91 | self.color = self.temp[1] 92 | self.activeColor =self.temp[0] 93 | 94 | def Render(self, screen, clicked): 95 | self.HandleMouse() 96 | self.clicked = clicked 97 | if self.state == True: 98 | pygame.draw.rect(screen, self.activeColor, pygame.Rect(self.position[0], self.position[1], self.w, self.h)) 99 | else: 100 | pygame.draw.rect(screen, self.color, pygame.Rect(self.position[0], self.position[1], self.w, self.h)) 101 | return self.state 102 | 103 | class TextUI: 104 | def __init__(self,text, position, fontColor, anchor='center'): 105 | self.position = position 106 | self.text = text 107 | self.font = 'freesansbold.ttf' 108 | self.anchor = anchor 109 | self.fontSize = 18 110 | self.fontColor = fontColor 111 | def Render(self, screen): 112 | font = pygame.font.Font(self.font, self.fontSize) 113 | text = font.render(self.text, True, self.fontColor) 114 | textRect = text.get_rect() 115 | setattr(textRect, self.anchor, self.position) 116 | #textRect.center = (self.position[0], self.position[1]) 117 | screen.blit(text, textRect) 118 | 119 | class DigitInput: 120 | def __init__(self,startingValue, position = (Width-320, 100), w= 300, h= 600, color=(8, 3, 12)): 121 | self.position = position 122 | self.text = str(startingValue) 123 | self.fontColor = (255, 255, 255) 124 | self.fontSize = 18 125 | self.font = 'freesansbold.ttf' 126 | self.w = w 127 | self.h = h 128 | self.color = color 129 | self.value = int(self.text) 130 | self.hoverEnter = False 131 | 132 | def Check(self, backspace,val): 133 | 134 | if self.hoverEnter == True: 135 | if backspace == True: 136 | 137 | if len(str(self.value)) <= 0 or len(str(self.value))-1 <= 0: 138 | self.value = 0 139 | else: 140 | self.value = int(str(self.value)[:-1]) 141 | 142 | else: 143 | if self.text.isdigit(): 144 | self.value = int(str(self.value) + str(self.text)) 145 | else: 146 | for el in self.text: 147 | if el.isdigit() != True: 148 | self.text = self.text.replace(el, "") 149 | backspace == False 150 | self.text = "" 151 | 152 | 153 | 154 | 155 | def updateText(self, val, pressed): 156 | m = pygame.mouse.get_pos() 157 | if m[0] >= self.position[0] and m[0] <= self.position[0] + self.w: 158 | if m[1] >= self.position[1] and m[1] <= self.position[1] + self.h: 159 | self.hoverEnter = True 160 | if pressed == True: 161 | self.text += val 162 | else: 163 | self.hoverEnter = False 164 | val = "" 165 | else: 166 | self.hoverEnter = False 167 | val = "" 168 | 169 | 170 | def Render(self, screen, val, backspace, pressed): 171 | self.updateText(val, pressed) 172 | self.Check(backspace, val) 173 | font = pygame.font.Font(self.font, self.fontSize) 174 | text = font.render(str(self.value), True, self.fontColor) 175 | textRect = text.get_rect() 176 | textRect.center = (self.position[0]+self.w//2, self.position[1]+self.h//2) 177 | pygame.draw.rect(screen, self.color, pygame.Rect(self.position[0], self.position[1], self.w, self.h)) 178 | screen.blit(text, textRect) 179 | 180 | class Slider: 181 | def __init__(self,x, y, val, min1, max1, length, h, max=500): 182 | self.value = val 183 | self.x = x 184 | self.y = y 185 | self.h = h 186 | self.min1 = min1 187 | self.max1 = max1 188 | self.length = length 189 | self.lineColor = (20, 10, 20) 190 | self.rectradius = 10 191 | self.temp_radius = self.rectradius 192 | self.rectColor = (255, 255, 255) 193 | self.v = 0.4 194 | self.temp = self.lineColor 195 | self.max = max 196 | 197 | def Calculate(self, val): 198 | self.v = translate(val, 0, self.length, 0, 1) 199 | self.value = self.v * self.max 200 | 201 | def HandleMouse(self): 202 | mx, my = pygame.mouse.get_pos() 203 | 204 | if mx >= self.x and mx <= self.x + self.length: 205 | if my >= self.y and my <= self.y + self.h: 206 | self.rectradius = 15 207 | if pygame.mouse.get_pressed()[0]: 208 | self.Calculate(mx - self.x) 209 | else: 210 | self.lineColor = self.temp 211 | self.rectradius = self.temp_radius 212 | else: 213 | self.lineColor = self.temp 214 | self.rectradius = self.temp_radius 215 | 216 | def Render(self,screen): 217 | self.HandleMouse() 218 | pygame.draw.rect(screen, self.lineColor, pygame.Rect(self.x, self.y, self.length, self.h)) 219 | x = int((self.v * self.length) + self.x) 220 | pygame.draw.rect(screen, self.rectColor, pygame.Rect(self.x, self.y, int( self.v * self.length), self.h)) 221 | pygame.draw.circle(screen, (130, 213, 151), (x, self.y + (self.rectradius//2)), self.rectradius) 222 | return self.value 223 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # Subscribe to my youtube 2 | # Youtube Channel: http://www.youtube.com/c/Auctux?sub_confirmation=1 3 | import sys 4 | import pygame 5 | from math import cos, sin, tan, pi 6 | from constants import * 7 | from line import Line 8 | from parameters import * 9 | import colorsys 10 | from event import HandleEvent 11 | 12 | pygame.init() 13 | screen = pygame.display.set_mode(size) 14 | clock = pygame.time.Clock() 15 | fps = 60 16 | 17 | position = (Width//2, Height//2) 18 | yAxis = Line( [position[0], 0], [position[0], Height], YaxisColor, 1) 19 | xAxis = Line( [0, position[1]], [Width, position[1]], XaxisColor, 1) 20 | 21 | Xwave = [] # sin wave 22 | Ywave = [] # cos wave 23 | TanGraph= [] 24 | SecWave = [] 25 | CscWave = [] 26 | 27 | previousRadius = radius 28 | previousSpeed = radius 29 | # theta in degrees 30 | angle = 0.0001 31 | 32 | def toRadian(degree): 33 | return degree * pi / 180 34 | 35 | def hsv_to_rgb(h, s, v): 36 | return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h, s, v)) 37 | 38 | clicked = False 39 | run = True 40 | while run: 41 | clock.tick(fps) 42 | dt = clock.tick(fps)/100 43 | frameRate = clock.get_fps() 44 | pygame.display.set_caption(str(frameRate) + " fps") 45 | 46 | #handle events 47 | run, clicked, pause, showUI, showValues = HandleEvent(clicked, pause, showUI, showValues) 48 | 49 | #theme 50 | backgroundColor = (4, 4, 8) if Dark == True else (255, 255, 255) 51 | circleColor = (255, 255, 255) if Dark == True else (0, 0, 0) 52 | PointColor = (255, 255, 255) if Dark == True else (0, 0, 0) 53 | lineColor = (255, 255, 255) if Dark == True else (0, 0, 0) 54 | panel.alpha = 80 if Dark == True else 200 55 | valueColor = (255, 255, 255) if Dark == True else (0, 0, 0) 56 | screen.fill(backgroundColor) 57 | 58 | if previousRadius != radius or previousSpeed != speed: 59 | Xwave.clear() 60 | Ywave.clear() 61 | TanGraph.clear() 62 | SecWave.clear() 63 | CscWave.clear() 64 | 65 | # draw x and y axis 66 | if showAxis: 67 | yAxis.Show(screen) 68 | xAxis.Show(screen) 69 | # draw main circle 70 | pygame.draw.circle(screen, circleColor, position, radius, circleStroke) 71 | 72 | # calculate 73 | theta = toRadian(angle) 74 | x = radius * cos(theta) # using the polar coordinates 75 | y = radius * -sin(theta) 76 | 77 | pointPos = [int(x) + position[0], int(y) + position[1]] # center the x and y pos 78 | 79 | secante = radius/cos(theta) 80 | cosecante = radius/sin(theta) 81 | tan_val = radius * (sin(theta)/cos(theta)) 82 | cotan_val = radius * (cos(theta)/sin(theta)) 83 | 84 | sinLine = Line( pointPos, [pointPos[0], position[1]], SinColor, 3, "sinθ", "Right") 85 | cosLine = Line( pointPos, [position[0], pointPos[1]], CosColor, 3, "cosθ", "Top") 86 | tanLine = Line( pointPos, [position[0] + secante , position[1]], TanColor, 3, "tanθ", "Top") 87 | ctanLine = Line( pointPos, [position[0], + position[1]-cosecante], CtanColor, 3, "cotanθ", "Top") 88 | SecLine = Line( position, [position[0] + secante , position[1]], SecColor, 3, "secθ", "Bottom") 89 | CscLine = Line( position, [position[0] , position[1] - cosecante], CscColor, 3, "cscθ", "Left") 90 | 91 | if pause==False: 92 | Xwave.insert(0, pointPos[1]) 93 | Ywave.insert(0, pointPos[0]) 94 | TanGraph.insert(0, tan_val) 95 | SecWave.insert(0, secante) 96 | CscWave.insert(0, cosecante*-1) 97 | 98 | if len(Xwave) > limit: 99 | Xwave.pop() 100 | Ywave.pop() 101 | TanGraph.pop() 102 | SecWave.pop() 103 | CscWave.pop() 104 | 105 | #draw waves 106 | if offsetWaves == False: 107 | waveOffset = 0 108 | 109 | else: 110 | waveOffset = radius 111 | previousTan = 0 112 | previousSec = 0 113 | previousCsc = 0 114 | 115 | for i in range(len(Xwave)): 116 | 117 | if showXwave: 118 | if i > 0: 119 | pygame.draw.line(screen, XwaveColor, (i+ position[0]+waveOffset, Xwave[i]),(i+ position[0]+waveOffset, Xwave[i-1]), strokeGraph) 120 | if projection: 121 | pygame.draw.line(screen, XwaveColor, (position[0] - i -waveOffset, Xwave[i]),(position[0]-i-waveOffset, Xwave[i-1]), strokeGraph) 122 | 123 | if showYwave: 124 | if i > 0: 125 | pygame.draw.line(screen, YwaveColor, (Ywave[i], position[1] + waveOffset + i),(Ywave[i-1], position[1] + waveOffset + i), strokeGraph) 126 | if projection: 127 | pygame.draw.line(screen, YwaveColor, (Ywave[i], position[1] - waveOffset - i),(Ywave[i-1], position[1] - waveOffset - i), strokeGraph) 128 | 129 | if showTanGraph: 130 | if i>0 and previousTan > -1000 and previousTan < 1000: 131 | pygame.draw.line(screen, TanGraphColor, (position[0]+i+waveOffset, TanGraph[i-1]+position[1]), (position[0]+i+waveOffset, TanGraph[i]+position[1]) ,strokeGraph) 132 | 133 | previousTan = TanGraph[i] 134 | 135 | if showSecFunction: 136 | if i>0 and previousSec > -1000 and previousSec < 1000: 137 | pygame.draw.line(screen, SecFunctionColor, (SecWave[i]+position[0], position[1]+i+waveOffset),(SecWave[i-1]+position[0], position[1]+i+waveOffset), strokeGraph) 138 | previousSec=SecWave[i] 139 | 140 | if showCscFunction: 141 | if i>0 and previousCsc > -1000 and previousCsc < 1000: 142 | pygame.draw.line(screen, CscFunctionColor, (position[0]+i+waveOffset, CscWave[i]+position[1]),(position[0]+i+waveOffset, CscWave[i-1]+position[1]), strokeGraph) 143 | 144 | previousCsc=CscWave[i] 145 | 146 | #--lines--- 147 | if showCos: 148 | cosLine.Show(screen) 149 | if showSin: 150 | sinLine.Show(screen) 151 | if showTan: 152 | tanLine.Show(screen) 153 | if showCtan: 154 | ctanLine.Show(screen) 155 | if showSec: 156 | SecLine.Show(screen) 157 | if showCsc: 158 | CscLine.Show(screen) 159 | if showTheta: 160 | offset = angleArc//2 161 | 162 | font = pygame.font.Font('freesansbold.ttf', 16) 163 | text = font.render(str(round(angle, 2)) + " °", True, circleColor) 164 | textRect = text.get_rect() 165 | p = (position[0]-offset, position[1]-offset) 166 | textRect.center = (position[0]+offset, position[1]-offset) 167 | pygame.draw.arc(screen, OriginColor, [p[0], p[1], angleArc, angleArc], 2*pi, theta, 2) 168 | screen.blit(text, textRect) 169 | 170 | #draw line from the origin to the point 171 | if showLine: 172 | pygame.draw.line(screen, lineColor, position, pointPos, 4 ) 173 | #draw origin: 174 | if showOrigin: 175 | pygame.draw.circle(screen, OriginColor, position, 5) 176 | #draw moving point 177 | if showPoint: 178 | PointColor = hsv_to_rgb(angle/140, 1, 1) 179 | pygame.draw.circle(screen, PointColor, pointPos, 10) 180 | 181 | previousRadius = radius 182 | previousSpeed = speed 183 | 184 | # -- draw ui --- 185 | if showUI: 186 | panel.Render(screen) 187 | CosText.Render(screen) 188 | SinText.Render(screen) 189 | TanText.Render(screen) 190 | CoText.Render(screen) 191 | SecText.Render(screen) 192 | CosecText.Render(screen) 193 | SinWaveText.Render(screen) 194 | CosWaveText.Render(screen) 195 | TanGraphText.Render(screen) 196 | SecFunctionText.Render(screen) 197 | CscFuncitonText.Render(screen) 198 | WOffsetText.Render(screen) 199 | AngleText.Render(screen) 200 | PressSpaceText.Render(screen) 201 | LineText.Render(screen) 202 | RadiusText.Render(screen) 203 | SpeedText.Render(screen) 204 | DarkText.Render(screen) 205 | ValuesText.Render(screen) 206 | projectionText.Render(screen) 207 | #toggle buttons 208 | showSin= SinToggle.Render(screen, clicked) 209 | showCos = CosToggle.Render(screen, clicked) 210 | showTan = TanToggle.Render(screen, clicked) 211 | showCtan = CoToggle.Render(screen, clicked) 212 | showSec = SecToggle.Render(screen, clicked) 213 | showCsc = CscToggle.Render(screen, clicked) 214 | showXwave = SinWaveToggle.Render(screen, clicked) 215 | showYwave = CosWaveToggle.Render(screen, clicked) 216 | offsetWaves = OffsetToggle.Render(screen, clicked) 217 | showTanGraph = TanGraphToggle.Render(screen, clicked) 218 | showSecFunction = SecFnToggle.Render(screen, clicked) 219 | showCscFunction = CscFnToggle.Render(screen, clicked) 220 | showTheta = AngleToggle.Render(screen, clicked) 221 | showLine = LineToggle.Render(screen, clicked) 222 | Dark = DarkToggle.Render(screen, clicked) 223 | projection = ProjectionToggle.Render(screen, clicked) 224 | #slider buttons 225 | radius = RadiusSlider.Render(screen) 226 | speed = speedSlider.Render(screen) 227 | 228 | else: 229 | UItoggle.Render(screen) 230 | 231 | if showValues: 232 | radius_value.text = "radius: " + str(radius) 233 | radius_value.Render(screen) 234 | radius_value.fontColor = valueColor 235 | 236 | Theta_value.text = "θ : " + str(round(angle,2)) + "°" 237 | Theta_value.Render(screen) 238 | Theta_value.fontColor = valueColor 239 | 240 | sin_value.text = "sinθ : " + str(round(y, 2)) 241 | sin_value.Render(screen) 242 | sin_value.fontColor = valueColor 243 | 244 | cos_value.text = "cosθ : " + str(round(x, 2)) 245 | cos_value.Render(screen) 246 | cos_value.fontColor = valueColor 247 | 248 | tan_value.text = "tanθ : " + str(round(tan_val, 2)) 249 | tan_value.Render(screen) 250 | tan_value.fontColor = valueColor 251 | 252 | ctn_value.text = "cotanθ: " + str(round(cotan_val, 2)) 253 | ctn_value.Render(screen) 254 | ctn_value.fontColor = valueColor 255 | 256 | sec_value.text = "secθ : " + str(round(secante, 2)) 257 | sec_value.Render(screen) 258 | sec_value.fontColor = valueColor 259 | 260 | csc_value.text = "cscθ : " + str(round(cosecante, 2)) 261 | csc_value.Render(screen) 262 | csc_value.fontColor = valueColor 263 | pygame.display.flip() 264 | 265 | if pause==False: 266 | angle += speed 267 | if angle >= 360: 268 | angle = 0.0001 269 | #UItoggle.fontSize = int( sin(angle/3) +24) 270 | clicked = False 271 | pygame.quit() 272 | sys.exit() 273 | --------------------------------------------------------------------------------