nsawelcome.blogg.se

Pygame draw dashed line
Pygame draw dashed line




pygame draw dashed line pygame draw dashed line pygame draw dashed line

Write another function that behaves similarly to (), but uses the former function ( draw_dashed_line) to draw the dashed curve. Start = (int(prev_line_len) // step) * stepĮnd = (int(prev_line_len + dist) // step + 1) * stepįor i in range(start, end, dash_length*2):Į = min(start - prev_line_len + dash_length, dist) Distribute the strokes along the line: def draw_dashed_line(surf, color, p1, p2, prev_line_len, dash_length=8): Compute the Euclidean distance between the points and the Unit vector that points from the beginning of the line segment to its end. The function has an additional argument prev_line_len which indicates where the line segment is within a consecutive curve. Write a function that operates similar as () but draws a dashed straight line. (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ĭef draw_dashed_line(surf, color, start_pos, end_pos, width=1, dash_length=4):įor index in range(0, int(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)) I have smth similar to what I need, but how can I make it curved? Or how can I improve this to make it like, not ? import pygame I did all the work well except I failed to represent dashed and curved line with pygame. I need to draw sine and cosine waves on a coordinate system exactly like in this picture. rect ( screen, BLUE, ( start, size ), 1 ) pygame. fill ( GRAY ) for rect in rect_list : pygame. pos size = end - start, end - start screen. type = MOUSEMOTION and drawing : end = event. append ( rect ) drawing = False elif event. pos size = end - start, end - start rect = pygame. pos size = 0, 0 drawing = True elif event. type = QUIT : running = False elif event. set_mode (( 640, 240 )) start = ( 0, 0 ) size = ( 0, 0 ) drawing = False rect_list = running = True while running : for event in pygame. """Place multiple rectangles with the mouse.""" import pygame from pygame.locals import * RED = ( 255, 0, 0 ) BLUE = ( 0, 0, 255 ) GRAY = ( 127, 127, 127 ) pygame.






Pygame draw dashed line