Giter Club home page Giter Club logo

framer-path's Introduction

Create custom svg shapes and animate each point individually in Framer JS.

Can be useful for:

  • Creating arrays of points with quick math expressions
  • Animated graphs & statistics
  • Simple animated icons
  • Fluid shapes

How to install:

  1. Download the 'Path.coffee' file to your project /modules/ folder
  2. Copy this line of code to the framer studio:
{Path} = require "Path"

New layer


p = new Path

    strokeWidth: 1

    pointVisible: true
    handleVisible: true

    pointSize: 6
    handleSize: 2

    fill: "#e8e9ff"
    pointColor: "blue"
    handleColor: "blue"
    strokeColor: "blue"

Path class is an extended layer class, so you can use most of the layer properties, as well as events with it.


p = new Path

     width: 300
     height: 300

     backgroundColor: "red"

p.center()

New points

Currently, this module supports only straight, quadratic and cubic bezier points.


p.path.point x: 30, y: 30
p.path.point x: 130, y: 30

Quadratic bezier is a curve with only one handle:


p.path.point x: 30, y: 30

p.path.quadratic
    x: 60, y: 60
    qx: 120, qy: 60

Cubic bezier has two handles:


p.path.point x: 30, y: 30

p.path.cubic
    x: 30, y: 60
    cx1: 120, cy1: 30
    cx2: 120, cy2: 60

If you want to use straight points after bezier, you need to use special closing point:


p.path.point x: 30, y: 30

p.path.quadratic
    x: 60, y: 60
    qx: 120, qy: 60

p.path.close x: 180, y: 60

Animation

To animate a value, add states to the point you want to animate and then run the animation with path.animate() function.

p.path.point x: 30, y: 30
p.path.point
     x: 130, y: 30
     states:
          x: 160, y: 60

p.path.animate()

You can add unlimited amount of states by using array instead of integer. The array lengths of x and y should always be equal.


p.path.point x: 30, y: 30
p.path.point
     x: 130, y: 30
     states:
          x: [160, 180, 200]
          y: [60, 80, 100]

p.path.animate()

There are two different modes of animating the points, ’animation’ and ’states’. The default value is set as ’states’. As position of the point is based on position of the point layer (even when it’s not visible), ’animation’ mode allows you to play different tricks such as updating the value of point on the go:


rdm = -> return Utils.randomNumber(30, 80)

p.path.point x: 30, y: 30
p.path.point
     x: 130, y: 30
     states:
          x: -> rdm()
          y: -> rdm()

Utils.interval 0.75, -> p.path.animate("animation")

Note that ’animation’ mode won’t work with states arrays.

You can add animation options in a traditional way:


p.path.animationOptions =
     time: 0.75
     curve: “spring"

Be aware that

  • Any kind of path should always start with simple point.
  • path.animationOptions should be assigned before you create any points
  • The path module alters the layer.html value, that’s how animation happens, so if you want to change layer.html, it’s better create new parent layer

Examples

Animated graph

http://share.framerjs.com/w27sxwwsn1rw/

Blend shapes

http://share.framerjs.com/j6977iinxa65/

Drawing tool

http://share.framerjs.com/2kfa8aoiw2jo/

framer-path's People

Contributors

slitrobo avatar

Watchers

James Cloos avatar Jungho Song avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.