Beispiel #1
0
  def find_intersection(self, radians):
    s = math.sin( radians )
    c = math.cos( radians )

    l = LineString([
      (self.x, self.y), 
      (self.x + 300*c, self.y + 300*s)
    ])

    intersections = []

    for boundry in self.tracklines:
      i = boundry.intersection(l)
      try:
        (i_x, i_y) = i.x, i.y
        intersections.append((i_x, i_y))
      except:
        i_x, i_y = 0, 0
    
    position = Point(self.x, self.y)
    closest = (0, 0)
    d = 1000

    for entry in intersections:
      point = Point(entry)
      if (position.distance(point) < d):
        d = position.distance(point)
        closest = entry

    circle = shapes.Circle(closest[0], closest[1], 7, color=(255, 0, 0))
    distance = d
    
    return circle, distance
Beispiel #2
0
    def add_to_batch(self, batch):
        super().add_to_batch(batch)

        self._circle = shapes.Circle(
            self.center.x,
            self.center.y,
            self.radius,
            color=(200, 20, 20),
            batch=batch,
        )
Beispiel #3
0
    def __init__(self, width, height):
        super().__init__(width, height, "Shapes")
        self.time = 0
        self.batch = pyglet.graphics.Batch()

        self.circle = shapes.Circle(360,
                                    240,
                                    100,
                                    color=(255, 225, 255),
                                    batch=self.batch)
        self.circle.opacity = 127

        # Rectangle with center as anchor
        self.square = shapes.Rectangle(360,
                                       240,
                                       200,
                                       200,
                                       color=(55, 55, 255),
                                       batch=self.batch)
        self.square.anchor_x = 100
        self.square.anchor_y = 100

        # Large transparent rectangle
        self.rectangle = shapes.Rectangle(0,
                                          190,
                                          720,
                                          100,
                                          color=(255, 22, 20),
                                          batch=self.batch)
        self.rectangle.opacity = 64

        self.line = shapes.Line(0,
                                0,
                                0,
                                480,
                                width=4,
                                color=(200, 20, 20),
                                batch=self.batch)

        self.triangle = shapes.Triangle(10,
                                        10,
                                        190,
                                        10,
                                        100,
                                        150,
                                        color=(20, 200, 20),
                                        batch=self.batch)
        self.triangle.opacity = 150
Beispiel #4
0
def on_draw():
    window.clear()
    shapes.Rectangle(x=0,
                     y=0,
                     width=board_size,
                     height=board_size,
                     color=(30, 100, 160)).draw()

    for i in range(N):
        p = (i + 0.5) * field_size
        shapes.Line(x=p, y=0, x2=p, y2=board_size).draw()
        shapes.Line(x=0, y=p, x2=board_size, y2=p).draw()

    for i, row in enumerate(board.fields):
        for j, color in enumerate(row):
            if color != Color.NONE:
                v = 200 if color == Color.WHITE else 30
                x, y = (i + 0.5) * field_size, (j + 0.5) * field_size
                shapes.Circle(x=x,
                              y=y,
                              radius=field_size / 2 - 2,
                              color=(v, v, v)).draw()
                if last_pos == (i, j):
                    shapes.Rectangle(x=x - 2,
                                     y=y - 2,
                                     width=5,
                                     height=5,
                                     color=(255, 0, 0)).draw()

    if info:
        text.Label(info,
                   x=window.width / 2,
                   y=50,
                   anchor_x='center',
                   color=(255, 255, 0, 255),
                   bold=True).draw()