Makes a color fully transparent, or more accurately, making a color simply not be blit. # x-y-value-pairs of where dashes start (and on next, will end)ĭash_knots = np.array(, end_pos, dash_amount) for i in range(2)]).There are kinds 3 of transparency supported in pygame: colorkeys, Surface alphas, and per-pixel alphas. # get amount of pieces that line will be split up in (half of it are amount of dashes) Length = np.linalg.norm(end_pos - start_pos) # get euclidian distance between start_pos and end_pos import pygame as pgĭef draw_line_dashed(surface, color, start_pos, end_pos, width = 1, dash_length = 10, exclude_corners = True): You could make this function way shorter, by using all of NumPy's features. Answers that consist of independent solutions with no justification do not constitute a code review, and may be removed. We are looking for answers that provide insightful observations about the code in the question. (surf, color, start.get(), end.get(), width) Start = origin + (slope * index * dash_length)Įnd = origin + (slope * (index + 1) * dash_length) # get back values in original tuple formatįor index in range(0, length/dash_length, 2): Return int(math.sqrt(self.x**2 + self.y**2)) Return Point((self.x/scalar, self.y/scalar)) Return Point((self.x*scalar, self.y*scalar)) Return Point((self.x - other.x, self.y - other.y)) Return Point((self.x + other.x, self.y + other.y)) Instead of storing all the values you're trying to draw, it might be more efficient to just get the slope of the drawn line, and compute dashes at draw time.Ĭonsidering that there's a lot of mirrored code here, consider using a point class to handle both the x and the y values at the same time! class Point: Line a = abs(x2 - x1) to line dy = dl * b / c calculates the amount x and y change for dl (dash_length).īecause dx and dy are floats, I had to use numpy.arange (built-in range() doesn't allow floating-point). This function takes two coordinates and draws a colored dashed line from the first to the second coordinate. Last_coords = list(zip(xcoords, ycoords))įor (x1, y1), (x2, y2) in zip(next_coords, last_coords): Next_coords = list(zip(xcoords, ycoords)) Def draw_dashed_line(surf, color, start_pos, end_pos, width=1, dash_length=10):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |