A quick, very very work-in-progress redux of p5py. Lets you draw with Skia in Python in a Processing-style way, with many functions borrowed from p5py's skia renderer. You probably shouldn't use this yet.
- simple, p5/processing-like api for skia
- more "pythony" than p5py, and exposes more skia stuff
- good for exporting animation as video files, images, and pdfs suitable for printing
- can be headless
- user interaction (mouse/keyboard/etc)
- audio
Drawing
from easyskia import Canvas
c = Canvas(width=600, height=600, show=True)
x = 0
while c.animate():
c.background(1, 1, 1)
c.fill(1, 0, 0)
c.stroke(0, 1, 0)
c.ellipse(x, 100, 50, 50)
x = x + 1
Saving videos
from easyskia import Canvas
c = Canvas(width=600, height=600, show=False)
c.save_video("testing.mp4", frames=200)
x = 0
while c.animate():
c.background(1, 1, 1)
c.fill(1, 0, 0)
c.stroke(0, 1, 0)
c.ellipse(x, 100, 50, 50)
x = x + 1
Exporting PDFs
from easyskia import Canvas
c = Canvas(width=600, height=600, renderer="PDF", output="testing.pdf")
c.background(1, 1, 1)
c.rect(100, 100, 120, 150)
c.add_page()
c.rect(200, 200, 90, 90)
c.save_pdf()
- easyskia.canvas
- Canvas
- __init__
- setup_raster
- setup_pdf
- setup_gl
- background
- clear
- fill
- stroke
- stroke_weight
- no_fill
- no_stroke
- text_font
- text_size
- text_style
- line
- ellipse
- circle
- quad
- rect
- triangle
- text
- load_font
- load_image
- image
- animate
- add_page
- render
- push
- pop
- translate
- rotate
- scale
- save
- save_frame
- save_pdf
- save_video
- save_video_frame
- finish_video
- Canvas
class Canvas()
def __init__(width: int = DEFAULT_WIDTH,
height: int = DEFAULT_HEIGHT,
show: bool = False,
renderer: str = "GPU",
title: str = "EasySkia",
output: Optional[str] = None)
Create a canvas
Arguments:
width
int - width of canvasheight
int - height of canvasshow
bool - show the canvasrenderer
str - renderer to use (GPU, CPU, PDF)title
str - title of windowoutput
str - output path for PDF renderer
def setup_raster()
Setup a raster canvas
def setup_pdf(output: str)
Setup a PDF canvas
Arguments:
output
str - output path
def setup_gl()
Setup a GPU canvas
def background(r: float, g: float, b: float, a=1.0)
Set the background color
Arguments:
r
float - red valueg
float - green valueb
float - blue valuea
float - alpha value (default: 1.0)
def clear()
Clear the canvas
def fill(r: float, g: float, b: float, a: float = 1.0)
Set the fill color
Arguments:
r
float - red valueg
float - green valueb
float - blue valuea
float - alpha value (default: 1.0)
def stroke(r: float, g: float, b: float, a: float = 1.0)
Set the stroke color
Arguments:
r
float - red valueg
float - green valueb
float - blue valuea
float - alpha value (default: 1.0)
def stroke_weight(w: float)
Set the stroke weight
Arguments:
w
float - stroke weight
def no_fill()
Disable fill
def no_stroke()
Disable stroke
def text_font(fontname: str)
Set the text font
Arguments:
fontname
str - font name
def text_size(size: float)
Set the text size
Arguments:
size
float - font size
def text_style(s: str)
Set the text style
Arguments:
s
str - text style
def line(x1: float, y1: float, x2: float, y2: float)
Draw a line
Arguments:
x1
float - x1y1
float - y1x2
float - x2y2
float - y2
def ellipse(x: float, y: float, w: float, h: float)
Draw an ellipse
Arguments:
x
float - xy
float - yw
float - widthh
float - height
def circle(x: float, y: float, d: float)
Draw a circle
Arguments:
x
float - xy
float - yd
float - diameter
def quad(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float,
x4: float, y4: float)
Draw a quad
Arguments:
x1
float - x1y1
float - y1x2
float - x2y2
float - y2x3
float - x3y3
float - y3x4
float - x4y4
float - y4
def rect(x: float,
y: float,
w: float,
h: float,
tl: Optional[float] = None,
tr: Optional[float] = None,
br: Optional[float] = None,
bl: Optional[float] = None)
Draw a rectangle
Arguments:
x
float - xy
float - yw
float - widthh
float - heighttl
float - top left corner radiustr
float - top right corner radiusbr
float - bottom right corner radiusbl
float - bottom left corner radius
def triangle(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float)
Draw a triangle
Arguments:
x1
float - x1y1
float - y1x2
float - x2y2
float - y2x3
float - x3y3
float - y3
def text(text: str, x: float, y: float)
Draw text
Arguments:
text
str - text to drawx
float - xy
float - y
def load_font(path: str) -> skia.Typeface
Load a font
Arguments:
path
str - path to font file
def load_image(path: str) -> skia.Image
Load an image
Arguments:
path
str - path to image file
def image(image: skia.Image,
x: float,
y: float,
w: Optional[float] = None,
h: Optional[float] = None)
Draw an image
Arguments:
image
skia.Image - image to drawx
float - xy
float - yw
float - widthh
float - height
def animate()
Animate the canvas
def add_page(width: Optional[float] = None, height: Optional[float] = None)
Add a page to a PDF canvas
Arguments:
width
float - width of pageheight
float - height of page
def render(rewind=True)
Render the shape/image/text etc to the canvas
def push()
Push the canvas state
def pop()
Pop the canvas state
def translate(x: float, y: float)
Translate the canvas
Arguments:
x
float - xy
float - y
def rotate(deg: float)
Rotate the canvas
Arguments:
deg
float - degrees to rotate
def scale(sx: float, sy: Optional[float] = None)
Scale the canvas
Arguments:
sx
float - x scalesy
float - y scale
def save(filename: str = "frame.png")
Save the canvas to a file
Arguments:
filename
str - filename to save to
def save_frame(filename: Optional[str] = None)
Save a frame. If filename is None, it will be named frame_0000000000.jpg
Arguments:
filename
str - filename to save to
def save_pdf()
Save the PDF canvas
def save_video(filename: str = "sketch.mp4",
fps: int = 60,
max_frames: int = 0)
Save a video
Arguments:
filename
str - filename to save tofps
float - frames per secondmax_frames
int - maximum number of frames to record
def save_video_frame()
Save a video frame
def finish_video()
Finish recording a video