예제 #1
0
def key_poller():

    shutdown = False

    key_map = {}
    for c in range(97, 123):
        key_map[chr(c)] = False

    rate = rospy.Rate(10)

    w = sf.RenderWindow(sf.VideoMode(640, 480), "tele-op",
                        sf.Style.TITLEBAR | sf.Style.RESIZE)
    while not rospy.is_shutdown() and not shutdown:
        for event in w.events:
            # Handle shutdown
            if type(event) is sf.KeyEvent and event.code is sf.Keyboard.ESCAPE:
                w.close()
                shutdown = True

            if type(event
                    ) is sf.KeyEvent and 0 <= event.code and event.code < 26:
                key = chr(event.code + 97)
                if (event.pressed):
                    key_map[key] = True

                if (event.released):
                    key_map[key] = False

        publish_cmd_vel(key_map)
        sf.sleep(sf.seconds(0.05))
예제 #2
0
파일: piece.py 프로젝트: gkraften/P-Uppgift
    def flip(self):
        """Flip the piece to change color."""

        self.max_scale = self.scale
        self.time = sf.seconds(0)
        self.color *= -1
        self.flipping = True
예제 #3
0
파일: time.py 프로젝트: PySFML/python-thor
def test_timer(timer):
    timer.restart(sf.seconds(1))
    timer.start()
    sf.sleep(sf.seconds(0.2))
    print(timer.remaining_time)
    print(timer.is_running())
    print(timer.is_expired())
    sf.sleep(sf.seconds(0.5))

    timer.reset(sf.seconds(0.2))
    print(timer.is_running())
    timer.start()

    while timer.is_running():
        sf.sleep(sf.seconds(0.025))
        print(timer.remaining_time)

    print(timer.is_expired())
예제 #4
0
 def soundMaker(self, tinfo=""):
     """
     Create the background music.
     """
     uargv = ""
     if (self.debug1):
         print("\n\tThe thread", tinfo, "is starting.")
     uargv = tinfo.upper()
     buffer = sf.SoundBuffer.from_file(self.soundFile)
     if (not buffer):
         print("\n\tUnable to load the sound", self.soundFile, ".")
     sound = sf.Sound(buffer)
     sound.loop = True
     while (True):
         sound.play()
         sf.sleep(sf.seconds(300))
     if (self.debug1):
         print("\n\tThe thread", uargv, "is terminated.")
예제 #5
0
파일: piece.py 프로젝트: gkraften/P-Uppgift
    def __init__(self, target, color):
        super().__init__(target)

        self.color = color

        self.time = sf.seconds(0)

        self.flipping = False

        self.black_tex = sf.Texture.from_file(
            assets.get_asset("/images/black.png"))
        self.black_tex.smooth = True
        self.white_tex = sf.Texture.from_file(
            assets.get_asset("/images/white.png"))
        self.white_tex.smooth = True

        self.texture_size = self.black_tex.size

        self.size = self.texture_size.x

        self.black = sf.Sprite(self.black_tex)
        self.black.origin = (self.texture_size.x / 2, self.texture_size.y / 2)
        self.white = sf.Sprite(self.white_tex)
        self.white.origin = (self.texture_size.x / 2, self.texture_size.y / 2)
예제 #6
0
파일: pong.py 프로젝트: Xender/python-sfml
ball.origin = (ball_radius / 2, ball_radius / 2)

# load the font
font = sf.Font.from_file("data/sansation.ttf")

# initialize the pause message
pause_message = sf.Text()
pause_message.font = font
pause_message.character_size = 40
pause_message.position = (170, 150)
pause_message.color = sf.Color.WHITE
pause_message.string = "Welcome to pySFML pong!\nPress space to start the game"

# define the paddles properties
ai_timer = sf.Clock()
ai_time = sf.seconds(0.1)
paddle_speed = 400.
right_paddle_speed = 0.
ball_speed = 400.
ball_angle = 0.  # to be changed later

clock = sf.Clock()
is_playing = False

while window.is_open:

    # handle events
    for event in window.events:
        # window closed or escape key pressed: exit
        if type(event) is sf.CloseEvent:
            window.close()
예제 #7
0
파일: time.py 프로젝트: PySFML/python-thor
from sfml import sf
from thor import th

# TEST #001 th.StopWatch
stopwatch = th.StopWatch()
stopwatch.start()
sf.sleep(sf.seconds(1))
print(stopwatch.elapsed_time)

print(stopwatch.is_running())
stopwatch.stop()
print(stopwatch.is_running())
stopwatch.reset()
stopwatch.restart()

def test_timer(timer):
    timer.restart(sf.seconds(1))
    timer.start()
    sf.sleep(sf.seconds(0.2))
    print(timer.remaining_time)
    print(timer.is_running())
    print(timer.is_expired())
    sf.sleep(sf.seconds(0.5))

    timer.reset(sf.seconds(0.2))
    print(timer.is_running())
    timer.start()

    while timer.is_running():
        sf.sleep(sf.seconds(0.025))
        print(timer.remaining_time)
예제 #8
0
add_frames(attack, 1, 4, 4, 5.0) # frame  4   : aim (5 times normal frame duration)
for _ in range(3):
    add_frames(attack, 1, 5, 7)  # frames 5..7: fire (repeat 3 times)
add_frames(attack, 1, 4, 4, 5.0) # frame  4   : wait
add_frames(attack, 1, 3, 0)      # frame  3..1: lower gun

# define static frame for stand animation
stand = th.FrameAnimation()
add_frames(stand, 0, 0, 0)

# register animations with their corresponding durations
animator = th.Animator()
#animator.add_animation("walk", walk, sf.seconds(1))
#animator.add_animation("stand", stand, sf.seconds(1))
#animator.add_animation("attack", attack, sf.seconds(1))
animator.add_animation(0, walk, sf.seconds(1))
animator.add_animation(1, stand, sf.seconds(1))
animator.add_animation(2, attack, sf.seconds(1))

# create clock to measure frame time
frame_clock = sf.Clock()

# main loop
running = True

while(running):

    # handle events
    for event in window.events:
        if event == sf.KeyEvent and event.pressed:
            if event.code == sf.Keyboard.W:
예제 #9
0
파일: checkers-sfml.py 프로젝트: jokoon/eio
    for a in filenames:
        print("opening", a[1])
        font = sf.Font.from_file("C:\\eio\\fonts\\more\\"+a[1])
        fonts[a[1]] = font
    i = 0
    for a in filenames:
        texts.append(sf.Text())
        texts[-1].font = fonts[a[1]]
        texts[-1].character_size = a[0]
        texts[-1].position = (10, 30*i)
        texts[-1].color = sf.Color.WHITE
        texts[-1].string = test_text +" "+ a[1]
        i+=1
# define the paddles properties
ai_timer = sf.Clock()
ai_time = sf.seconds(0.1)

clock = sf.Clock()
is_playing = False
points = []
def addpt(coords, radius = 10):
    points.append(sf.CircleShape())
    points[-1].radius = radius
    points[-1].outline_thickness = 2
    points[-1].outline_color = sf.Color(255,255,255)
    points[-1].fill_color = sf.Color(255,255,255, 0)
    points[-1].origin = (radius, radius)
    points[-1].position = coords
mousepos = None
##################### graphics ###############################
verts = sf.VertexArray(sf.PrimitiveType.LINES)
예제 #10
0
파일: time.py 프로젝트: PySFML/python-thor
from sfml import sf
from thor import th

# create SFML window
window = sf.RenderWindow(sf.VideoMode(300, 200), "Thor - Time", sf.Style.CLOSE)
window.vertical_synchronization = True

# create stopwatch and timer
initial_time = sf.seconds(4)
stop_watch = th.StopWatch()
timer = th.CallbackTimer()
timer.reset(initial_time)

# load font
font = sf.Font.from_file("Media/sansation.ttf")

# create texts that display instructions and current time
instructions_text = "S      Start/pause stopwatch\n"
instructions_text += "T      Start/pause timer\n"
instructions_text += "R      Reset stopwatch and timer\n"
instructions_text += "Esc  Quit"
instructions = sf.Text(instructions_text, font, 14)

stop_watch_measurement = sf.Text()
stop_watch_measurement.character_size = 20
stop_watch_measurement.font = font
stop_watch_measurement.position = (70, 120)
stop_watch_measurement.color = sf.Color(0, 190, 140)

timer_measurement = sf.Text()
timer_measurement.font = font
예제 #11
0
from copy import copy
from sfml import sf
from thor import th

# various constants as firework parameters
EXPLOSION_INTERVAL  = sf.seconds(1)
EXPLOSION_DURATION  = sf.seconds(0.2)
TAIL_DURATION       = sf.seconds(2.5)
TAILS_PER_EXPLOSION = 15
GRAVITY             = 30

# array with possible colors for explosions
firework_colors = (
	sf.Color(100, 255, 135), # light green
	sf.Color(175, 255, 135), # lime green
	sf.Color(85, 190, 255),  # light blue
	sf.Color(255, 145, 255), # pink
	sf.Color(100, 100, 255), # indigo
	sf.Color(140, 250, 190), # turquoise
	sf.Color(255, 135, 135), # red
	sf.Color(240, 255, 135), # light yellow
	sf.Color(245, 215, 80)   # light orange
)

# custom emitter that groups particles in tails
class FireworkEmitter(th.Emitter):
	def __init__(self, position):
		th.Emitter.__init__(self)

		self._accumulated_time = copy(sf.Time.ZERO)
		self._position = copy(position)
예제 #12
0
파일: main.py 프로젝트: borbrudar/Spark
from sfml import sf

import pyximport; pyximport.install()
import extension

window = sf.RenderWindow(sf.VideoMode(640, 480), "sfml")

image = sf.Image.from_file("image.jpg")
extension.flip_image(image)

texture = sf.Texture.from_image(image)

window.clear()
window.draw(sf.Sprite(texture))
window.display()

sf.sleep(sf.seconds(5))
예제 #13
0
from thor import th

# create window
window = sf.RenderWindow(sf.VideoMode(800, 600), "pyThor - Particles")

# load image and initialize sprite
try:
	texture = sf.Texture.from_file("Media/particle.png")
except IOError as error:
	print(error)
	exit(1)

# create emitter
emitter = th.UniversalEmitter()
emitter.emission_rate = 30
emitter.particle_lifetime = sf.seconds(5)
emitter.particle_position = lambda: sf.Mouse.get_position(window)

# create particle system
system = th.ParticleSystem(texture)
system.add_emitter(emitter)

## build color gradient (green -> teal -> blue)
gradient = th.create_gradient([sf.Color(0, 150, 0), 1,
								sf.Color(0, 150, 100), 1,
								sf.Color(0, 0, 150)])

# create color and fade in/out animations
colorizer = th.ColorAnimation(gradient)
fader     = th.FadeAnimation(0.1, 0.1)