Giter Club home page Giter Club logo

svg-path-to-canvas's Introduction

Convert SVG d path to canvas commands

针对一些不支持Path2D API的canvas环境(比如微信小程序),提供将svg path转换成canvas命令的方法。

<script src="https://s4.ssl.qhres.com/!b67dd8e2/svg-path-to-canvas.min.js"></script>
npm install svg-path-to-canvas
const d = 'M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2 c6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z'

const sp = new SvgPath(d)
const [cx, cy] = sp.center

const context = mycanvas.getContext('2d')

sp.save()
  .beginPath()
  .translate(-cx, -cy)
  .rotate(45)
  .scale(10)
  .translate(cx, cy)
  .translate(350, 350)
  .strokeStyle('red')
  .lineWidth(3)
  .to(context)
  .stroke()

svg-path-to-canvas's People

Contributors

akira-cn avatar hamger avatar

Watchers

James Cloos avatar Max 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.