This commit is contained in:
Michael Mikovsky
2024-03-13 14:59:45 -07:00
parent e538a8c382
commit 2dab7295ac
4 changed files with 105 additions and 33 deletions
+27 -1
View File
@@ -1 +1,27 @@
# class menu:
pg = None
render = None
class menu:
name = "Menu"
def __init__(self, tmppg, tmprender):
global pg
pg = tmppg
global render
render = tmprender
def mouseDown(self, pos):
pass
def mouseUp(self, pos):
pass
def mouseMove(self, pos):
pass
def doubleClick(self, pos):
pass
def load(self):
render.clear()
pg.display.update()
+32 -15
View File
@@ -4,9 +4,13 @@ from pygame.locals import *
nodeColor = (255, 255, 255)
nodeRadius = 15
rotNodeDist = 30
rotNodeDist = 35
rotNodeColor = (255, 0, 255)
rotNodeRadius = 5
rotNodeRadius = 10
nodeSquareRadius = 35
nodeSquareColor = (127, 127, 127, 0.5)
nodeSquareWidth = 3
lineApproximationLineColor = (127, 127, 127, 0.5)
lineApproximationLineWidth = 3
@@ -14,8 +18,6 @@ lineApproximationLineWidth = 3
curveEditPointColor = (0, 255, 255)
curveEditPointRadius = 5
name = "Path Editor"
nodes = []
curveEditPoints = []
nodeRotations = []
@@ -24,23 +26,38 @@ clickType = -1
clickIndex = -1
pg = None
pathRenderer = None
render = None
def refresh():
pathRenderer.render(nodes, curveEditPoints)
render.render(nodes, curveEditPoints)
for i in range(0,len(curveEditPoints)):
pathRenderer.line(lineApproximationLineColor, nodes[i], curveEditPoints[i], lineApproximationLineWidth)
pathRenderer.line(lineApproximationLineColor, curveEditPoints[i], nodes[i+1], lineApproximationLineWidth)
render.line(lineApproximationLineColor, nodes[i], curveEditPoints[i], lineApproximationLineWidth)
render.line(lineApproximationLineColor, curveEditPoints[i], nodes[i+1], lineApproximationLineWidth)
#bezier(nodes[i], curveEditPoints[i], nodes[i+1])
pathRenderer.circle(curveEditPointColor, curveEditPoints[i], curveEditPointRadius)
render.circle(curveEditPointColor, curveEditPoints[i], curveEditPointRadius)
for i in range(0,len(nodeRotations)):
posX = (math.sin(nodeRotations[i])*rotNodeDist) + nodes[i][0]
posY = (math.cos(nodeRotations[i])*rotNodeDist) + nodes[i][1]
pathRenderer.circle(rotNodeColor, (posX, posY), rotNodeRadius)
render.circle(rotNodeColor, (posX, posY), rotNodeRadius)
rect1 = ((math.sin(nodeRotations[i] + math.pi*-0.25)*nodeSquareRadius) + nodes[i][0],
(math.cos(nodeRotations[i] + math.pi*-0.25)*nodeSquareRadius) + nodes[i][1])
rect2 = ((math.sin(nodeRotations[i] + math.pi*0.25)*nodeSquareRadius) + nodes[i][0],
(math.cos(nodeRotations[i] + math.pi*0.25)*nodeSquareRadius) + nodes[i][1])
rect3 = ((math.sin(nodeRotations[i] + math.pi*0.75)*nodeSquareRadius) + nodes[i][0],
(math.cos(nodeRotations[i] + math.pi*0.75)*nodeSquareRadius) + nodes[i][1])
rect4 = ((math.sin(nodeRotations[i] + math.pi*1.25)*nodeSquareRadius) + nodes[i][0],
(math.cos(nodeRotations[i] + math.pi*1.25)*nodeSquareRadius) + nodes[i][1])
render.line(nodeSquareColor, rect1, rect2, nodeSquareWidth)
render.line(nodeSquareColor, rect2, rect3, nodeSquareWidth)
render.line(nodeSquareColor, rect3, rect4, nodeSquareWidth)
render.line(nodeSquareColor, rect4, rect1, nodeSquareWidth)
for pos in nodes:
pathRenderer.circle(nodeColor, pos, nodeRadius)
render.circle(nodeColor, pos, nodeRadius)
pg.display.update()
def getElemAt(pos):
@@ -84,14 +101,14 @@ def points2rad(center, pos):
return -math.atan2(diffY, diffX) - (math.pi/2)
class pathEditor:
def __init__(self, tmppg, tmppathRenderer):
name = "Path Editor"
def __init__(self, tmppg, tmprender):
global pg
pg = tmppg
# global screen
# screen = tmpscreen
global pathRenderer
pathRenderer = tmppathRenderer
global render
render = tmprender
refresh()
+9 -6
View File
@@ -6,7 +6,7 @@ curvePointCount = 300
curvePointColor = (255, 255, 0)
curvePointRadius = 2
class pathRenderer():
class render():
def __init__(self, pg, screen, offsetY):
self.pg = pg
self.screen = screen
@@ -35,14 +35,17 @@ class pathRenderer():
px = p0[0]*(1-t)**2 + 2*(1-t)*t*p1[0] + p2[0]*t**2
py = p0[1]*(1-t)**2 + 2*(1-t)*t*p1[1] + p2[1]*t**2
self.circle(curvePointColor, (px, py), curvePointRadius)
def clear(self):
self.pg.draw.rect(self.screen, (0, 0, 0), self.rect)
def render(self, nodes, curveEditPoints):
self.pg.draw.rect(self.screen, (0, 0, 0), self.rect)
self.screen.blit(self.fieldImg, self.rect)
for i in range(0,len(curveEditPoints)):
# self.pg.draw.line(self.screen, lineApproximationLineColor, nodes[i], curveEditPoints[i], lineApproximationLineWidth)
# self.pg.draw.line(self.screen, lineApproximationLineColor, curveEditPoints[i], nodes[i+1], lineApproximationLineWidth)
self.bezier(nodes[i], curveEditPoints[i], nodes[i+1])
# self.pg.draw.circle(self.screen, curveEditPointColor, curveEditPoints[i], curveEditPointRadius)
# self.pg.draw.line(self.screen, lineApproximationLineColor, nodes[i], curveEditPoints[i], lineApproximationLineWidth)
# self.pg.draw.line(self.screen, lineApproximationLineColor, curveEditPoints[i], nodes[i+1], lineApproximationLineWidth)
self.bezier(nodes[i], curveEditPoints[i], nodes[i+1])
# self.pg.draw.circle(self.screen, curveEditPointColor, curveEditPoints[i], curveEditPointRadius)
self.pg.display.update()