kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Porównaj commity
14 Commity
059a3a10da
...
7a01a5a797
Autor | SHA1 | Data |
---|---|---|
Ryan | 7a01a5a797 | |
Philip Howard | f1ea35fbbf | |
thirdr | 3aa4f170a8 | |
thirdr | 8bca73df5d | |
thirdr | 06dba8c009 | |
thirdr | 951ee18c42 | |
thirdr | 7cdf939a4c | |
thirdr | 19141cf89a | |
thirdr | bd5624658e | |
thirdr | 03c2a68e3f | |
thirdr | 735cb1a058 | |
thirdr | 3c2d710e2e | |
thirdr | 4a65862858 | |
Phil Howard | 964cf5eedf |
|
@ -494,11 +494,14 @@ namespace pimoroni {
|
|||
void CosmicUnicorn::set_brightness(float value) {
|
||||
value = value < 0.0f ? 0.0f : value;
|
||||
value = value > 1.0f ? 1.0f : value;
|
||||
// Max brightness is - in fact - 256 since it's applied with:
|
||||
// result = (channel * brightness) >> 8
|
||||
// eg: (255 * 256) >> 8 == 255
|
||||
this->brightness = floor(value * 256.0f);
|
||||
}
|
||||
|
||||
float CosmicUnicorn::get_brightness() {
|
||||
return this->brightness / 255.0f;
|
||||
return this->brightness / 256.0f;
|
||||
}
|
||||
|
||||
void CosmicUnicorn::adjust_brightness(float delta) {
|
||||
|
|
|
@ -488,11 +488,14 @@ namespace pimoroni {
|
|||
void GalacticUnicorn::set_brightness(float value) {
|
||||
value = value < 0.0f ? 0.0f : value;
|
||||
value = value > 1.0f ? 1.0f : value;
|
||||
// Max brightness is - in fact - 256 since it's applied with:
|
||||
// result = (channel * brightness) >> 8
|
||||
// eg: (255 * 256) >> 8 == 255
|
||||
this->brightness = floor(value * 256.0f);
|
||||
}
|
||||
|
||||
float GalacticUnicorn::get_brightness() {
|
||||
return this->brightness / 255.0f;
|
||||
return this->brightness / 256.0f;
|
||||
}
|
||||
|
||||
void GalacticUnicorn::adjust_brightness(float delta) {
|
||||
|
|
|
@ -485,11 +485,14 @@ namespace pimoroni {
|
|||
void StellarUnicorn::set_brightness(float value) {
|
||||
value = value < 0.0f ? 0.0f : value;
|
||||
value = value > 1.0f ? 1.0f : value;
|
||||
// Max brightness is - in fact - 256 since it's applied with:
|
||||
// result = (channel * brightness) >> 8
|
||||
// eg: (255 * 256) >> 8 == 255
|
||||
this->brightness = floor(value * 256.0f);
|
||||
}
|
||||
|
||||
float StellarUnicorn::get_brightness() {
|
||||
return this->brightness / 255.0f;
|
||||
return this->brightness / 256.0f;
|
||||
}
|
||||
|
||||
void StellarUnicorn::adjust_brightness(float delta) {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
import pngdec
|
||||
|
||||
# Create a PicoGraphics instance
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
WIDTH, HEIGHT = graphics.get_bounds()
|
||||
|
||||
# Set the font
|
||||
graphics.set_font("bitmap8")
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(graphics)
|
||||
|
||||
# Clear the screen
|
||||
graphics.set_pen(1)
|
||||
graphics.clear()
|
||||
graphics.set_pen(0)
|
||||
|
||||
# Few lines of text.
|
||||
graphics.text("PNG Pencil", 70, 100, WIDTH, 3)
|
||||
|
||||
# Open our PNG File from flash. In this example we're using a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Inky Frame.
|
||||
try:
|
||||
png.open_file("pencil_256x256.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(200, 100)
|
||||
|
||||
except OSError:
|
||||
graphics.text("Unable to find PNG file! Copy 'pencil_256x256.png' to your Inky Frame using Thonny :)", 10, 70, WIDTH, 3)
|
||||
|
||||
# Start the screen update
|
||||
graphics.update()
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 5.4 KiB |
|
@ -0,0 +1,40 @@
|
|||
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_RGB332
|
||||
import pngdec
|
||||
|
||||
# Create a PicoGraphics instance
|
||||
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332)
|
||||
|
||||
# Set the backlight so we can see it!
|
||||
display.set_backlight(1.0)
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Create some pens for use later.
|
||||
BG = display.create_pen(200, 200, 200)
|
||||
TEXT = display.create_pen(0, 0, 0)
|
||||
|
||||
# Clear the screen
|
||||
display.set_pen(BG)
|
||||
display.clear()
|
||||
|
||||
display.set_pen(TEXT)
|
||||
display.text("PNG Pencil", 15, 80)
|
||||
|
||||
try:
|
||||
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Pico.
|
||||
png.open_file("pencil.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(20, 100, scale=3)
|
||||
|
||||
# Handle the error if the image doesn't exist on the flash.
|
||||
except OSError:
|
||||
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
|
||||
|
||||
display.update()
|
||||
|
||||
# We're not doing anything else with the display now but we want to keep the program running!
|
||||
while True:
|
||||
pass
|
|
@ -0,0 +1,54 @@
|
|||
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8
|
||||
import pngdec
|
||||
|
||||
# Create a PicoGraphics instance
|
||||
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P8, rotate=270)
|
||||
|
||||
# Set the backlight so we can see it!
|
||||
display.set_backlight(1.0)
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Create some pens for use later.
|
||||
BG = display.create_pen(200, 200, 200)
|
||||
|
||||
# 16 Reds
|
||||
for i in range(16):
|
||||
display.create_pen(i * 16, 0, 0)
|
||||
|
||||
# 16 Greens
|
||||
for i in range(16):
|
||||
display.create_pen(0, i * 16, 0)
|
||||
|
||||
# 16 Blues
|
||||
for i in range(16):
|
||||
display.create_pen(0, 0, i * 16)
|
||||
|
||||
# Adding in an white background colour at the beginning of each offset.
|
||||
for i in range(3):
|
||||
display.update_pen(i * 16, 200, 200, 200)
|
||||
|
||||
# Clear the screen
|
||||
display.set_pen(BG)
|
||||
display.clear()
|
||||
|
||||
try:
|
||||
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Pico.
|
||||
png.open_file("pencil_gray.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
|
||||
png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
|
||||
png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
|
||||
|
||||
# Handle the error if the image doesn't exist on the flash.
|
||||
except OSError:
|
||||
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
|
||||
|
||||
display.update()
|
||||
|
||||
# We're not doing anything else with the display now but we want to keep the program running!
|
||||
while True:
|
||||
pass
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 1.1 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 497 B |
|
@ -0,0 +1,36 @@
|
|||
from picographics import PicoGraphics, DISPLAY_TUFTY_2040
|
||||
import pngdec
|
||||
|
||||
display = PicoGraphics(display=DISPLAY_TUFTY_2040)
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Create some pens for use later.
|
||||
BG = display.create_pen(200, 200, 200)
|
||||
TEXT = display.create_pen(0, 0, 0)
|
||||
|
||||
# Clear the screen
|
||||
display.set_pen(BG)
|
||||
display.clear()
|
||||
|
||||
display.set_pen(TEXT)
|
||||
display.text("PNG Pencil", 105, 80)
|
||||
|
||||
try:
|
||||
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Pico.
|
||||
png.open_file("pencil.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(140, 100)
|
||||
|
||||
# Handle the error if the image doesn't exist on the flash.
|
||||
except OSError:
|
||||
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
|
||||
|
||||
display.update()
|
||||
|
||||
# We're not doing anything else with the display now but we want to keep the program running!
|
||||
while True:
|
||||
pass
|
|
@ -0,0 +1,54 @@
|
|||
from picographics import PicoGraphics, DISPLAY_TUFTY_2040, PEN_P8
|
||||
import pngdec
|
||||
|
||||
display = PicoGraphics(display=DISPLAY_TUFTY_2040, pen_type=PEN_P8)
|
||||
|
||||
# Create an instance of the PNG Decoder
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Create some pens for use later.
|
||||
BG = display.create_pen(200, 200, 200)
|
||||
TEXT = display.create_pen(0, 0, 0)
|
||||
|
||||
# 16 Reds
|
||||
for i in range(15):
|
||||
display.create_pen(i * 16, 0, 0)
|
||||
|
||||
# 16 Greens
|
||||
for i in range(16):
|
||||
display.create_pen(0, i * 16, 0)
|
||||
|
||||
# 16 Blues
|
||||
for i in range(15):
|
||||
display.create_pen(0, 0, i * 16)
|
||||
|
||||
# Adding in an white background colour at the beginning of each offset.
|
||||
for i in range(3):
|
||||
display.update_pen(i * 16, 200, 200, 200)
|
||||
|
||||
# Clear the screen
|
||||
display.set_pen(BG)
|
||||
display.clear()
|
||||
|
||||
display.set_pen(TEXT)
|
||||
display.text("PNG Pencil \n& Offset Palette", 125, 115)
|
||||
|
||||
try:
|
||||
# Open our PNG File from flash. In this example we're using an image of a cartoon pencil.
|
||||
# You can use Thonny to transfer PNG Images to your Pico.
|
||||
png.open_file("pencil_gray.png")
|
||||
|
||||
# Decode our PNG file and set the X and Y
|
||||
png.decode(35, 10, scale=2, mode=pngdec.PNG_COPY, palette_offset=0)
|
||||
png.decode(35, 90, scale=2, mode=pngdec.PNG_COPY, palette_offset=16)
|
||||
png.decode(35, 170, scale=2, mode=pngdec.PNG_COPY, palette_offset=32)
|
||||
|
||||
# Handle the error if the image doesn't exist on the flash.
|
||||
except OSError:
|
||||
print("Error: PNG File missing. Copy the PNG file from the example folder to your Pico using Thonny and run the example again.")
|
||||
|
||||
display.update()
|
||||
|
||||
# We're not doing anything else with the display now but we want to keep the program running!
|
||||
while True:
|
||||
pass
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 1.1 KiB |
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 497 B |
|
@ -583,3 +583,42 @@ The arguments for `decode` are as follows:
|
|||
2. Decode Y
|
||||
3. Flags - one of `JPEG_SCALE_FULL`, `JPEG_SCALE_HALF`, `JPEG_SCALE_QUARTER` or `JPEG_SCALE_EIGHTH`
|
||||
4. If you want to turn off dither altogether, try `dither=False`. This is useful if you want to [pre-dither your images](https://ditherit.com/) or for artsy posterization effects.
|
||||
|
||||
### PNG Files
|
||||
|
||||
We've included BitBank's PNGDEC - https://github.com/bitbank2/PNGDEC - so you can display PNG files on your LCDs.
|
||||
|
||||
Eg:
|
||||
|
||||
```python
|
||||
import picographics
|
||||
import pngdec
|
||||
|
||||
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332)
|
||||
|
||||
# Create a new PNG decoder for our PicoGraphics
|
||||
png = pngdec.PNG(display)
|
||||
|
||||
# Open the PNG file
|
||||
png.open_file("filename.jpeg")
|
||||
|
||||
# Decode the PNG
|
||||
png.decode(0, 0)
|
||||
|
||||
# Display the result
|
||||
display.update()
|
||||
```
|
||||
|
||||
PNG files must be small enough to load into RAM for decoding.
|
||||
|
||||
PNGDEC Supports the following PNG types:
|
||||
|
||||
1. True Colour
|
||||
2. True Colour (with Alpha)
|
||||
3. Indexed
|
||||
4. Grayscale
|
||||
|
||||
The arguments for `decode` are as follows:
|
||||
|
||||
1. Decode X - where to place the decoded JPEG on screen
|
||||
2. Decode Y
|
Ładowanie…
Reference in New Issue