Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • F firmware
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Graph
    • Compare revisions
  • Issues 74
    • Issues 74
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 29
    • Merge requests 29
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • External wiki
    • External wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • card10card10
  • firmware
  • Merge requests
  • !507

Draft: "User-space" CTX

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Rahix requested to merge rahix/user-space-ctx into master Dec 28, 2021
  • Overview 2
  • Commits 4
  • Pipelines 6
  • Changes 12

Add python API for CTX vector graphics. This is a work-in-progress!!!

There is still lot's missing, see the todo list below. That said, I've opened this PR so people can start playing with CTX on card10. You can download a card10.bin for this MR from the "Exposed Artifacts" under the CI pipeline below. Documentation is null at the moment, but you can probably get quite far by reading the HTML5 Canvas Docs and consulting

import ctx_graphics
for e in dir(ctx_graphics.Ctx): print(e)

on card10 for method and constant names.

As a kick-start, here is some example code:

import ctx_graphics, display, color

ctx = ctx_graphics.Ctx()

# Global Settings
ctx.line_width(5)
ctx.line_cap(ctx.CAP_ROUND)
ctx.line_join(ctx.JOIN_ROUND)
ctx.font_size(30)
ctx.font("ctx-mono")
ctx.text_align(ctx.TEXT_ALIGN_CENTER)
ctx.text_baseline(ctx.TEXT_BASELINE_MIDDLE)

with display.open() as d:
    d.clear()
    ctx.save()

    # Some Lines with nice joints
    ctx.stroke_color(color.CHAOSBLUE)
    ctx.move_to(10, 10).line_to(10, 70).line_to(150, 70).line_to(150, 10).stroke()

    # Draw a rectangle which perfectly fits the text
    width = ctx.text_width("Hello CTX!") + 4
    ctx.color(color.WHITE).rectangle(80 - width / 2, 20, width, 40).fill()

    # Draw some text!
    ctx.color(color.CAMPGREEN).fill_text("Hello CTX!", 80, 40)

    ctx.restore()
    ctx.update(d)
    d.update()

TODO

  • Finish covering relevant API surface
  • Implement alpha for color functions
  • Take colors in many formats
  • Cleanup the CTX when the python object gets garbage collected
  • Improve API ergonomics
Edited Dec 28, 2021 by Rahix
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: rahix/user-space-ctx