示例#1
0
    def __init__(self, timer, length, height):
        PyGameScene.__init__(self, timer, length, height)

        self.borders = []
        self.borders.append(
            Segment(Vertex(BORDER_SIZE, BORDER_SIZE),
                    Vertex(length - BORDER_SIZE, BORDER_SIZE)))  # Top
        self.borders.append(
            Segment(Vertex(length - BORDER_SIZE, BORDER_SIZE),
                    Vertex(length - BORDER_SIZE,
                           height - BORDER_SIZE)))  # Right
        self.borders.append(
            Segment(Vertex(BORDER_SIZE, height - BORDER_SIZE),
                    Vertex(length - BORDER_SIZE,
                           height - BORDER_SIZE)))  # Bottom
        self.borders.append(
            Segment(Vertex(BORDER_SIZE, BORDER_SIZE),
                    Vertex(BORDER_SIZE, height - BORDER_SIZE)))  # Left

        self.previewColor = (127, 127, 127)
        self.segmentColor = (0, 0, 127)

        # Track the four vertices/vectors comprising of the line segments AC and BD.
        self.capturePosition = False
        self.A = None
        self.AC = None

        # Indicate a 'mode' for checking for intersection between the line segments.
        self.checking = False
        self.derivativesColor = (127, 127, 0)
        self.intersectionColor = (255, 127, 127)
示例#2
0
 def __init__(self, timer, length, height, algorithm, data):
     PyGameScene.__init__(self, timer, length, height)
     resolution = Milli()
     Intervaled.__init__(self, 1 / (resolution.scalor * 120), resolution)
     self.origin = Vertex(length / 2, height / 2)
     self.radius = min(*self.origin.components) * 0.80
     self.algorithm = algorithm
     self.reset(data)
示例#3
0
 def __init__(self, timer, length, height):
     PyGameScene.__init__(self, timer, length, height)
     Gravitational.__init__(
         self, 10, Vertex(DEMO_WINDOW_LENGTH / 2, DEMO_WINDOW_HEIGHT << 4))
     self.ball = Ball(
         32, Vertex(DEMO_WINDOW_LENGTH / 3, DEMO_WINDOW_HEIGHT / 3),
         Vector(BALL_VELOCITY, BALL_VELOCITY))
     self.wind = Wind(0.125)
     self.addEntity(self.ball)
示例#4
0
  def live(self):
    PyGameScene.live(self)

    self.scene.fill((0, 0, 0))

    # Always draw the borders.
    for border in self.borders:
      pygame.draw.line(self.scene, BORDER_COLOR, border.debut.tupled(), border.arret.tupled(), BORDER_SIZE)

    self.radar.draw(self.scene, self.borders)
示例#5
0
  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}.")
示例#6
0
    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"
                        )
示例#7
0
    def __init__(self, timer, length, height, continuous=False):
        PyGameScene.__init__(self, timer, length, height)
        # Start a new clock at the current local time.
        instant = datetime.now()
        self.clock = Clock(instant.hour, instant.minute, instant.second)
        self.addEntity(self.clock)  # Tap into the Temporal entity updating.

        # Use the center of the view as the origin of the clock face.
        self.origin = Vertex(length / 2, height / 2)

        # Track request for continuous mode or not.
        self.continuous = continuous
示例#8
0
  def __init__(self, timer, length, height, continuous=False):
    PyGameScene.__init__(self, timer, length, height)
    self.origin = Vertex(length / 2, height / 2)

    self.borders = list()
    self.borders.append(Segment(Vertex(BORDER_SIZE, BORDER_SIZE), Vertex(length - BORDER_SIZE, BORDER_SIZE))) # Top
    self.borders.append(Segment(Vertex(length - BORDER_SIZE, BORDER_SIZE), Vertex(length - BORDER_SIZE, height - BORDER_SIZE))) # Right
    self.borders.append(Segment(Vertex(BORDER_SIZE, height - BORDER_SIZE), Vertex(length - BORDER_SIZE, height - BORDER_SIZE))) # Bottom
    self.borders.append(Segment(Vertex(BORDER_SIZE, BORDER_SIZE), Vertex(BORDER_SIZE, height - BORDER_SIZE))) # Left

    # Ensure the radar beam can reach the corners of the screen.
    self.radar = Radar(self.origin)
    self.addEntity(self.radar) # Tap into the Temporal entity updating.
示例#9
0
    def live(self):
        PyGameScene.live(self)

        self.scene.fill((0, 0, 0))

        if not self.ball.halt:
            # Apply gravitational attraction.
            self.influence(self.ball)

            # Apply wind.
            if self.wind.blowing:
                self.wind.influence(self.ball)

        # Always draw the ball.
        self.ball.draw(self.scene)
示例#10
0
  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)
示例#11
0
  def __init__(self, timer, length, height):
    PyGameScene.__init__(self, timer, length, height)

    self.previewColor = (127, 127, 127)
    self.segmentColor = (0, 0, 127)
    
    # Track the four vertices/vectors comprising of the line segments AC and BD.
    self.capturePosition = False
    self.A = None
    self.AC = None
    self.B = None
    self.BD = None

    # Indicate a 'mode' for checking for intersection between the line segments.
    self.checking = False
    self.derivativesColor = (127, 127, 0)
    self.intersectionColor = (255, 127, 127)
示例#12
0
    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)
示例#13
0
 def __init__(self, timer, length, height):
     PyGameScene.__init__(self, timer, length, height)
示例#14
0
 def onElapsedTime(self, elapsedTime):
     Intervaled.onElapsedTime(self, elapsedTime)
     PyGameScene.onElapsedTime(self, elapsedTime)
示例#15
0
  def live(self):
    PyGameScene.live(self)

    if self.wiping:
      self.scene.fill((0, 0, 0))
示例#16
0
 def __init__(self, timer, length, height):
   PyGameScene.__init__(self, timer, length, height)
   self.emitting = False
   self.wiping = True
   self.rays = list()
示例#17
0
 def __init__(self, timer, length, height, cameraLens):
     PyGameScene.__init__(self, timer, length, height)
     self.enlightening = False
     self.cameraLens = cameraLens
     self.wiping = False