def find_normal_lines(self, points, radius, current_pass): working_line = [] i = 0 for point in points: if point == points[0] or point == points[-1]: # start and end points self.scene.debug_batch.add(2, GL_LINES, self.scene.ordered_group4, ('v2f', (point[0],point[1],point[0],point[1]-radius)), ('c3B', (55,255,85)*2)) working_line.append((point[0],point[1]-radius)) else: angle1 = math.radians(utils.angle_between_points(point, points[i-1])+90) angle2 = math.radians(utils.angle_between_points(point, points[i+1])+90) delta = angle1-angle2-math.radians(180) # disable this and see what happens # yeah, i don't get it either... if delta < -3: delta += math.radians(360) new_step_point = utils.point_on_circle(radius, angle1-delta/2, point) working_line.append(new_step_point) # actual appending normal = (point[0], point[1], new_step_point[0], new_step_point[1]) self.scene.debug_batch.add(2, GL_LINES, self.scene.ordered_group4, ('v2f', normal), ('c3B', (25,255,55)*2)) self.scene.debug_batch.add(1, GL_POINTS, self.scene.ordered_group4, ('v2f', (new_step_point[0],new_step_point[1])), ('c3B', (95,95,255))) self.scene.debug_batch.add(1, GL_POINTS, self.scene.ordered_group4, ('v2f', (point[0],point[1])), ('c3B', (255,255,255))) i += 1 l = [] for point in working_line: l.append(point[0]) l.append(point[1]) ''' #self.scene.debug_batch.add_indexed(len(l)/2, GL_LINES, self.scene.ordered_group5, # pyglet_util.calc_line_index(len(l)/2), # ('v2f', l), # ('c3B', (25,255,255)*(len(l)/2))) ''' print working_line return working_line
def find_normals(point_dict, scene, radius=120): new_dict = {} points = point_dict.values() for i, point in enumerate(points): if point == points[0] or point == points[-1]: # start and end points scene.debug_batch.add(2, GL_LINES, scene.ordered_group4, ('v2f', (point[0],point[1],point[0],point[1]-radius)), ('c3B', (55,255,85)*2)) new_dict[i] = point[0], point[1]-radius else: angle1 = math.radians(utils.angle_between_points(point, points[i-1])+90) angle2 = math.radians(utils.angle_between_points(point, points[i+1])+90) delta = angle1-angle2-math.radians(180) # disable this and see what happens # yeah, i don't get it either... if delta < -3: delta += math.radians(360) normal_point = utils.point_on_circle(radius, angle1-delta/2, point) if normal_point[0] > points[0][0]: new_dict[i] = normal_point normal = (point[0], point[1], normal_point[0], normal_point[1]) scene.debug_batch.add(2, GL_LINES, scene.ordered_group4, ('v2f', normal), ('c3B', (25,255,55)*2)) scene.debug_batch.add(1, GL_POINTS, scene.ordered_group4, ('v2f', (normal_point[0],normal_point[1])), ('c3B', (95,95,255))) scene.debug_batch.add(1, GL_POINTS, scene.ordered_group4, ('v2f', (point[0],point[1])), ('c3B', (255,255,255))) return new_dict
def setup(self): for segment in self.segments: length = utils.distance(segment.a, segment.b) angle = utils.angle_between_points(segment.a, segment.b) verts = [Vec2d(-length/2, segment.radius), Vec2d(length/2, segment.radius), Vec2d(length/2, -segment.radius), Vec2d(-length/2, -segment.radius)] cap_l = [Vec2d(-length/2, segment.radius), Vec2d(-length/2, -segment.radius), Vec2d((-length/2)-segment.radius, 0),] cap_r = [Vec2d(length/2, segment.radius), Vec2d(length/2, -segment.radius), Vec2d((length/2)+segment.radius, 0),] for vert in verts: vert.rotate_degrees(angle) vert += utils.midpoint(segment.a, segment.b) points = [] for vert in verts: points.append(vert[0]) points.append(vert[1]) res = len(points)//2 segment.pyglet_debug = self.scene.debug_batch.add_indexed(res, GL_TRIANGLES, self.scene.ordered_group1, calc_index_tri(res), ('v2f', points), ('c3B', self.seg_color*res)) # Segment end caps for vert in cap_l: vert.rotate_degrees(angle) vert += utils.midpoint(segment.a, segment.b) points = [] for vert in cap_l: points.append(vert[0]) points.append(vert[1]) segment.cap_l = self.scene.debug_batch.add_indexed(3, GL_TRIANGLES, self.scene.ordered_group1, calc_index_tri(3), ('v2f', points), ('c3B', self.seg_color*3)) for vert in cap_r: vert.rotate_degrees(angle) vert += utils.midpoint(segment.a, segment.b) points = [] for vert in cap_r: points.append(vert[0]) points.append(vert[1]) segment.cap_r = self.scene.debug_batch.add_indexed(3, GL_TRIANGLES, self.scene.ordered_group1, calc_index_tri(3), ('v2f', points), ('c3B', self.seg_color*3)) for circle in self.circles: if not hasattr(circle,'fill_color'): circle.fill_color = random.choice(self.rand_colors) circle.outline_color = (255,255,255) circle.line_color = (255,255,255) circle.sleep_color = self.sleep_color # divisible by 3! if circle.radius <= 150: circle.circle_res = 21 if circle.radius <= 100: circle.circle_res = 18 if circle.radius <= 50: circle.circle_res = 15 if circle.radius <= 25: circle.circle_res = 12 if circle.radius <= 10: circle.circle_res = 9 if circle.radius <= 5: circle.circle_res = 6 if circle.radius <= 2: circle.circle_res = 3 points = define_circle_points(circle.radius, circle.body.position, circle.circle_res) res = len(points)//2 circle.res = res circle.pyglet_outline = self.scene.debug_batch.add_indexed(res, GL_LINES, self.scene.ordered_group3, calc_index(res), ('v2f', points), ('c3B', (255,255,255)*res)) fill_points = points fill_points.insert(0, circle.body.position[0]) fill_points.insert(1, circle.body.position[1]) circle.pyglet_fill = self.scene.debug_batch.add_indexed(res+1, GL_TRIANGLES, self.scene.ordered_group4, calc_circle_index(res+1), ('v2f', fill_points), ('c4B', circle.fill_color*(res+1))) circle.rotation_line = self.scene.debug_batch.add_indexed(2, GL_LINES, self.scene.ordered_group5, [0,1,1,0], ('v2f', (0,0,0,0)), ('c3B', (255,255,255)*2)) for poly in self.polygons: if not hasattr(poly,'fill_color'): poly.fill_color = random.choice(self.rand_colors) poly.outline_color = (255,255,255,255) poly.sleep_fill_color = self.poly_sleep_fill poly.sleep_color = (255,255,255,255) poly.outline_color = (255,255,255,255) p = poly.get_points()#.get_vertices() points = [] for vert in p: points.append(vert[0]) points.append(vert[1]) res = len(points)//2 poly.res = res # fill and outline for polygons poly.pyglet_fill = self.scene.debug_batch.add_indexed(res, GL_TRIANGLES, self.scene.ordered_group2, calc_index_tri(res), ('v2f', points), ('c4B', (0,0,0,0)*res)) poly.pyglet_outline = self.scene.debug_batch.add_indexed(res, GL_LINES, self.scene.ordered_group1, calc_index(res), ('v2f', points), ('c4B', poly.outline_color*res))
def angles_between_points( stroke: Stroke) -> Iterable[utils.Rads]: # TODO Write a test for this return (utils.angle_between_points(p1, p2) for p1, p2 in point_pairs(stroke))
def setup(self): for segment in self.segments: length = utils.distance(segment.a, segment.b) angle = utils.angle_between_points(segment.a, segment.b) verts = [ Vec2d(-length / 2, segment.radius), Vec2d(length / 2, segment.radius), Vec2d(length / 2, -segment.radius), Vec2d(-length / 2, -segment.radius) ] cap_l = [ Vec2d(-length / 2, segment.radius), Vec2d(-length / 2, -segment.radius), Vec2d((-length / 2) - segment.radius, 0), ] cap_r = [ Vec2d(length / 2, segment.radius), Vec2d(length / 2, -segment.radius), Vec2d((length / 2) + segment.radius, 0), ] for vert in verts: vert.rotate_degrees(angle) vert += utils.midpoint(segment.a, segment.b) points = [] for vert in verts: points.append(vert[0]) points.append(vert[1]) res = len(points) // 2 segment.pyglet_debug = self.scene.debug_batch.add_indexed( res, GL_TRIANGLES, self.scene.ordered_group1, calc_index_tri(res), ('v2f', points), ('c3B', self.seg_color * res)) # Segment end caps for vert in cap_l: vert.rotate_degrees(angle) vert += utils.midpoint(segment.a, segment.b) points = [] for vert in cap_l: points.append(vert[0]) points.append(vert[1]) segment.cap_l = self.scene.debug_batch.add_indexed( 3, GL_TRIANGLES, self.scene.ordered_group1, calc_index_tri(3), ('v2f', points), ('c3B', self.seg_color * 3)) for vert in cap_r: vert.rotate_degrees(angle) vert += utils.midpoint(segment.a, segment.b) points = [] for vert in cap_r: points.append(vert[0]) points.append(vert[1]) segment.cap_r = self.scene.debug_batch.add_indexed( 3, GL_TRIANGLES, self.scene.ordered_group1, calc_index_tri(3), ('v2f', points), ('c3B', self.seg_color * 3)) for circle in self.circles: if not hasattr(circle, 'fill_color'): circle.fill_color = random.choice(self.rand_colors) circle.outline_color = (255, 255, 255) circle.line_color = (255, 255, 255) circle.sleep_color = self.sleep_color # divisible by 3! if circle.radius <= 150: circle.circle_res = 21 if circle.radius <= 100: circle.circle_res = 18 if circle.radius <= 50: circle.circle_res = 15 if circle.radius <= 25: circle.circle_res = 12 if circle.radius <= 10: circle.circle_res = 9 if circle.radius <= 5: circle.circle_res = 6 if circle.radius <= 2: circle.circle_res = 3 points = define_circle_points(circle.radius, circle.body.position, circle.circle_res) res = len(points) // 2 circle.res = res circle.pyglet_outline = self.scene.debug_batch.add_indexed( res, GL_LINES, self.scene.ordered_group3, calc_index(res), ('v2f', points), ('c3B', (255, 255, 255) * res)) fill_points = points fill_points.insert(0, circle.body.position[0]) fill_points.insert(1, circle.body.position[1]) circle.pyglet_fill = self.scene.debug_batch.add_indexed( res + 1, GL_TRIANGLES, self.scene.ordered_group4, calc_circle_index(res + 1), ('v2f', fill_points), ('c4B', circle.fill_color * (res + 1))) circle.rotation_line = self.scene.debug_batch.add_indexed( 2, GL_LINES, self.scene.ordered_group5, [0, 1, 1, 0], ('v2f', (0, 0, 0, 0)), ('c3B', (255, 255, 255) * 2)) for poly in self.polygons: if not hasattr(poly, 'fill_color'): poly.fill_color = random.choice(self.rand_colors) poly.outline_color = (255, 255, 255, 255) poly.sleep_fill_color = self.poly_sleep_fill poly.sleep_color = (255, 255, 255, 255) poly.outline_color = (255, 255, 255, 255) p = poly.get_points() #.get_vertices() points = [] for vert in p: points.append(vert[0]) points.append(vert[1]) res = len(points) // 2 poly.res = res # fill and outline for polygons poly.pyglet_fill = self.scene.debug_batch.add_indexed( res, GL_TRIANGLES, self.scene.ordered_group2, calc_index_tri(res), ('v2f', points), ('c4B', (0, 0, 0, 0) * res)) poly.pyglet_outline = self.scene.debug_batch.add_indexed( res, GL_LINES, self.scene.ordered_group1, calc_index(res), ('v2f', points), ('c4B', poly.outline_color * res))