all: Format with black.

Also activate auto formatting. Bump flake8 and mark black
disagreements in setup.cfg.
This commit is contained in:
Laurens Valk
2022-05-27 16:22:05 +02:00
parent 24f7d7c288
commit bd7806d2d4
60 changed files with 716 additions and 709 deletions
+2 -3
View File
@@ -12,12 +12,11 @@ hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500)
wait(10000)
# Make the color RED grow faint and bright using a sine pattern.
hub.light.animate(
[Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40)
hub.light.animate([Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40)
wait(10000)
# Cycle through a rainbow of colors.
hub.light.animate([Color(h=i*8) for i in range(45)], interval=40)
hub.light.animate([Color(h=i * 8) for i in range(45)], interval=40)
wait(10000)
+1 -1
View File
@@ -12,7 +12,7 @@ hub.light.off()
brightness = list(range(0, 100, 4)) + list(range(100, 0, -4))
# Create an animation of the heart icon with changing brightness.
hub.display.animate([Icon.HEART * i/100 for i in brightness], 30)
hub.display.animate([Icon.HEART * i / 100 for i in brightness], 30)
# The animation repeats in the background. Here we just wait.
while True:
@@ -12,15 +12,15 @@ while True:
# Start with random left brow: up or down.
if randint(0, 100) < 70:
brows = Icon.EYE_LEFT_BROW*0.5
brows = Icon.EYE_LEFT_BROW * 0.5
else:
brows = Icon.EYE_LEFT_BROW_UP*0.5
brows = Icon.EYE_LEFT_BROW_UP * 0.5
# Add random right brow: up or down.
if randint(0, 100) < 70:
brows += Icon.EYE_RIGHT_BROW*0.5
brows += Icon.EYE_RIGHT_BROW * 0.5
else:
brows += Icon.EYE_RIGHT_BROW_UP*0.5
brows += Icon.EYE_RIGHT_BROW_UP * 0.5
for i in range(3):
# Display eyes open plus the random brows.
@@ -28,5 +28,7 @@ while True:
wait(2000)
# Display eyes blinked plus the random brows.
hub.display.image(Icon.EYE_LEFT_BLINK*0.7 + Icon.EYE_RIGHT_BLINK*0.7 + brows)
hub.display.image(
Icon.EYE_LEFT_BLINK * 0.7 + Icon.EYE_RIGHT_BLINK * 0.7 + brows
)
wait(200)
+9 -7
View File
@@ -6,13 +6,15 @@ from pybricks.geometry import Matrix
hub = PrimeHub()
# Make a square that is bright on the outside and faint in the middle.
SQUARE = Matrix([
[100, 100, 100, 100, 100],
[100, 50, 50, 50, 100],
[100, 50, 0, 50, 100],
[100, 50, 50, 50, 100],
[100, 100, 100, 100, 100],
])
SQUARE = Matrix(
[
[100, 100, 100, 100, 100],
[100, 50, 50, 50, 100],
[100, 50, 0, 50, 100],
[100, 50, 50, 50, 100],
[100, 100, 100, 100, 100],
]
)
# Display the square.
hub.display.image(SQUARE)
+2 -2
View File
@@ -5,8 +5,8 @@ from pybricks.tools import wait
hub = PrimeHub()
# Display the letter A for two seconds.
hub.display.char('A')
hub.display.char("A")
wait(2000)
# Display text, one letter at a time.
hub.display.text('Hello, world!')
hub.display.text("Hello, world!")
+2 -3
View File
@@ -12,12 +12,11 @@ hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500)
wait(10000)
# Make the color RED grow faint and bright using a sine pattern.
hub.light.animate(
[Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40)
hub.light.animate([Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40)
wait(10000)
# Cycle through a rainbow of colors.
hub.light.animate([Color(h=i*8) for i in range(45)], interval=40)
hub.light.animate([Color(h=i * 8) for i in range(45)], interval=40)
wait(10000)
+2 -3
View File
@@ -13,12 +13,11 @@ hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500)
wait(10000)
# Make the color RED grow faint and bright using a sine pattern.
hub.light.animate(
[Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40)
hub.light.animate([Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40)
wait(10000)
# Cycle through a rainbow of colors.
hub.light.animate([Color(h=i*8) for i in range(45)], interval=40)
hub.light.animate([Color(h=i * 8) for i in range(45)], interval=40)
wait(10000)
@@ -3,10 +3,10 @@
import os
# Get list of scripts to be parsed
script_names = [f for f in os.listdir('.') if f != 'make_shared_examples.py']
script_names = [f for f in os.listdir(".") if f != "make_shared_examples.py"]
# Go through all template scripts
for script in (open(f, 'r') for f in script_names):
for script in (open(f, "r") for f in script_names):
# First line contains hub info
hubs = script.readline().strip().split()[3:]
@@ -15,17 +15,17 @@ for script in (open(f, 'r') for f in script_names):
for hub in hubs:
# Determine path to the hub
hub_path = os.path.join('..', 'hub_' + hub.lower())
hub_path = os.path.join("..", "hub_" + hub.lower())
# Reset source script
script.seek(0)
script.readline()
# Open destination script:
with open(os.path.join(hub_path, script.name), 'w') as dest_file:
with open(os.path.join(hub_path, script.name), "w") as dest_file:
# Read script line by line
for line in script.readlines():
# Replace hub name if present
dest_file.writelines(line.replace('ExampleHub', hub))
dest_file.writelines(line.replace("ExampleHub", hub))
+2 -3
View File
@@ -12,12 +12,11 @@ hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500)
wait(10000)
# Make the color RED grow faint and bright using a sine pattern.
hub.light.animate(
[Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40)
hub.light.animate([Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40)
wait(10000)
# Cycle through a rainbow of colors.
hub.light.animate([Color(h=i*8) for i in range(45)], interval=40)
hub.light.animate([Color(h=i * 8) for i in range(45)], interval=40)
wait(10000)
@@ -51,7 +51,7 @@ for port in ports:
raise
# Get the device id
id = device.info()['id']
id = device.info()["id"]
# Look up the name.
try:
+2 -2
View File
@@ -15,10 +15,10 @@ MAX = 100
# Make the brightness fade in and out.
while True:
# Get phase of the cosine.
phase = watch.time()/PERIOD*2*pi
phase = watch.time() / PERIOD * 2 * pi
# Evaluate the brightness.
brightness = (0.5 - 0.5*cos(phase))*MAX
brightness = (0.5 - 0.5 * cos(phase)) * MAX
# Set light brightness and wait a bit.
light.on(brightness)
+1 -1
View File
@@ -7,6 +7,6 @@ my_remote = Remote()
print(my_remote.name())
# Choose a new name.
my_remote.name('truck2')
my_remote.name("truck2")
print("Done!")
+1 -1
View File
@@ -2,7 +2,7 @@ from pybricks.pupdevices import Remote
from pybricks.tools import wait
# Connect to a remote called truck2.
truck_remote = Remote('truck2', timeout=None)
truck_remote = Remote("truck2", timeout=None)
print("Connected!")
+2 -2
View File
@@ -15,12 +15,12 @@ PERIOD = 3000
while True:
# The phase is where we are in the unit circle now.
phase = watch.time()/PERIOD*2*pi
phase = watch.time() / PERIOD * 2 * pi
# Each light follows a sine wave with a mean of 50, with an amplitude of 50.
# We offset this sine wave by 90 degrees for each light, so that all the
# lights do something different.
brightness = [sin(phase + offset*pi/2) * 50 + 50 for offset in range(4)]
brightness = [sin(phase + offset * pi / 2) * 50 + 50 for offset in range(4)]
# Set the brightness values for all lights.
eyes.lights.on(brightness)