import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from smartphone_connector import Connector, Colors
from typing import Union, Literal
from examples.server_address import SERVER_ADDRESS

device = Connector(SERVER_ADDRESS, 'FooBar')
device.clear_playground()
device.configure_playground(
    width=180,
    height=180,
    origin_x=10,
    origin_y=10,
    color=Colors.BISQUE,
)


def color(i: int, j: int) -> Union[Literal['white'], Literal['black']]:
    if i % 2 == 0:
        if j % 2 == 0:
            return 'black'
        else:
            return 'white'
    else:
        if j % 2 == 0:
            return 'white'
        else:
            return 'black'

Exemplo n.º 2
0
import os
import sys
sys.path.insert(0,
                os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from smartphone_connector import Connector, SpriteClickedMsg, Colors, time_s
from examples.server_address import SERVER_ADDRESS
from math import cos, sin, pi, radians

device = Connector(SERVER_ADDRESS, 'FooBar')

RADIUS = 40
device.clear_playground()
device.configure_playground(width=100,
                            height=100,
                            shift_x=-50,
                            shift_y=-50,
                            color=Colors.WHITE)
device.add_circle(radius=RADIUS, pos_x=0, pos_y=0, border_color="black")
for deg in range(0, 360, 6):
    device.add_line(x1=sin(radians(deg)) * (RADIUS - 3),
                    y1=cos(radians(deg)) * (RADIUS - 3),
                    y2=cos(radians(deg)) * RADIUS,
                    x2=sin(radians(deg)) * RADIUS,
                    line_width=0.3)

for deg in range(0, 360, 30):
    device.add_line(x1=sin(radians(deg)) * (RADIUS - 5),
                    y1=cos(radians(deg)) * (RADIUS - 5),
                    y2=cos(radians(deg)) * RADIUS,
                    x2=sin(radians(deg)) * RADIUS,
                    line_width=1)
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from smartphone_connector import Connector, AccMsg, KeyMsg, Colors
from random import randint
from examples.server_address import SERVER_ADDRESS

device = Connector(SERVER_ADDRESS, 'FooBar')
device.clear_playground()
device.configure_playground(
    width=100,
    height=100,
    origin_x=50,
    origin_y=50
)

id = device.add_circle(
    pos_x=0,
    pos_y=40,
    radius=5,
    color=Colors.RED,
    direction=[0, -1],
    speed=1,
    time_span=4
)

device.sleep(3)

speed = 1

device.update_circle(
import os
import sys
sys.path.insert(0,
                os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from smartphone_connector import Connector, SpriteClickedMsg, Colors
from examples.server_address import SERVER_ADDRESS

device = Connector(SERVER_ADDRESS, 'FooBar')
score = 0
device.clear_playground()
device.configure_playground(width=100,
                            height=180,
                            color=Colors.ALICEBLUE,
                            images='images')
device.add_sprite(id='score',
                  pos_x=0,
                  pos_y=160,
                  height=20,
                  width=30,
                  text=f'Score: {score}',
                  form='rectangle',
                  color=Colors.LIGHTBLUE)
device.add_sprite(id='cookie',
                  pos_x=30,
                  pos_y=40,
                  height=30,
                  width=30,
                  form='rectanle',
                  color=Colors.BROWN,
                  clickable=True,
                  image='firefox')
Exemplo n.º 5
0
    if data.key == 'down':
        player.pos_y -= DT
        device.update_sprite(id='player1', pos_y=player.pos_y)
    if data.key == 'home':
        if player.form == 'round':
            player.form = 'rectangle'
        else:
            player.form = 'round'
        device.update_sprite(id='player1', form=player.form)


device.on_key = on_key
device.on_sprite_collision = lambda data: print(data)
device.configure_playground(width=100,
                            height=100,
                            shift_x=0,
                            shift_y=0,
                            color=Colors.ALICEBLUE)
with device.add_sprites() as add:

    add(**player)
    add(color='red',
        direction=[1, 1],
        form='round',
        height=5,
        width=5,
        id='asdfa1',
        pos_x=0,
        pos_y=0,
        speed=2,
        reset_time=True)
import os
import sys

sys.path.insert(0,
                os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from smartphone_connector import Connector, Colors
from examples.server_address import SERVER_ADDRESS
from math import sin, cos

DT = 2

device = Connector(SERVER_ADDRESS, 'FooBar')
device.clear_playground()
device.configure_playground(width=100,
                            height=100,
                            shift_x=-50,
                            shift_y=-50,
                            color='lightblue')

device.add_sprite(id='circler',
                  height=10,
                  width=10,
                  form='round',
                  speed=1,
                  color='yellow')

angle = 0
while True:
    device.update_sprite(id='circler',
                         direction=[cos(angle), sin(angle)],
                         color=Colors.next())
Exemplo n.º 7
0
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from smartphone_connector import Connector, Colors
from examples.server_address import SERVER_ADDRESS

device = Connector(SERVER_ADDRESS, 'FooBar')
score = 0
device.clear_playground()
device.configure_playground(
    width=100,
    height=60,
    images='images',
    color=Colors.ALICEBLUE,
    image='waterfall'
)
device.add_sprite(
    id='cookie',
    width=20,
    height=20,
    pos_x=10,
    pos_y=10,
    image='cookie'
)
for rotation in range(360):
    device.update_sprite(id='cookie', rotate=rotation)
    device.sleep(0.1)
device.disconnect()
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from examples.server_address import SERVER_ADDRESS
from smartphone_connector import Connector
from math import sin, cos, pi

device = Connector(SERVER_ADDRESS, 'FooBar')

device.clear_playground()
device.configure_playground(
    width=100,
    height=100,
    origin_x=50,
    origin_y=50,
    color="#FF3366"
)
device.add_line(0, 0, 20, 20, line_width=2)
device.add_line(0, 0, 0, 20, line_width=2)
device.add_line(-20, 0, 0, 0, color="white")
device.add_line(0, 20, -20, 20, color="white")
device.add_line(0, 0, 10, 10, color="white")
id = device.add_line(0, 0, 10, 0, color="yellow")
device.sleep(1)
device.update_line(id, x2=0, y2=-10)
with device.add_lines() as add:
    for i in range(30):
        add(x1=-25, y1=i * 2, x2=-45, y2=i * 2, line_width=1, color="lightblue")


device.add_line(0, 0, 10, 0, line_width=2, color='hsla(0, 100%, 50%, 0.5)')
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from examples.server_address import SERVER_ADDRESS
from smartphone_connector import Connector

device = Connector(SERVER_ADDRESS, 'FooBar')

device.clear_playground()
device.configure_playground(100, 100, 50, 50, color="white")
device.add_circle(pos_x=0, pos_y=0, radius=5, color='red')
device.add_square(pos_x=0, pos_y=0, size=10, color='yellow', text='hi', clickable=True)
device.add_rectangle(pos_x=-20, pos_y=-40, width=10, height=5, color='orange', text='hi', clickable=True, z_index=999)
device.add_circle(pos_x=0, pos_y=0, radius=13, color='green', clickable=True)
device.add_square(pos_x=15, pos_y=0, size=10, color='red', anchor=[0.5, 0.5])
device.add_text(text='1', pos_x=-20, pos_y=10)
device.add_text(text='1', pos_x=-20, pos_y=10, background_color='unset')
device.add_text(text='Hello', pos_x=-20, pos_y=0, border_color='red')
device.add_text(text='Hello', pos_x=-20, pos_y=0, border_color='red', rotate=90, anchor=[0, 1])
device.add_text(text='Hello My Friend', pos_x=-20, pos_y=-10, clickable=True)
device.add_text(text='Hello There', pos_x=-40, pos_y=-40, font_color='white', font_size=10)
device.add_text(text='Hello There', pos_x=-40, pos_y=-40, font_color='white', font_size=10, rotate=-90)

device.on_sprite_clicked = lambda x: print(x)
device.sleep(10)
device.disconnect()
Exemplo n.º 10
0
def on_key(data: KeyMsg):
    global form
    if (data.key == 'home'):
        if form == 'round':
            form = 'rectangle'
        else:
            form = 'round'
        for sprite_nr in range(1, QUEUE_SIZE + 1):
            device.update_sprite(id=f'sprite{sprite_nr}',
                                 color=Colors.random(),
                                 form=form)


device.clear_playground()
device.configure_playground(width=WIDTH,
                            height=HEIGHT,
                            shift_x=SHIFT_X,
                            shift_y=SHIFT_Y)

with device.add_sprites() as add:
    for sprite_nr in range(1, QUEUE_SIZE + 1):
        add(
            id=f'sprite{sprite_nr}',
            color=Colors.random(),
            form=form,
            height=5 + QUEUE_SIZE - sprite_nr,
            width=5 + QUEUE_SIZE - sprite_nr,
            collision_detection=False,
            pos_x=WIDTH * sprite_nr / QUEUE_SIZE,
            pos_y=HEIGHT * sprite_nr / QUEUE_SIZE,
        )