Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import math
- pygame.init()
- displaySize = (400, 400)
- gameDisplay = pygame.display.set_mode(displaySize)
- pygame.display.set_caption('Triangler')
- clock = pygame.time.Clock()
- background = pygame.Surface(gameDisplay.get_size())
- background.fill((0, 0, 0))
- white = (255, 255, 255)
- font = pygame.font.SysFont('AmericanTypewriter', 15)
- pointCoords = ((int(displaySize[0]/2)), int((displaySize[1]/2)))
- def mathDistance():
- global pointCoords
- # Math
- lineCoords = (mouseCoords[0], pointCoords[1])
- # triangle data
- aLen = math.fabs(200 - mouseCoords[0])
- bLen = math.fabs(200 - mouseCoords[1])
- cLen = round(math.sqrt((bLen ** 2) + (aLen ** 2)), 2)
- peri = round(aLen + bLen + cLen, 2)
- area = (aLen * bLen) / 2
- cLenInt = int(cLen)
- # circle data
- radi = cLen
- diameter = radi * 2
- circ = round(2 * (math.pi * radi), 2)
- circArea = round(math.pi * (radi ** 2), 2)
- # Perameters of location math
- if mouseCoords[1] > 200:
- lineHorzText = (((lineCoords[0] + 200) / 2), pointCoords[1] - 10)
- else:
- lineHorzText = (((lineCoords[0] + 200) / 2), pointCoords[1])
- if mouseCoords[0] > 200:
- lineVertText = (lineCoords[0] + 5, (mouseCoords[1] + 200) / 2)
- else:
- lineVertText = (lineCoords[0] - 10, (mouseCoords[1] + 200) / 2)
- if mouseCoords[0] > 200:
- lineCText = (lineHorzText[0] - 10, lineVertText[1] - 10)
- if mouseCoords[1] > 200:
- lineCText = (lineHorzText[0] -4, lineVertText[1] + 6.5)
- else:
- lineCText = (lineHorzText[0] + 10, lineVertText[1] - 10)
- if mouseCoords[1] > 200:
- lineCText = (lineHorzText[0] + 4, lineVertText[1] + 6.5)
- # Renders - Text
- gameDisplay.blit(background, (0, 0))
- aTri = font.render('a', True, white)
- gameDisplay.blit(aTri, lineHorzText)
- bTri = font.render('b', True, white)
- gameDisplay.blit(bTri, lineVertText)
- cTri = font.render('c', True, white)
- gameDisplay.blit(cTri, lineCText)
- # a, b, c text
- aLenTxt = font.render('a = ' + str(aLen) + "px", True, white)
- gameDisplay.blit(aLenTxt, (5,20))
- bLenTxt = font.render('b = ' + str(bLen) + "px", True, white)
- gameDisplay.blit(bLenTxt, (72,20))
- cLenTxt = font.render('c = ' + str(cLen) + "px", True, white)
- gameDisplay.blit(cLenTxt, (139,20))
- # triangle data
- triText = font.render('TRIANGLE ', True, white)
- gameDisplay.blit(triText, (70, 7))
- peri = font.render('P = ' + str(peri) + "px", True, white)
- gameDisplay.blit(peri, (5,35))
- area = font.render('A = ' + str(area) + "px", True, white)
- gameDisplay.blit(area, (80,35))
- # circles
- circleText = font.render('CIRCLE', True, white)
- gameDisplay.blit(circleText, (305, 7))
- radi = font.render('r = ' + str(radi) + "px", True, white)
- gameDisplay.blit(radi, (260,20))
- diameter = font.render('d = ' + str(diameter) + "px", True, white)
- gameDisplay.blit(diameter, (330,20))
- circ = font.render('circ = ' + str(circ) + 'px', True, white)
- gameDisplay.blit(circ, (230,35))
- circArea = font.render('A = ' + str(circArea) + 'px', True, white)
- gameDisplay.blit(circArea, (315,35))
- # name
- name = font.render('Code and design by Elison Crum', True, white)
- gameDisplay.blit(name, (0,390))
- # Renders Lines
- pygame.draw.line(gameDisplay, white, pointCoords , lineCoords)
- pygame.draw.line(gameDisplay, white, lineCoords, (lineCoords[0], mouseCoords[1]))
- pygame.draw.line(gameDisplay, white, pointCoords, mouseCoords)
- pygame.draw.circle(gameDisplay, (169, 169, 169), (200, 200), cLenInt + 1, 1)
- pygame.draw.circle(gameDisplay, (34,206,255), (pointCoords), 2, 1)
- boxX = aLen * .2
- boxY = bLen * .2
- if mouseCoords[1] < 200:
- boxY = -boxY
- if mouseCoords[0] > 200:
- boxX = -boxX
- pygame.draw.rect(gameDisplay, white, [lineCoords[0], lineCoords[1], boxX, boxY], 1)
- end = False
- while not end:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- end = True
- elif pygame.mouse.get_focused() == 1:
- mouseCoords = pygame.mouse.get_pos()
- mathDistance()
- pygame.display.update()
- clock.tick(30)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement