View Source Scenic.Primitive.Path (Scenic v0.11.2)

Draw a complex path on the screen described by a list of actions.

data

Data

list_of_commands

The data for a path is a list of commands. They are interpreted in order when the path is drawn. See below for the commands it will accept.

styles

Styles

This primitive recognizes the following styles

  • hidden - show or hide the primitive
  • scissor - "scissor rectangle" that drawing will be clipped to.
  • fill - fill in the area of the primitive
  • stroke - stroke the outline of the primitive. In this case, only the curvy part.
  • cap - says how to draw the ends of the line.
  • join - control how segments are joined.
  • miter_limit - control how segments are joined.

commands

Commands

  • :begin - start a new path segment
  • :close_path - draw a line back to the start of the current segment
  • {:move_to, x, y} - move the current draw position
  • {:line_to, x, y} - draw a line from the current position to a new location.
  • {:bezier_to, c1x, c1y, c2x, c2y, x, y} - draw a bezier curve from the current position to a new location.
  • {:quadratic_to, cx, cy, x, y} - draw a quadratic curve from the current position to a new location.
  • {:arc_to, x1, y1, x2, y2, radius} - draw an arc from the current position to a new location.

path-vs-script

Path vs. Script

Both the Path and the Script primitives use the Scenic.Script to create scripts that are sent to the driver for drawing. The difference is that a Path is far more limited in what it can do, and is inserted inline with the compiled graph that created it.

The script primitive, on the other hand, has full access to the API set of Scenic.Script and accesses scripts by reference.

The inline vs. reference difference is important. A simple path will consume fewer resources. BUT it will cause the entire graph to be recompiled and resent to the driver if you change it.

A script primitive references a script that you create separately from the graph. This means that any changes to the graph (such as an animation) will NOT need to recompile or resend the script.

usage

Usage

You should add/modify primitives via the helper functions in Scenic.Primitives

graph
  |> path( [
      :begin,
      {:move_to, 0, 0},
      {:bezier_to, 0, 20, 0, 50, 40, 50},
      {:line_to, 30, 60},
      :close_path
    ],
    fill: :blue
  )

Link to this section Summary

Functions

Compile the data for this primitive into a mini script. This can be combined with others to generate a larger script and is called when a graph is compiled.

Returns a list of styles recognized by this primitive.

Link to this section Types

@type cmd() ::
  :begin
  | :close_path
  | {:move_to, x :: number(), y :: number()}
  | {:line_to, x :: number(), y :: number()}
  | {:bezier_to, c1x :: number(), c1y :: number(), c2x :: number(),
     c2y :: number(), x :: number(), y :: number()}
  | {:quadratic_to, cx :: number(), cy :: number(), x :: number(),
     y :: number()}
  | {:arc_to, x1 :: number(), y1 :: number(), x2 :: number(), y2 :: number(),
     radius :: number()}
@type styles_t() :: [
  :hidden
  | :scissor
  | :fill
  | :stroke_width
  | :stroke_fill
  | :cap
  | :join
  | :miter_limit
]
@type t() :: [cmd()]

Link to this section Functions

Link to this function

compile(primitive, styles)

View Source
@spec compile(primitive :: Scenic.Primitive.t(), styles :: Scenic.Primitive.Style.t()) ::
  Scenic.Script.t()

Compile the data for this primitive into a mini script. This can be combined with others to generate a larger script and is called when a graph is compiled.

Note: Path is a "Meta" primitive. It isn't really a primitive that is represented in a draw script. Instead, it generates it's own mini-script, which is included inline to the graph it is contained in.

Note: The compiled script is backwards. This is an inline script, which means it is inserted into a larger script as part of the graph compile process and Script.finish() will be called on that later.

@spec valid_styles() :: styles_t()

Returns a list of styles recognized by this primitive.