def update(self, **kwargs): PyGameScene.update(self, **kwargs) cursor = kwargs["cursor"] if "cursor" in kwargs else None self.scene.fill((0, 0, 0)) if cursor: # Capture the current position as the next vector. if self.capturePosition: if not self.A: self.A = cursor.position.copy() elif not self.AC: self.AC = Segment(self.A, cursor.position.copy()) elif not self.B: self.B = cursor.position.copy() elif not self.BD: self.BD = Segment(self.B, cursor.position.copy()) self.capturePosition = False # Draw line segment AC if set... if self.AC: pygame.draw.line(self.scene, self.segmentColor, self.AC.debut.tupled(), self.AC.arret.tupled(), 2) # ... otherwise, draw a line segment preview. elif self.A: pygame.draw.line(self.scene, self.previewColor, self.A.tupled(), cursor.position.tupled(), 1) # Draw line segment BD if set... if self.BD: pygame.draw.line(self.scene, self.segmentColor, self.BD.debut.tupled(), self.BD.arret.tupled(), 2) # ... otherwise, draw a line segment preview. elif self.B: pygame.draw.line(self.scene, self.previewColor, self.B.tupled(), cursor.position.tupled(), 1) # Switch to the checking for intersection 'mode' if all vertices/vectors have been set. self.checking = self.AC and self.BD if self.checking: # Draw the 'missing' part of the triangle used to calculate the intersection vertex. pygame.draw.line(self.scene, self.derivativesColor, self.A.tupled(), self.B.tupled(), 1) I, delta = Segment.intersection(self.AC, self.BD) if not None in [I, delta]: print(f"Intersection: {I} | delta: {delta}") # Might as well as draw the intersection point(s). pygame.draw.circle(self.scene, self.intersectionColor, I.tupled(), 5, 2) else: # There's no intersection. print(f"No intersection between {self.AC} and {self.BD}.")
def update(self, **kwargs): PyGameScene.update(self, **kwargs) cursor = kwargs["cursor"] if "cursor" in kwargs else None self.scene.fill((0, 0, 0)) # Always draw the borders. for border in self.borders: pygame.draw.line(self.scene, self.segmentColor, border.debut.tupled(), border.arret.tupled(), BORDER_SIZE) if cursor: # Capture the current position as the next vector. if self.capturePosition: if not self.A: self.A = cursor.position.copy() elif not self.AC: self.AC = Segment(self.A, cursor.position.copy()) self.capturePosition = False # Draw line segment AC if set... if self.AC: pygame.draw.line(self.scene, self.segmentColor, self.AC.debut.tupled(), self.AC.arret.tupled(), 2) # ... otherwise, draw a line segment preview. elif self.A: pygame.draw.line(self.scene, self.previewColor, self.A.tupled(), cursor.position.tupled(), 1) # Switch to the checking for intersection 'mode' if all vertices/vectors have been set. if self.AC: # Check the intersection with all borders. for border in self.borders: I, delta = Segment.intersection(self.AC, border) if not None in [I, delta]: print( f"Intersection between {self.AC} and {border}: {I}" ) # Might as well as draw the intersection point(s). pygame.draw.circle(self.scene, self.intersectionColor, I.tupled(), 5, 2) else: # There's no intersection. print( f"Intersection between {self.AC} and {border}: None" )
def update(self, **kwargs): PyGameScene.update(self, **kwargs) cursor = kwargs["cursor"] if "cursor" in kwargs else None if cursor: if self.emitting: # Get the current amount of living rays. rays = self.getExistingEntities(TrailingRay) # Emit some more rays, if there are any to emit. self.addEntities(cursor.emitRays(self.raysToEmit(len(rays)))) # Draw all living rays, for ray in self.getExistingEntities(TrailingRay): ray.draw(self.scene)
def update(self, **kwargs): PyGameScene.update(self, **kwargs) self.scene.fill((0, 0, 0)) # Draw a clock face. radius = min(self.origin.components) * 0.75 pygame.draw.circle(self.scene, (127, 127, 127), self.origin.tupled(), radius, 2) # Adjust reference angle from 0 tau (3 o'clock) to 1/4 tau (midnight). referenceAngle = -0.25 * tau referencePosition = self.origin + Vertex( cos(referenceAngle) * radius, sin(referenceAngle) * radius) # pygame.draw.line(self.scene, (127, 127, 0), self.origin.tupled(), referencePosition.tupled(), 2) # Draw the hour hand. hoursAngle = referenceAngle + (self.clock.hours % 12) / 12 * tau hourHandPosition = self.origin + Vertex( cos(hoursAngle) * radius, sin(hoursAngle) * radius) pygame.draw.line(self.scene, (127, 0, 0), self.origin.tupled(), hourHandPosition.tupled(), 2) # Draw the minute hand. minutesAngle = referenceAngle + self.clock.minutes / 60 * tau minuteHandPosition = self.origin + Vertex( cos(minutesAngle) * radius, sin(minutesAngle) * radius) pygame.draw.line(self.scene, (0, 127, 0), self.origin.tupled(), minuteHandPosition.tupled(), 2) # Draw the second hand. secondsAngle = referenceAngle + (self.clock.seconds if self.continuous else floor( self.clock.seconds)) / 60 * tau secondHandPosition = self.origin + Vertex( cos(secondsAngle) * radius, sin(secondsAngle) * radius) pygame.draw.line(self.scene, (0, 0, 127), self.origin.tupled(), secondHandPosition.tupled(), 2)