예제 #1
0
    def add_teeth(self, center, num_teeth):
        for tooth in self.teeth:
            self.remove(tooth)

        self.teeth = []
        self.add(self.color)
        self.add(PushMatrix())
        self.add(Translate(center))

        # use this Rotate to animate rotation for the whole flower
        self.rot = Rotate(angle=0, origin=self.storage_pos)
        self.add(self.rot)

        # make petals ellipses with these width and height:
        self.middle_size = self.size / 2
        w = self.size / 5
        h = self.size / 5

        # how much to rotate each petal.
        d_theta = 360. / num_teeth

        for n in range(num_teeth):
            self.add(Rotate(angle=d_theta, origin=center))
            self.add(Translate(self.middle_size, 0))
            rect = CRectangle(cpos=center, csize=(h, w))
            self.teeth.append(rect)
            self.add(rect)
            self.add(Translate(-self.middle_size, 0))

        self.add(PopMatrix())
예제 #2
0
    def __init__(self, pos, texture, size_x=1.0, size_y=1.0, intensity=1.0, Tr=1.0):
        super(BillboardDisplay, self).__init__()
        
        self.intensity = intensity
        self.Tr = Tr

        self.translate = Translate()
        self.rotate_azi = Rotate(origin=(0,0,0), axis=(0,1,0))
        self.rotate_ele = Rotate(origin=(0,0,0), axis=(1,0,0))
        self.scale = Scale()
        self.color_instruction = InstructionGroup()
        self.mesh = Mesh(
            texture=texture,
            vertices=rectangle_nurb.vertices,
            indices=rectangle_nurb.indices,
            fmt=rectangle_nurb.vertex_format,
            mode='triangles'
        )

        self.add(PushMatrix())
        self.add(self.translate)
        self.add(self.rotate_azi)
        self.add(self.rotate_ele)
        self.add(self.scale)
        self.add(self.color_instruction)
        self.add(self.mesh)
        self.add(PopMatrix())

        self.set_color(intensity=intensity, Tr=Tr)
        self.set_size(size_x, size_y)
        self.set_pos(pos)
        self.set_texture(texture)
예제 #3
0
    def draw_object(self, obj_id):
        m = self._scene.objects[obj_id]
        self.obj_rot_z = Rotate(self.obj_rotation[2], 0, 0, 1)
        self.obj_rot_y = Rotate(self.obj_rotation[1], 0, 1, 0)
        self.obj_rot_x = Rotate(self.obj_rotation[0], 1, 0, 0)
        self.obj_translate = Translate(xyz=self.obj_translation)

        if len(m.indices) > 2**16:
            print '%s too big! %s indices' % (obj_id, len(m.indices))

        if m.texture:
            print "loading texture %s " % m.texture
            img = Image(
                source=resource_find(join(dirname(self.scene), m.texture)))
            texture = img.texture
            if texture:
                texture.wrap = 'repeat'
        else:
            texture = None

        vertex_lenght = sum(x[1] for x in m.vertex_format)
        if len(m.vertices) % vertex_lenght:
            print(('warning: vertices lenght (%s)'
                   'is not a multiple of vertex_format lenght(%s)') %
                  (len(m.vertices), vertex_lenght))
        Mesh(vertices=m.vertices,
             indices=m.indices,
             fmt=m.vertex_format,
             texture=texture,
             mode=self.mode)
예제 #4
0
def _draw_sprite(state, canvas, view_pos, view_scale, sprite_name, texture, pos, scale, rotate, origin_xy):
        """
        TODO
        """
        rectangles_rotates_dict = state[globals.IDX_STATE_SPRITES][IDX_SPRITES_RECTS_ROTS]
        col = int(pos[0])
        row = int(pos[1])
        scaled_tile_size = tiles.get_tile_size(state) * view_scale

        tile_x = col * scaled_tile_size
        tile_y = row * scaled_tile_size

        draw_x = tile_x - view_pos[0] * scaled_tile_size
        draw_y = tile_y - view_pos[1] * scaled_tile_size

        draw_pos = (draw_x, draw_y)
        offset = (pos[0] - col, pos[1] - row,)
        offset_pos = (int(draw_pos[0] + scaled_tile_size * offset[0] + origin_xy[0]),
                                 int(draw_pos[1] + scaled_tile_size * offset[1] + origin_xy[1]))

        if rectangles_rotates_dict.has_key(sprite_name):
                rect, rot = rectangles_rotates_dict[sprite_name]
                if not rect.texture is texture:
                        rect.texture = texture

                pos_changed = (abs(rect.pos[0] - offset_pos[0]) > 1) or (abs(rect.pos[1] - offset_pos[1]) > 1)
                rot_changed = abs(rot.angle - rotate) > 1

                if pos_changed or rot_changed:
                        rect.pos = offset_pos
                        rot.angle = rotate
                        x = offset_pos[0]
                        y = offset_pos[1]
                        w = texture.size[0] * view_scale * scale[0]
                        h = texture.size[1] * view_scale * scale[1]
                        rot.origin = (x + w/2, y + h/2)
        else:
                with canvas:
                        PushMatrix()
                        x = offset_pos[0]
                        y = offset_pos[1]
                        w = texture.size[0] * view_scale * scale[0]
                        h = texture.size[1] * view_scale * scale[1]
                        rot = Rotate()
                        rot.angle = rotate
                        rot.axis = (0, 0, 1)
                        rot.origin = (x + w/2, y + h/2)
                        rect = Rectangle(
                                texture=texture,
                                pos=offset_pos,
                                size=(w, h)
                                )
                        rectangles_rotates_dict[sprite_name] = (rect, rot,)
                        PopMatrix()
예제 #5
0
def draw_tile(tile, rotated = False):
	if rotated:
		Rotate(90, 0, 0, 1)
		# no idea why pos isn't 80 or 120
		Rectangle(pos=(0,-100), size=(80, 95),
				source=tilelist[tile / 4])
		Rotate(-90, 0, 0, 1)
		Translate(120, 0, 0)
	else:
		Rectangle(pos=(0,0), size=(80, 95),
			source=tilelist[tile / 4])
		Translate(80, 0, 0)
예제 #6
0
 def reinit_before(self, base_angle=None):
     """Initialize the “before” canvas, i.e., whatever's below the MazeBoard
     """
     cell_size = self.board.cell_size
     if base_angle is None:
         base_angle = 180 if self.current_solver else 0
     self.canvas.before.clear()
     with self.canvas.before:
         for player, rotation in enumerate((90, 270)):
             # Win/lose messages at end of game
             if self.round_number < NUM_ROUNDS:
                 text = ''
             elif player ^ (self.times[0] < self.times[1]):
                 text = 'Winner!'
             else:
                 text = 'Second place'
             PushMatrix()
             Translate(
                 self.board.window_width / 2,
                 self.board.window_height / 2,
                 0,
             )
             Rotate(rotation, 0, 0, 1)
             l = Label(
                 text=text,
                 pos=(
                     -self.board.window_height / 2,
                     -self.board.window_width / 2 + cell_size,
                 ),
                 size=(self.board.window_height, cell_size * 4),
                 bold=True,
                 font_size=cell_size * 2,
                 color=(1, 1, 0),
             )
             PopMatrix()
         PushMatrix()
         Translate(
             self.board.window_width / 2,
             self.board.window_height / 2,
             0,
         )
         # Instructions for animating the board
         self.scale_instruction = Scale(1)
         self.rotate_instruction = Rotate(base_angle, 0, 0, 1)
         Translate(
             -self.board.window_width / 2,
             -self.board.window_height / 2,
             0,
         )
예제 #7
0
    def draw_quad(self, star_list):
        star_tex = Image('star1.png').texture

        with self.canvas:
            for star in star_list:
                size = .5 * star[2]
                PushMatrix()
                t = Translate()
                r = Rotate()
                r.angle = star[3]
                Quad(texture=star_tex,
                     points=(-size, -size, size, -size, size, size, -size,
                             size))
                t.xy = star[0], star[1]
                PopMatrix()
예제 #8
0
 def draw_quad(self, star_list):
     star_tex = Image('star1.png').texture
    
     with self.canvas:
         for star in star_list:
             size = .5*star[2]
             PushMatrix()
             t = Translate()
             r = Rotate()
             r.angle = star[3]
             Quad(texture = star_tex, points = (-size, 
                 -size, size, -size,
                 size, size, -size, size))
             t.xy = star[0], star[1]
             PopMatrix()
예제 #9
0
    def __init__(self, norm, pos, tempo, clock, tempo_map, touch_points,
                 block_handler):
        super(TempoCursor, self).__init__()
        self.norm = norm
        self.pos = pos
        self.size = self.norm.nt((70, 70))

        self.cursor = CEllipse(cpos=pos, csize=self.size)
        self.add(Color(1, 1, 1))
        self.add(self.cursor)

        self.tempo = tempo
        self.clock = clock
        self.tempo_map = tempo_map
        self.sched = Scheduler(self.clock, self.tempo_map)

        self.block_handler = block_handler

        # 0..15, for 16th note granularity
        self.touch_points = touch_points
        self.index = 0

        # add touch markers
        self.add(PushMatrix())
        self.add(Translate(*pos))
        for touch_point in self.touch_points:
            self.add(Rotate(angle=-360 * touch_point / 16))
            self.add(Color(159 / 255, 187 / 255, 208 / 255))  # blue
            self.add(Line(points=(0, 0, 0, self.norm.nv(25)), width=2))
            self.add(Rotate(angle=360 * touch_point / 16))
        self.add(PopMatrix())

        # add current time marker
        self.add(PushMatrix())
        self.add(Translate(*pos))
        self.time_marker = Line(points=(0, 0, 0, self.norm.nv(30)), width=3)
        self.rotate = Rotate(angle=0)
        self.add(self.rotate)
        self.add(Color(0, 0, 0))
        self.add(self.time_marker)
        self.add(PopMatrix())

        self.on_update(0)

        cur_tick = self.sched.get_tick()
        next_tick = quantize_tick_up(cur_tick, kTicksPerQuarter * 4)
        next_tick += self.calculate_tick_interval(0, self.touch_points[0])
        self.sched.post_at_tick(self.touch_down, next_tick)
예제 #10
0
 def draw(self):
     self.canvas.clear()
     with self.canvas:
         Color(self.color.r, self.color.g, self.color.b)
         # half-circle
         Ellipse(pos=(self.position.x - TankWidget.tank_size / 2,
                      self.position.y - TankWidget.tank_size / 2),
                 size=(TankWidget.tank_size, TankWidget.tank_size),
                 angle_start=-90,
                 angle_end=90,
                 segments=30)
         # base
         Rectangle(pos=(self.position.x - TankWidget.tank_size / 2,
                        self.position.y - TankWidget.tank_size / 4),
                   size=(TankWidget.tank_size, TankWidget.tank_size / 4))
         # barrel
         PushMatrix()
         self.rot = Rotate()
         self.rot.angle = self.barrel_rotation
         self.rot.origin = (self.position.x, self.position.y)
         Rectangle(pos=(self.position.x - TankWidget.tank_barrel_size.x / 2,
                        self.position.y),
                   size=(TankWidget.tank_barrel_size.x,
                         TankWidget.tank_size / 2 +
                         TankWidget.tank_barrel_size.y))
         PopMatrix()
예제 #11
0
    def __init__(self, color, pos):
        super(SingularKaleidoscope, self).__init__()
        offset = Window.width * 0.05
        self.height = Window.height / 3

        self.add(PushMatrix())
        self.background = CRectangle(
            pos=pos,
            size=(0, 0),
            texture=Image('res/kaleidoscope/bw-circle.png').texture)
        self.add(self.background)

        self.rotate = Rotate(angle=0, origin=pos)
        self.add(self.rotate)

        self.star = CRectangle(
            pos=pos,
            size=(0, 0),
            texture=Image('res/kaleidoscope/bw-inner-star.png').texture)
        self.add(self.star)

        self.add(PopMatrix())

        self.circle = CEllipse(cpos=pos, csize=(0, 0))
        self.color = Color(*color)
        self.color.a = 0.5
        self.add(self.color)
        self.add(self.circle)

        self.size_grow = None
예제 #12
0
    def _render(self):
        if self.num_particles == 0:
            return
        for i in range(self.num_particles):
            particle = self.particles[i]
            size = (self.texture.size[0] * particle.scale,
                    self.texture.size[1] * particle.scale)
            if particle not in self.particles_dict:
                self.particles_dict[particle] = dict()
                color = particle.color[:]
                with self.canvas:

                    PushMatrix()
                    self.particles_dict[particle]['color'] = Color(
                        color[0], color[1], color[2], color[3])
                    self.particles_dict[particle]['translate'] = Translate()
                    self.particles_dict[particle]['rotate'] = Rotate()
                    self.particles_dict[particle]['rotate'].set(
                        particle.rotation, 0, 0, 1)
                    self.particles_dict[particle]['rect'] = Quad(
                        texture=self.texture,
                        points=(-size[0] * 0.5, -size[1] * 0.5, size[0] * 0.5,
                                -size[1] * 0.5, size[0] * 0.5, size[1] * 0.5,
                                -size[0] * 0.5, size[1] * 0.5))
                    self.particles_dict[particle]['translate'].xy = (
                        particle.x, particle.y)
                    PopMatrix()

            else:
                self.particles_dict[particle][
                    'rotate'].angle = particle.rotation
                self.particles_dict[particle]['translate'].xy = (particle.x,
                                                                 particle.y)
                self.particles_dict[particle]['color'].rgba = particle.color
예제 #13
0
    def countdown(self, num):
        """The countdown for the solving player

        For positive `num`, shows the number near the maze entrance, animates
        it, and schedules a call to countdown(num-1) for one second.
        For num == 0, display 'Go!', animate it, and grow the ball source.
        """
        label = Label(
            text=str(num) if num else 'Go!',
            font_size=24,
            color=(0, 0, 1, 1),
        )
        with label.canvas.before:
            PushMatrix()
            Translate(
                self.window_width - self.cell_size * 1,
                self.window_height - self.cell_size * 5,
                0,
            )
            Rotate(90, 0, 0, 1)
        with label.canvas.after:
            PopMatrix()
        animation = Animation(font_size=256,
                              color=(0, 0, 1, 0),
                              t='in_cubic',
                              duration=1.5)
        animation.start(label)
        self.add_widget(label)
        if num > 0:
            Clock.schedule_once(lambda dt: self.countdown(num - 1), 1)
        else:
            self.ball_source.grow(self.cell_size * 3)
            if self.parent:
                self.parent.set_message(True,
                                        u'Take a ball from the blue corner.')
예제 #14
0
    def add_screen(self, screen):
        self.screen_in.pos = self.screen_out.pos
        self.screen_in.size = self.screen_out.size
        self.manager.real_remove_widget(self.screen_out)

        self.fbo_in = self.make_screen_fbo(self.screen_in)
        self.fbo_out = self.make_screen_fbo(self.screen_out)
        self.manager.canvas.add(self.fbo_in)
        self.manager.canvas.add(self.fbo_out)

        screen_rotation = Config.getfloat('graphics', 'rotation')
        pos = (0, 1)
        if screen_rotation == 90:
            pos = (0, 0)
        elif screen_rotation == 180:
            pos = (-1, 0)
        elif screen_rotation == 270:
            pos = (-1, 1)

        self.render_ctx = RenderContext(fs=self.fs, vs=self.vs)
        with self.render_ctx:
            BindTexture(texture=self.fbo_out.texture, index=1)
            BindTexture(texture=self.fbo_in.texture, index=2)
            Rotate(screen_rotation, 0, 0, 1)
            Rectangle(size=(1, -1), pos=pos)
        self.render_ctx['projection_mat'] = Matrix().\
            view_clip(0, 1, 0, 1, 0, 1, 0)
        self.render_ctx['tex_out'] = 1
        self.render_ctx['tex_in'] = 2
        self.manager.canvas.add(self.render_ctx)
예제 #15
0
    def __init__(self, cpos, dim, shape):
        super().__init__()

        self.shape = shape
        tex_file = 'res/background/%s%d.png' % (self.shape, randint(1, 4))

        self.buffer = dim[1] / 2

        self.dim = np.array(dim, dtype=np.float)
        self.cpos = cpos
        self.pos = np.array([cpos[0] - 0.5 * dim[0], cpos[1] - 0.5 * dim[1]])
        self.vel = np.array((choice([-1, 1]) * randint(50, 200), choice([-1, 1]) * randint(50, 200)), dtype=np.float)

        self.add(PushMatrix())

        self.rotate = Rotate(origin=self.pos, angle=randint(0, 359))
        self.add(self.rotate)

        self.shape = Rectangle(size=dim, texture=Image(tex_file).texture, pos=self.pos)
        self.add(self.shape)

        self.add(PopMatrix())

        self.time = 0
        self.on_update(0)
예제 #16
0
    def __init__(self, **kwargs):
        super(Cannon, self).__init__(**kwargs)
        self.velocity = 0
        self.velocity_clock = 0
        self.velocity_x = 0
        self.velocity_y = 0
        self.angle = 0
        self.x_collide = False
        self.y_collide = False
        self.x_rand = 0
        self.y_rand = 0
        random.seed()
        with self.canvas:
            self.sky = Rectangle(size=(2000, 1000), source="Back_Drop.png")
            self.grass = Rectangle(size=(2000, 100), source="Grass.png")
            self.target = Rectangle(size=(35, 35), pos=(400, 0), source="python_discord_logo.png")
            self.wheel = Rectangle(size=(35, 35), pos=(20, 0), source="Wheel.png")

            # Draws the cannon and binds rotation object to it for changing in set_angle()
            self.canvas.before
            context_instructions.PushMatrix()
            self.rotate = Rotate(origin=(42.5, 12.5), angle=self.angle)
            self.cannon = Rectangle(size=(50, 15), pos=(35, 10), source="cannon.png")
            context_instructions.PopMatrix()
            self.canvas.after

            self.cannonball = Rectangle(pos=(1000, 1000), size=(10, 10), source="Cannon_Ball.png")
예제 #17
0
    def __init__(self, filepath):
        super(Picture, self).__init__()

        im = Image.open(filepath).convert("RGBA")
        self.image = im.copy()
        self.temp = im.copy()
        self.filepath = filepath

        # Save states
        self.history = [(im, im.size[0], im.size[1])]  # includes current state
        self.history_pos = 0

        # Size and graphics
        width, height = self.image.size
        pos = (Window.width - width) // 2, (Window.height - height) // 2
        size = (width, height)

        # allow rotation:
        self.add(PushMatrix())
        self.rotate = Rotate(angle=0)
        self.add(self.rotate)

        # create rectangle to hold image
        self.rectangle = Rectangle(pos=pos, size=size)
        self.add(PopMatrix())
        self.on_update()
        self.add(self.rectangle)
예제 #18
0
    def _get_fbo(self,widget):
        '''get frame buffer object of widget.
        Args:
            widget: subclass of kivy.uix.widget.
        Returns:
            kivy.graphics.fbo
        '''
        if widget.parent is not None:
            canvas_parent_index = widget.parent.canvas.indexof(self.canvas)
            if canvas_parent_index > -1:
                widget.parent.canvas.remove(widget.canvas)

        fbo = Fbo(size=widget.size, with_stencilbuffer=True)

        with fbo:
            PushMatrix()
            ClearColor(0, 0, 0, 0)
            ClearBuffers()
            Scale(1, -1, 1)
            Translate(-widget.x, -widget.y - widget.height, 0)
            Rotate(origin=widget.center,
                axis=(widget.center_x,0,0),
                angle=-180)

        return fbo
예제 #19
0
    def _set_canvas(self):
        with self.canvas.before:
            PushMatrix()
            self.rotation = Rotate(angle=self.start_angle, origin=self.center)

        with self.canvas.after:
            PopMatrix()
예제 #20
0
    def draw_setpoint(self, *args):
        # draw a setpoint
        if self.setpoint_canvas:
            self.canvas.after.remove(self.setpoint_canvas)
            self.setpoint_canvas = None

        if math.isnan(self.setpoint_value):
            return

        v = self.value_to_angle(self.setpoint_value)
        length = self.dial_diameter / 2.0 - self.tic_length if not self.setpoint_length else self.setpoint_length
        self.setpoint_canvas = InstructionGroup()

        self.setpoint_canvas.add(PushMatrix())
        self.setpoint_canvas.add(Color(*self.setpoint_color))
        self.setpoint_canvas.add(
            Rotate(angle=v, axis=(0, 0, -1), origin=self.dial_center))
        self.setpoint_canvas.add(
            Translate(self.dial_center[0], self.dial_center[1]))
        self.setpoint_canvas.add(
            Line(points=[0, 0, 0, length],
                 width=self.setpoint_thickness,
                 cap='none'))
        #self.setpoint_canvas.add(SmoothLine(points=[0, 0, 0, length], width=self.setpoint_thickness))
        self.setpoint_canvas.add(PopMatrix())

        self.canvas.after.add(self.setpoint_canvas)
예제 #21
0
    def draw_ticks(self):
        scangle = self.angle_stop - self.angle_start
        inc = scangle / (
            (self.scale_max - self.scale_min) / self.scale_increment)
        inc /= self.tic_frequency
        cnt = 0

        # create an instruction group so we can remove it and recall draw_ticks to update when pos or size changes
        self.ticks = InstructionGroup()

        self.ticks.add(Color(*self.tic_color))

        labi = self.scale_min
        x = -180.0 + self.angle_start + self.angle_offset  # start
        while x <= self.angle_stop - 180 + self.angle_offset:
            a = x if (x < 0.0) else x + 360.0

            need_label = True
            ticlen = self.tic_length

            if (cnt % self.tic_frequency != 0):
                ticlen = self.tic_length / 2
                need_label = False

            cnt += 1

            self.ticks.add(PushMatrix())
            self.ticks.add(
                Rotate(angle=a,
                       axis=(0, 0, -1),
                       origin=(self.dial_center[0], self.dial_center[1])))
            self.ticks.add(Translate(0, self.tic_radius - ticlen))
            self.ticks.add(
                Line(points=[
                    self.dial_center[0], self.dial_center[1],
                    self.dial_center[0], self.dial_center[1] + ticlen
                ],
                     width=self.tic_width,
                     cap='none',
                     joint='none'))

            if need_label:
                #print("label: " + str(labi))
                #kw['font_size'] = self.tic_length * 2
                label = CoreLabel(text=str(int(round(labi))),
                                  font_size=self.scale_font_size)
                label.refresh()
                texture = label.texture
                self.ticks.add(
                    Translate(-texture.size[0] / 2, -texture.size[1] - 2))
                self.ticks.add(
                    Rectangle(texture=texture,
                              pos=self.dial_center,
                              size=texture.size))
                labi += self.scale_increment

            self.ticks.add(PopMatrix())
            x += inc

        self.canvas.add(self.ticks)
예제 #22
0
    def __init__(self, pos, tick):
        super(Trail, self).__init__()
        self.pos = pos
        self.tick = tick
        self.x = NOW_X + DRAW_CALIBRATION + tick * PIXELS_PER_TICK
        self.y = 360 - 240 + 480 * (pos)
        self.is_hit = False

        self.color = Color(rgb=[0.9, 0.9, 1.0], a=0.9)

        self.width = 40 * PIXELS_PER_TICK
        self.height = 20

        self.flare_color = Color(rgb=[0.5, 0.5, 0.6])
        self.flare_color.a = 0
        self.hit_flare = Rectangle(pos=(self.x, self.y - 40), size=(20, 80))
        self.add(self.flare_color)
        self.add(self.hit_flare)

        self.add(self.color)
        self.shape = Rectangle(pos=(-10, -10), size=(20, 20))

        self.add(PushMatrix())
        self.add(Translate(self.x, self.y))
        self.add(Rotate(angle=45))
        self.add(self.shape)
        self.add(PopMatrix())
예제 #23
0
    def __init__(self, pos, color, angle):
        super(Note, self).__init__()
        self.pos = np.array(pos, dtype=np.float)

        self.pos[0] += 25
        self.pos[1] += 10

        self.color = Color(*color)
        self.add(self.color)
        # adds a translation and rotation and another translation to the note
        self.add(PushMatrix())

        self.translate = Translate(*self.pos)
        self.add(self.translate)

        self._angle = Rotate(angle=angle)
        self.add(self._angle)

        self.translate2 = Translate(0, 40)
        self.add(self.translate2)

        self.note = Rectangle(texture=Image("particle/texture.png").texture,
                              pos=(-15, -15),
                              size=(30, 30))

        self.add(self.note)

        self.add(PopMatrix())

        self.vel = np.array((0, 60), dtype=np.float)

        self.color.a = 1
예제 #24
0
    def __init__(self,
                 start_pos=(Window.width / 2, Window.height / 2),
                 start_ind=0,
                 colors=((0, 1, 0), (0, 0, 1)),
                 num_dots=8,
                 dot_rad=30,
                 ring_rad=60):
        super(DotRing, self).__init__()
        self.start_ind = start_ind
        self.colors = colors
        self.dot_rad = dot_rad

        self.start_pos = start_pos

        self.add(PushMatrix())
        self.add(Translate(*start_pos))

        # Each dot needs another rotation
        d_theta = 360. / num_dots

        # Rotates the whole ring
        self._angle = Rotate(angle=0)
        self.add(self._angle)

        # Scales the whole ring
        self._scale = Scale(origin=self.start_pos, xy=(1, 1))
        self.add(self._scale)

        # Translates the whole ring
        self._translate = Translate()
        self.add(self._translate)

        # Increment rotation to place each petal
        for n in range(num_dots):
            self.add(Rotate(angle=d_theta))
            self.add(Translate(ring_rad, 0))
            c = colors[(self.start_ind + n) % len(
                colors
            )]  # Iterate through the list of colors so each dot is new color
            self.add(Color(*c))
            self.add(CEllipse(cpos=(0, 0), csize=(self.dot_rad, self.dot_rad)))
            self.add(Translate(-ring_rad, 0))

        self.add(PopMatrix())

        self.progress = 1
        self.is_alive = True
예제 #25
0
파일: canvas.py 프로젝트: salt-die/starkv
    def setup_canvas(self):
        """Populate the canvas with the initial instructions.
        """
        self._selecting_nnodes = False

        self.G = Graph.Star(self.nnodes, mode="out")
        self._unscaled_layout = Layout([(0.0, 0.0),
                                        *circle_points(self.nnodes - 1)])

        self.scale = INIT_SCALE
        self.offset_x, self.offset_y = INIT_OFFSET

        self._selected_edge = self._selected_node = None
        self._source_node = self._target_edge = None

        self.canvas.clear()

        with self.canvas.before:
            self.background_color = Color(*BACKGROUND_COLOR)
            self._background = Rectangle(size=self.size, pos=self.pos)

        with self.canvas:
            self.animated_edge_color = Color(*HIGHLIGHTED_EDGE)
            self.animated_edge_color.a = 0
            self.animated_edge = Line(width=1.1)

        # Edge instructions before Node instructions so they're drawn underneath nodes.
        self._edge_instructions = CanvasBase()
        with self._edge_instructions:
            self.edges = {
                edge.tuple: Edge(edge.tuple, self)
                for edge in self.G.es
            }
        self.canvas.add(self._edge_instructions)

        # Animated node drawn above edges but below other nodes.
        with self.canvas:
            PushMatrix()
            self.rotation_instruction = Rotate()
            self.animated_node_color = Color(*ANIMATED_NODE_COLOR)
            self.animated_node_color.a = 0
            self.animated_node = Rectangle(size=(ANIMATION_WIDTH,
                                                 ANIMATION_HEIGHT),
                                           source=ANIMATED_NODE_SOURCE)
            PopMatrix()

        self._node_instructions = CanvasBase()
        with self._node_instructions:
            self.nodes = [Node(vertex.index, self) for vertex in self.G.vs]
        self.canvas.add(self._node_instructions)

        # TODO: Refactor so we only need to do this once
        self.bind(size=self._delayed_resize, pos=self._delayed_resize)
        Window.bind(mouse_pos=self.on_mouse_pos)

        self.step_layout()
        self.layout_stepper()

        self._mouse_pos_disabled = False
예제 #26
0
    def setup_scene(self):
        Color(1, 1, 1, 0)

        PushMatrix()
        self.cam_translate = Translate(self.cam_translation)
        # Rotate(0, 1, 0, 0)
        self.cam_rot_x = Rotate(self.cam_rotation[0], 1, 0, 0)
        self.cam_rot_y = Rotate(self.cam_rotation[1], 0, 1, 0)
        self.cam_rot_z = Rotate(self.cam_rotation[2], 0, 0, 1)
        self.scale = Scale(self.obj_scale)
        UpdateNormalMatrix()
        if self.display_all:
            for i in self._scene.objects:
                self.draw_object(i)
        else:
            self.draw_object(self.obj_id)
        PopMatrix()
예제 #27
0
파일: main.py 프로젝트: brsc2909/discom
    def rotate(self, angle):
        self.canvas.clear()
        self.angle += angle

        with self.canvas:
            Rotate(origin=self.center, angle=self.angle)
            Color(rgba=self.wheelColor)
            Rectangle(pos=self.pos, size=self.size, source=self.source)
예제 #28
0
    def setup_scene(self):
        Color(.5, .5, .5, 0)

        PushMatrix()
        Translate(0, -3, -5)
        # This Kivy native Rotation is used just for
        # enabling rotation scene like trackball
        self.rotx = Rotate(0, 1, 0, 0)
        # here just rotate scene for best view
        self.roty = Rotate(180, 0, 1, 0)
        self.scale = Scale(1)

        UpdateNormalMatrix()

        self.draw_elements()

        PopMatrix()
예제 #29
0
 def _setup_scene(self):
     for mi, m in enumerate(self.scene.objects.values()):
         Color(1, 1, 1, 1)
         PushMatrix()
         Translate(0, -0.3, -1.8)
         setattr(self, 'mesh%03d_rotx' % mi, Rotate(180, 1, 0, 0))
         setattr(self, 'mesh%03d_roty' % mi, Rotate(0, 0, 1, 0))
         setattr(self, 'mesh%03d_scale' % mi, Scale(1))
         UpdateNormalMatrix()
         mesh = Mesh(
             vertices=m.vertices,
             indices=m.indices,
             fmt=m.vertex_format,
             mode='triangles',
         )
         setattr(self, 'mesh%03d' % mi, mesh)
         PopMatrix()
예제 #30
0
 def __init__(self, angle=0, **kwargs):
     super(IconButton, self).__init__(**kwargs)
     self.rotate = Rotate(angle = angle)
     self.canvas.before.add(PushMatrix())
     self.canvas.before.add(self.rotate)
     self.canvas.after.add(PopMatrix())
     self.bind(pos=self.update_canvas)
     self.bind(size=self.update_canvas)
     self.guess = None
예제 #31
0
 def ctclcwiseRot(self, instance):
     self.angle += 10
     with self.imageLayout.canvas:
         newText = self.imageLayout.rect.texture
         newSize = self.imageLayout.rect.size
         newPos = self.imageLayout.rect.pos
         self.imageLayout.canvas.clear()
         Rotate(origin=self.imageLayout.center, angle=self.angle)
         self.imageLayout.rect = Rectangle(texture=newText, size=newSize)
         self.imageLayout.rect.pos = newPos