def bezier3x_simplified(self, data, canvas, i): # points = [[beginning], [beginning_midifier], [end], [end_midifier]] # points = [[200, 400], [300, 250], [450, 500], [500, 475]] canvas_w = self.layout.game_w canvas_h = self._step * data[3] x_center = self.layout.game_w // 2 y_center = self._step * data[3] // 2 first = self.start_positions last = self.end_positions bezier = [[[0, 0] for j in range(4)] for j in range(3)] # points = ex.simplified_points(self.start_positions[i],self.end_positions[i],canvas_w,canvas_h,x_center,y_center,self._step) bezier[0][0] = Vector2(first[i]) bezier[0][1] = Vector2(random.randrange(first[i][0] - self._step * 2, first[i][0] + self._step * 2), random.randrange(self._step * 3, canvas_h)) # mod1 #first point modifier # p1 if first[i][0] < x_center: x_range = (first[i][0] + self._step, canvas_w - self._step) else: x_range = (self._step, first[i][0] - self._step) y_range = (self._step, y_center - self._step // 2) # line 1 end bezier[0][2] = Vector2(random.randrange(*x_range), random.randrange( *y_range)) # Vector2(random.randrange(self._step,canvas_w-self._step),random.randrange(self._step,canvas_h-self._step)) #first line end bezier[0][3] = Vector2(bezier[0][2][0], bezier[0][2][1] - self._step) # line 2 start bezier[1][0] = bezier[0][2] bezier[1][1] = Vector2(bezier[0][2][0], bezier[0][2][ 1] + self._step) # bezier[0][2] + Vector2(-(Vector2.from_points(bezier[0][2], bezier[0][3]))) #3rd point modifier # p2 if last[i][0] < x_center: x_range = (last[i][0] + self._step, canvas_w - self._step) p4_x_mod = last[i][0] - self._step else: x_range = (self._step, last[i][0] - self._step) p4_x_mod = last[i][0] + self._step y_range = (canvas_h - y_center, round(canvas_h - self._step * 0.5)) bezier[1][2] = Vector2(random.randrange(*x_range), random.randrange(*y_range)) # second line end bezier[1][3] = Vector2(bezier[1][2][0] + self._step, bezier[1][2][1] - self._step) # line 3 start bezier[2][0] = bezier[1][2] bezier[2][1] = Vector2(bezier[1][2][0] - self._step, bezier[1][2][ 1] + self._step) # bezier[1][2] + Vector2(-(Vector2.from_points(bezier[1][2], bezier[1][3]))) #5th point modifier # line 3 end bezier[2][2] = Vector2(self.end_positions[i]) # last point bezier[2][3] = Vector2(p4_x_mod, random.randrange(2 * self._step, canvas_h - self._step)) # Vector2(random.randrange(self.end_positions[i][0]-self._step//2,self.end_positions[i][0]+self._step//2),random.randrange(self._step*(data[3]-3),self._step*(data[3]-1))) #6th point modifier bezier_points = [] # labels = ["p1s","mod","p1e","mod","p2s","mod","p2e","mod","p3s","mod","p3e","mod"] for j in range(3): bezier_points.extend(ex.DrawBezier(bezier[j])) self.ready_lines.append(bezier_points)
def bezier_lines(self, data, canvas, i): # points = [[beginning], [beginning_midifier], [end_midifier], [end]] # points = [[200, 400], [300, 250], [450, 500], [500, 475]] modifiers = [[0, 0], [0, 0]] modifiers[0] = [random.randrange(0, self.layout.game_w), random.randrange(self._step * 2, self._step * data[3])] modifiers[1] = [random.randrange(0, self.layout.game_w), random.randrange(0, self._step * (data[3] - 2))] points = [Vector2(self.start_positions[i]), Vector2(modifiers[0]), Vector2(self.end_positions[i]), Vector2(modifiers[1])] bezier_points = ex.DrawBezier(points) self.ready_lines.append(bezier_points)
def bezier2x_lines(self, data, canvas, i): # points = [[beginning], [beginning_midifier], [end], [end_midifier]] # points = [[200, 400], [300, 250], [450, 500], [500, 475]] canvas_w = self.layout.game_w canvas_h = self._step * data[3] bezier = [[[0, 0] for j in range(4)] for j in range(2)] # line 1 start bezier[0][0] = Vector2(self.start_positions[i]) bezier[0][1] = Vector2(random.randrange(self._step, canvas_w - self._step), random.randrange(self._step * 2, canvas_h - self._step)) # mod1 #first point modifier # line 1 end bezier[0][2] = Vector2(random.randrange(self._step, canvas_w - self._step), random.randrange(self._step, canvas_h - self._step)) # first line end bezier[0][3] = Vector2(ex.rand_safe_curve(bezier[0][2], canvas_w, canvas_h)) # line 3 start bezier[1][0] = bezier[0][2] bezier[1][1] = bezier[0][2] + Vector2(-(Vector2.from_points(bezier[0][2], bezier[0][3]))) # 5th point modifier # line 3 end bezier[1][2] = Vector2(self.end_positions[i]) # last point bezier[1][3] = Vector2(random.randrange(self._step, canvas_w - self._step), random.randrange(self._step, self._step * (data[3] - 1))) # 6th point modifier bezier_points = [] for j2 in range(2): bezier_points.extend(ex.DrawBezier(bezier[j2])) self.ready_lines.append(bezier_points)
def bezier2x_lines(self, data, canvas, i): #points = [[beginning], [beginning_midifier], [end], [end_midifier]] #points = [[200, 400], [300, 250], [450, 500], [500, 475]] canvas_w = self.layout.game_w canvas_h = self._step*data[3] x_center = self.layout.game_w //2 y_center = self._step*data[3]//2 bezier = [[[0,0] for j in range(4)] for j in range(2)] #line 1 start bezier[0][0] = Vector2(self.start_positions[i]) bezier[0][1] = Vector2(random.randrange(self._step,canvas_w-self._step),random.randrange(self._step*2,canvas_h-self._step))#mod1 #first point modifier #line 1 end bezier[0][2] = Vector2(random.randrange(self._step,canvas_w-self._step),random.randrange(self._step,canvas_h-self._step)) #first line end bezier[0][3] = Vector2(ex.rand_safe_curve(bezier[0][2],canvas_w,canvas_h)) #line 3 start bezier[1][0] = bezier[0][2] bezier[1][1] = bezier[0][2] + Vector2(-(Vector2.from_points(bezier[0][2], bezier[0][3]))) #5th point modifier #line 3 end bezier[1][2] = Vector2(self.end_positions[i]) #last point bezier[1][3] = Vector2(random.randrange(self._step,canvas_w-self._step),random.randrange(self._step,self._step*(data[3]-1))) #6th point modifier bezier_points = [] for j2 in range(2): bezier_points.extend(ex.DrawBezier(bezier[j2])) self.ready_lines.append(bezier_points)
def bezier3x_lines(self, data, canvas, i): # points = [[beginning], [beginning_midifier], [end], [end_midifier]] # points = [[200, 400], [300, 250], [450, 500], [500, 475]] canvas_w = self.layout.game_w canvas_h = self._step * data[3] x_center = self.layout.game_w // 2 y_center = self._step * data[3] // 2 bezier = [[[0, 0] for j in range(4)] for j in range(3)] # line 1 start bezier[0][0] = Vector2(self.start_positions[i]) bezier[0][1] = Vector2(random.randrange(self._step, canvas_w - self._step), random.randrange(self._step * 2, canvas_h - self._step)) # mod1 #first point modifier # line 1 end bezier[0][2] = Vector2(random.randrange(self._step, canvas_w - self._step), random.randrange(self._step, canvas_h - self._step)) # first line end bezier[0][3] = Vector2(ex.rand_safe_curve(bezier[0][2], canvas_w, canvas_h)) # line 2 start bezier[1][0] = bezier[0][2] bezier[1][1] = bezier[0][2] + Vector2(-(Vector2.from_points(bezier[0][2], bezier[0][3]))) # 3rd point modifier # line 2 end if bezier[0][2][0] > x_center: # if first point is on the right the second will be on the left x_range = [self._step, x_center] else: x_range = [x_center, canvas_w - self._step] if bezier[0][2][1] > y_center: # if first point is on the bottom the second will be on the over the center y_range = [self._step, y_center] else: y_range = [y_center, canvas_h - self._step] bezier[1][2] = Vector2(random.randrange(*x_range), random.randrange(*y_range)) # second line end bezier[1][3] = Vector2(ex.rand_safe_curve(bezier[1][2], canvas_w, canvas_h)) # line 3 start bezier[2][0] = bezier[1][2] bezier[2][1] = bezier[1][2] + Vector2(-(Vector2.from_points(bezier[1][2], bezier[1][3]))) # 5th point modifier # line 3 end bezier[2][2] = Vector2(self.end_positions[i]) # last point bezier[2][3] = Vector2(random.randrange(self._step, canvas_w - self._step), random.randrange(self._step, self._step * (data[3] - 1))) # 6th point modifier bezier_points = [] for j in range(3): bezier_points.extend(ex.DrawBezier(bezier[j])) self.ready_lines.append(bezier_points)
def draw_circles(self): r = self.size // 2 - self.size // 10 m = (self.size - r * 2) // 2 angles = [] angle_start = [] angle_start_float = [] for i in range(len(self.numbers)): angles.append(self.numbers[i] * 3.6) if i == 0: angle_start.append(0) angle_start_float.append(0) else: angle_start.append(int(angle_start_float[-1] - angles[i])) angle_start_float.append(angle_start_float[-1] - angles[i]) for i in range(len(self.numbers)): offset = 0 # Center and radius of pie chart cx = m + r cy = m + r #create vector to push the pieces away from the centre towards middle of the arch centre_vect = Vector2().from_points([cx, cy], [ cx + int( round(r * cos(( (angles[i] - angles[i] / 2.0) + angle_start_float[i]) * pi / 180))), cy + int( round(r * sin(( (angles[i] - angles[i] / 2.0) + angle_start_float[i]) * pi / 180))) ]) centre_vect.normalize() p = [(cx + centre_vect[0] * offset, cy + centre_vect[1] * offset)] # Get points on arc for n in range(-1 + angle_start[i], 1 + int(round(angle_start_float[i] + angles[i]))): x = cx + int(round(r * cos( (n) * pi / 180))) + centre_vect[0] * offset y = cy + int(round(r * sin( (n) * pi / 180))) + centre_vect[1] * offset p.append((x, y)) p.append( (cx + centre_vect[0] * offset, cy + centre_vect[1] * offset)) # Draw pie segment if len(p) > 2 and angles[i] > 0: pygame.draw.polygon(self.canvas, self.colors[i], p) if self.numbers[i] not in [0, 100]: pygame.draw.polygon(self.canvas, self.b_colors[i], p, 2) else: pygame.draw.polygon(self.canvas, self.b_colors[i], p[1:-1], 2)
def draw_circles(self): if self.numbers == [0, 0]: pass elif self.numbers == [1, 1]: #draw circle r = self.size // 2 - self.size // 10 m = (self.size - r * 2) // 2 cx = m + r cy = m + r #circle(Surface, color, pos, radius, width=0) -> Rect pygame.draw.circle(self.canvas, self.color1, (cx, cy), r, 0) pygame.draw.circle(self.canvas, self.border_color1, (cx, cy), r, 1) else: r = self.size // 2 - self.size // 10 m = (self.size - r * 2) // 2 angle = 360.0 / self.numbers[1] angle_start = int(round((self.numbers[0] * angle) / 2.0)) - 1 for i in range(self.numbers[1]): if i < self.numbers[0]: col = self.color1 bd_col = self.border_color1 #offset = self.size // (40 - self.numbers[1] * 2) offset = self.offset_selected else: col = self.color2 bd_col = self.border_color2 offset = self.offset_unselected #offset = self.size // (80 - self.numbers[1] * 2) # Center and radius of pie chart cx = m + r cy = m + r #create vector to push the pieces away from the centre towards middle of the arch centre_vect = Vector2().from_points([cx, cy], [cx + int(round(r * cos(((angle*(i+1) - angle / 2.0) - angle_start) * pi / 180))), cy + int(round(r * sin(((angle*(i+1) - angle / 2.0) - angle_start) * pi / 180)))]) centre_vect.normalize() p = [(cx + centre_vect[0] * offset, cy + centre_vect[1] * offset)] # Get points on arc for n in range(int(round(-1 + angle*i)), int(round(angle*(i+1)))): x = cx + int(round(r * cos((n-angle_start) * pi / 180))) + centre_vect[0] * offset y = cy + int(round(r * sin((n-angle_start) * pi / 180))) + centre_vect[1] * offset p.append((x, y)) p.append((cx + centre_vect[0] * offset, cy + centre_vect[1] * offset)) # Draw pie segment if len(p) > 2: pygame.draw.polygon(self.canvas, col, p) pygame.draw.polygon(self.canvas, bd_col, p, self.border_width)
def draw_circles(self): r = self.size // 2 - self.size // 10 m = (self.size - r * 2) // 2 angles = (self.number * 3.6, (100 - self.number) * 3.6) #angle_start = [int(angles[0]), 0] #int(round((self.number * angle) / 2.0)) #angle_start = [int(round(angles[0] / 2.0 - angles[0])), int(round(angles[0] / 2.0)) + int(angles[0])] angle_start = [int(round(angles[0] / 2.0 - angles[0])) + 1, int(round(angles[0] / 2.0 - angles[0]))+int(angles[0]) + 1] #angle_start = [270, 270+int(angles[0])] for i in range(2): if i == 0: col = self.color1 bd_col = self.border_color1 offset = self.size // 40 else: col = self.color2 bd_col = self.border_color2 offset = self.size // 40 # Center and radius of pie chart cx = m + r cy = m + r #create vector to push the pieces away from the centre towards middle of the arch centre_vect = Vector2().from_points([cx, cy], [cx + int(round(r * cos(((angles[i] - angles[i] / 2.0) + angle_start[i]) * pi / 180))), cy + int(round(r * sin(((angles[i] - angles[i] / 2.0) + angle_start[i]) * pi / 180)))]) centre_vect.normalize() p = [(cx + centre_vect[0] * offset, cy + centre_vect[1] * offset)] # Get points on arc for n in range(-1 + angle_start[i], angle_start[i] + int(round(angles[i]))): x = cx + int(round(r * cos((n) * pi / 180))) + centre_vect[0] * offset y = cy + int(round(r * sin((n) * pi / 180))) + centre_vect[1] * offset p.append((x, y)) p.append((cx + centre_vect[0] * offset, cy + centre_vect[1] * offset)) # Draw pie segment if len(p) > 2 and angles[i] > 0: pygame.draw.polygon(self.canvas, col, p) if self.number not in [0, 100]: pygame.draw.polygon(self.canvas, bd_col, p, 2) else: pygame.draw.polygon(self.canvas, bd_col, p[1:-1], 2)
def bezier3x_lines(self, data, canvas, i): # points = [[beginning], [beginning_midifier], [end], [end_midifier]] # points = [[200, 400], [300, 250], [450, 500], [500, 475]] canvas_w = self.layout.game_w canvas_h = self._step * data[3] x_center = self.layout.game_w // 2 y_center = self._step * data[3] // 2 bezier = [[[0, 0] for j in range(4)] for j in range(3)] # line 1 start bezier[0][0] = Vector2(self.start_positions[i]) bezier[0][1] = Vector2( random.randrange(self._step, canvas_w - self._step), random.randrange(self._step * 2, canvas_h - self._step)) # mod1 #first point modifier # line 1 end bezier[0][2] = Vector2( random.randrange(self._step, canvas_w - self._step), random.randrange(self._step, canvas_h - self._step)) # first line end bezier[0][3] = Vector2( ex.rand_safe_curve(bezier[0][2], canvas_w, canvas_h)) # line 2 start bezier[1][0] = bezier[0][2] bezier[1][1] = bezier[0][2] + Vector2(-(Vector2.from_points( bezier[0][2], bezier[0][3]))) # 3rd point modifier # line 2 end if bezier[0][2][ 0] > x_center: # if first point is on the right the second will be on the left x_range = [self._step, x_center] else: x_range = [x_center, canvas_w - self._step] if bezier[0][2][ 1] > y_center: # if first point is on the bottom the second will be on the over the center y_range = [self._step, y_center] else: y_range = [y_center, canvas_h - self._step] bezier[1][2] = Vector2(random.randrange(*x_range), random.randrange(*y_range)) # second line end bezier[1][3] = Vector2( ex.rand_safe_curve(bezier[1][2], canvas_w, canvas_h)) # line 3 start bezier[2][0] = bezier[1][2] bezier[2][1] = bezier[1][2] + Vector2(-(Vector2.from_points( bezier[1][2], bezier[1][3]))) # 5th point modifier # line 3 end bezier[2][2] = Vector2(self.end_positions[i]) # last point bezier[2][3] = Vector2( random.randrange(self._step, canvas_w - self._step), random.randrange(self._step, self._step * (data[3] - 1))) # 6th point modifier bezier_points = [] for j in range(3): bezier_points.extend(ex.DrawBezier(bezier[j])) # pygame.draw.aalines(canvas, (0, 0, 0), False, bezier_points) self.ready_lines.append(bezier_points)
def draw_fraction(self): if self.numbers == [0, 0]: pass elif self.numbers == [1, 1]: #draw circle r = self.size // 2 - self.size // 10 m = (self.size - r * 2) // 2 cx = m + r cy = m + r pygame.draw.circle(self.canvas, self.color1, (cx, cy), r, 0) pygame.draw.circle(self.canvas, self.border_color1, (cx, cy), r, 1) else: r = self.size // 2 - self.size // 10 m = (self.size - r * 2) // 2 if self.numbers[1] < 48: step = 5 else: step = 2 angle = 360.0 / self.numbers[1] angle_start_f = (self.numbers[0] * angle) / 2.0 for i in range(self.numbers[1]): if i < self.numbers[0] and self.numbers[0] > 0: col = self.color1 bd_col = self.border_color1 offset = self.offset_selected else: col = self.color2 bd_col = self.border_color2 offset = self.offset_unselected # Center and radius of pie chart cx = m + r cy = m + r #create vector to push the pieces away from the centre towards middle of the arch centre_vect = Vector2().from_points([cx, cy], [cx + (r * cos(((angle*(i+1) - angle / 2.0) - angle_start_f) * pi / 180.0)), cy + (r * sin(((angle*(i+1) - angle / 2.0) - angle_start_f) * pi / 180.0))]) centre_vect.normalize() #first point p = [(cx + centre_vect[0] * offset, cy + centre_vect[1] * offset)] # Get points on arc for n in range(int(round(angle*i)), int(round(angle*(i+1))), step): x = cx + int(round(r * cos((n-angle_start_f) * pi / 180) + centre_vect[0] * offset)) y = cy + int(round(r * sin((n-angle_start_f) * pi / 180) + centre_vect[1] * offset)) p.append((x, y)) # final point on arc n = angle * (i + 1) x = cx + int(round(r * cos((n-angle_start_f) * pi / 180) + centre_vect[0] * offset)) y = cy + int(round(r * sin((n-angle_start_f) * pi / 180) + centre_vect[1] * offset)) p.append((x, y)) # last point - same as the first one p.append((cx + centre_vect[0] * offset, cy + centre_vect[1] * offset)) # Draw pie segment if len(p) > 2: pygame.draw.polygon(self.canvas, col, p) pygame.draw.polygon(self.canvas, bd_col, p, self.border_width)