-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartA.py
124 lines (99 loc) · 2.9 KB
/
partA.py
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
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import pygame
import math
import time
# My Modules
import settings
import ASDrawing
import ASUI
import ASMath
import ASWindow
# Set initial Screen
def refresh2d(width, height):
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, width, 0.0, height, 0.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def setBackground(hexString):
rgb = ASDrawing.getRgbTuple(hexString)
glClearColor(rgb[0], rgb[1], rgb[2], 0.0)
# Interface
def addControlPoint(x,y):
settings.points.append([x, y])
def getCurvePoint(t, drawLine):
pointsCopy = settings.points
resultArray = pointsCopy
while len(resultArray) > 1:
resultArray = calculateNextLevel(resultArray, t, drawLine)
return resultArray[0]
def draw():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
ASDrawing.drawControlPoints(settings.points)
ASDrawing.drawControlPolygon(settings.points)
ASDrawing.drawBernsteinBezierCurve(settings.points)
ASDrawing.drawElevatedOrReducedCurve(settings.points, settings.degreeOffset)
glutSwapBuffers()
# Point Array Manipulation Functions
def getClosestPointIndex(x, y, points):
minDistance = 8
closestPointIndex = None
if len(points) >= 1:
for i in range(0, len(points)):
if ASMath.distancePoints(x, y, points[i][0], points[i][1]) < minDistance:
closestPointIndex = i
minDistance = ASMath.distancePoints(x, y, points[i][0], points[i][1])
return closestPointIndex
# Mouse Functions
lastMouseDown = None
currentDraggedPoint = None
selectedPointIndex = None
def on_keyboard(key, x, y):
if key == "+" or key == "=":
settings.degreeOffset += 1
print "up"
elif key == "-":
settings.degreeOffset -= 1
print "down"
draw()
def on_click(button, state, x, y):
mouseX = x
mouseY = settings.height - y
global selectedPointIndex
selectedPointIndex = getClosestPointIndex(mouseX, mouseY, settings.points)
if button == GLUT_LEFT_BUTTON and state == GLUT_DOWN:
if selectedPointIndex == None:
addControlPoint(mouseX, mouseY)
selectedPointIndex = len(settings.points) - 1
draw()
if button == GLUT_RIGHT_BUTTON:
if selectedPointIndex != None:
settings.points.pop(selectedPointIndex)
draw()
def on_drag(x, y):
mouseX = x
mouseY = settings.height - y
global selectedPointIndex
if len(settings.points) > 0:
settings.points[selectedPointIndex] = [mouseX, mouseY]
draw()
def main():
settings.init()
glutInit()
ASWindow.setupWindow()
glutMouseFunc(on_click)
glutMotionFunc(on_drag)
glutKeyboardFunc(on_keyboard)
glutDisplayFunc(draw)
# glutIdleFunc(draw)
app = QApplication(sys.argv)
ex = ASUI.sliderdemo()
ex.show()
glutMainLoop()
if __name__ == "__main__": main()