Skip to content

Commit

Permalink
Split the example usage into two sections
Browse files Browse the repository at this point in the history
Now, the usage section shows how to use both, the Context and the Decorator API.
  • Loading branch information
RossAdrian committed Aug 4, 2024
1 parent f683156 commit 61d7666
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ required to see the magic of the graphics output.

## Usage

After installing, the general usage is as following:
After installing, there are two APIs to use pyframebuffer:

### The pyframebuffer Context API

Here an example snippet:

```py
# Import the library
Expand Down Expand Up @@ -61,6 +65,46 @@ with openfb(framebuffer_number) as fb:
# to the screen. For that, please use the update() function.
```

### The pyframebuffer Decorator API

Here an example snippet aswell:

```py
# Import the library
from pyframebuffer.color import rgb
from pyframebuffer import fbuser

# Create a color to draw with
color_red = rgb(255, 0, 0) # red

# Select a framebuffer to draw on (determined by it's device file number)
framebuffer_number = 0

# Create a framebuffer user function
# becomes the framebuffer object as first argument
@fbuser
def compositor(fb):
# get framebuffer resolution
(xres, yres, depth) = fb.getResolution()

# draw something to the framebuffer
# here: drawing a red pixel in the middle of the screen
xpos = int(xres / 2)
ypos = int(yres / 2)
fb.drawPixel(xpos, ypos, color_red)

# And when the frame is ready, update the framebuffer to become all changes
# visible on the screen
fb.update()

# And now call the framebuffer user function to draw to the framebuffer
compositor(framebuffer_number)

# Yes, the argument to the framebuffer user function is a <int>
# The decorator itself manages the context and make sure that the first argument
# is replaced by the Framebuffer object.
```

## Contributing

See [Contributing Page](./CONTRIBUTING.md) for guidelines and development environment setup.
Expand Down

0 comments on commit 61d7666

Please sign in to comment.