mirror of
https://github.com/pybricks/pybricks-projects.git
synced 2026-09-15 11:03:15 +00:00
snippets/ev3: Split screen into separate projects
These will be included as examples in the API docs
This commit is contained in:
committed by
Laurens Valk
parent
51c91aebd7
commit
d59bf03daf
@@ -1,77 +0,0 @@
|
||||
#!/usr/bin/env pybricks-micropython
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.media.ev3dev import Font, Image, ImageFile
|
||||
|
||||
# It takes some time for fonts to load from file, so it is best to only
|
||||
# load them once at the beginning of the program like this:
|
||||
tiny_font = Font(size=6)
|
||||
big_font = Font(size=24, bold=True)
|
||||
chinese_font = Font(size=24, lang='zh-cn')
|
||||
|
||||
# The same goes for images
|
||||
ev3_img = Image(ImageFile.EV3_ICON)
|
||||
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
|
||||
# TEXT ########################################################################
|
||||
|
||||
# Say hello
|
||||
ev3.screen.print('Hello!')
|
||||
|
||||
# Say tiny hello
|
||||
ev3.screen.set_font(tiny_font)
|
||||
ev3.screen.print('hello')
|
||||
|
||||
# Say big hello
|
||||
ev3.screen.set_font(big_font)
|
||||
ev3.screen.print('HELLO')
|
||||
|
||||
# Say Chinese hello
|
||||
ev3.screen.set_font(chinese_font)
|
||||
ev3.screen.print('你好')
|
||||
|
||||
# Wait some time too look at text
|
||||
wait(5000)
|
||||
|
||||
|
||||
# IMAGES ######################################################################
|
||||
|
||||
# Show an image
|
||||
ev3.screen.load_image(ev3_img)
|
||||
|
||||
# Wait some time too look at image
|
||||
wait(5000)
|
||||
|
||||
|
||||
# SHAPES ######################################################################
|
||||
|
||||
# Clear the screen
|
||||
ev3.screen.clear()
|
||||
|
||||
# Draw a rectangle
|
||||
ev3.screen.draw_box(10, 10, 40, 40)
|
||||
|
||||
# Draw a solid rectangle
|
||||
ev3.screen.draw_box(20, 20, 30, 30, fill=True)
|
||||
|
||||
# Draw a rectangle with rounded corners
|
||||
ev3.screen.draw_box(50, 10, 80, 40, 5)
|
||||
|
||||
# Draw a circle
|
||||
ev3.screen.draw_circle(25, 75, 20)
|
||||
|
||||
# Draw a triangle using lines
|
||||
x1, y1 = 65, 55
|
||||
x2, y2 = 50, 95
|
||||
x3, y3 = 80, 95
|
||||
ev3.screen.draw_line(x1, y1, x2, y2)
|
||||
ev3.screen.draw_line(x2, y2, x3, y3)
|
||||
ev3.screen.draw_line(x3, y3, x1, y1)
|
||||
|
||||
# Wait some time too look at shapes
|
||||
wait(5000)
|
||||
Vendored
Vendored
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env pybricks-micropython
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
|
||||
# Draw a rectangle
|
||||
ev3.screen.draw_box(10, 10, 40, 40)
|
||||
|
||||
# Draw a solid rectangle
|
||||
ev3.screen.draw_box(20, 20, 30, 30, fill=True)
|
||||
|
||||
# Draw a rectangle with rounded corners
|
||||
ev3.screen.draw_box(50, 10, 80, 40, 5)
|
||||
|
||||
# Draw a circle
|
||||
ev3.screen.draw_circle(25, 75, 20)
|
||||
|
||||
# Draw a triangle using lines
|
||||
x1, y1 = 65, 55
|
||||
x2, y2 = 50, 95
|
||||
x3, y3 = 80, 95
|
||||
ev3.screen.draw_line(x1, y1, x2, y2)
|
||||
ev3.screen.draw_line(x2, y2, x3, y3)
|
||||
ev3.screen.draw_line(x3, y3, x1, y1)
|
||||
|
||||
# Wait some time too look at the shapes
|
||||
wait(5000)
|
||||
@@ -0,0 +1,3 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.venv/
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
||||
|
||||
// List of extensions which should be recommended for users of this workspace.
|
||||
"recommendations": [
|
||||
"lego-education.ev3-micropython"
|
||||
],
|
||||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
||||
"unwantedRecommendations": [
|
||||
"ms-python.python"
|
||||
]
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Download and Run",
|
||||
"type": "ev3devBrowser",
|
||||
"request": "launch",
|
||||
"program": "/home/robot/${workspaceRootFolderName}/main.py"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.eol": "\n",
|
||||
"debug.openDebug": "neverOpen",
|
||||
"python.linting.enabled": false
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env pybricks-micropython
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.media.ev3dev import Image, ImageFile
|
||||
|
||||
# It takes some time to load images from the SD card, so it is best to load
|
||||
# them once at the beginning of a program like this:
|
||||
ev3_img = Image(ImageFile.EV3_ICON)
|
||||
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
|
||||
# Show an image
|
||||
ev3.screen.load_image(ev3_img)
|
||||
|
||||
# Wait some time too look at the image
|
||||
wait(5000)
|
||||
@@ -0,0 +1,3 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.venv/
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
||||
|
||||
// List of extensions which should be recommended for users of this workspace.
|
||||
"recommendations": [
|
||||
"lego-education.ev3-micropython"
|
||||
],
|
||||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
||||
"unwantedRecommendations": [
|
||||
"ms-python.python"
|
||||
]
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Download and Run",
|
||||
"type": "ev3devBrowser",
|
||||
"request": "launch",
|
||||
"program": "/home/robot/${workspaceRootFolderName}/main.py"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.eol": "\n",
|
||||
"debug.openDebug": "neverOpen",
|
||||
"python.linting.enabled": false
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env pybricks-micropython
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.media.ev3dev import Font
|
||||
|
||||
# It takes some time for fonts to load from file, so it is best to only
|
||||
# load them once at the beginning of the program like this:
|
||||
tiny_font = Font(size=6)
|
||||
big_font = Font(size=24, bold=True)
|
||||
chinese_font = Font(size=24, lang='zh-cn')
|
||||
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
|
||||
# Say hello
|
||||
ev3.screen.print('Hello!')
|
||||
|
||||
# Say tiny hello
|
||||
ev3.screen.set_font(tiny_font)
|
||||
ev3.screen.print('hello')
|
||||
|
||||
# Say big hello
|
||||
ev3.screen.set_font(big_font)
|
||||
ev3.screen.print('HELLO')
|
||||
|
||||
# Say Chinese hello
|
||||
ev3.screen.set_font(chinese_font)
|
||||
ev3.screen.print('你好')
|
||||
|
||||
# Wait some time too look at the screen
|
||||
wait(5000)
|
||||
Reference in New Issue
Block a user