Giter Site home page Giter Site logo

How to get the new path about ipycanvas HOT 7 OPEN

zhenzi0322 avatar zhenzi0322 commented on May 29, 2024
How to get the new path

from ipycanvas.

Comments (7)

martinRenou avatar martinRenou commented on May 29, 2024

Can you please elaborate on this issue?

from ipycanvas.

zhenzi0322 avatar zhenzi0322 commented on May 29, 2024
from ipycanvas import Canvas, Path2D

canvas = Canvas(width=350, height=350)

path1 = Path2D("M80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 Z")

canvas.fill_style = "green"
canvas.fill(path1)
# Get the new path
print(canvas.get_path())

I want to get the path2d of the canvas by getting

from ipycanvas.

zhenzi0322 avatar zhenzi0322 commented on May 29, 2024

Or save it as a new svg. svg format There are

<svg xmlns="http://www.w3.org/2000/svg" width="341.333333" height="341.333333" version="1.0" viewBox="0 0 256 256">
    <path d="M74.9 3...."/>
</svg>

from ipycanvas.

martinRenou avatar martinRenou commented on May 29, 2024

You have full knowledge of the path you've given to the fill method, so you know what your hypothetical get_path method would return here, is that correct?

If what you want is to save your Path as SVG, then ipycanvas is of no help, as it does not produce any SVG.

You might want to check out this library https://github.com/cduck/drawSvg

from ipycanvas.

zhenzi0322 avatar zhenzi0322 commented on May 29, 2024

Yes. I just want to get the new path2d

from ipycanvas.

martinRenou avatar martinRenou commented on May 29, 2024

What I mean is you have it already, it's path1. Or am I missing something?

from ipycanvas.

zhenzi0322 avatar zhenzi0322 commented on May 29, 2024

I am trying to put the following svg:

<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
 width="128.000000pt" height="128.000000pt" viewBox="0 0 128.000000 128.000000"
 preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,128.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M546 965 c-53 -19 -101 -68 -137 -140 -27 -55 -28 -60 -12 -67 50
-19 70 -10 102 47 17 30 40 59 52 66 121 64 239 -15 215 -145 -10 -52 -53 -92
-122 -111 -71 -21 -78 -27 -71 -57 5 -18 17 -26 57 -35 29 -7 67 -22 85 -33
83 -52 87 -185 6 -253 -83 -69 -207 -27 -250 86 -10 26 -13 27 -53 21 -24 -4
-45 -8 -47 -10 -8 -7 30 -99 54 -130 57 -75 181 -112 280 -85 105 28 178 128
178 245 0 91 -35 152 -111 195 -15 9 -12 14 20 41 50 42 78 103 78 174 0 94
-50 165 -139 195 -46 15 -137 13 -185 -4z"/>
</g>
</svg>

Convert to svg with only one node path in.

<svg xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 128 128">
    <path d="M74.9 32.7c0 .5-.2 1.5-.5 2.3-1.6 6.1-1.6 7 0 7 2.1 0 2 1-.1 4-1.7 2.4-3.6 15-2.2 15 .3 0 1.6-1.1 2.9-2.5 2.5-2.7 4.5-2.4 3.7.6-.3 1 .1 2.6.9 3.6.7 1 1.4 2.1 1.4 2.6 0 .9-8xxx..."/>
</svg>

CaCan't ipycanvas get the path2d data?n't ipycanvas get the path2d data?

Example:

from ipycanvas import Canvas, Path2D

canvas = Canvas(width=128, height=128)
canvas.translate(0, 128)
canvas.scale(0.10, -0.10)
canvas.fill_style = "#000000"
path = Path2D("M546 965 c-53 -19 -101 -68 -137 -140 -27 -55 -28 -60 -12 -67 50 -19 70 -10 102 47 17 30 40 59 52 66 121 64 239 -15 215 -145 -10 -52 -53 -92 -122 -111 -71 -21 -78 -27 -71 -57 5 -18 17 -26 57 -35 29 -7 67 -22 85 -33 83 -52 87 -185 6 -253 -83 -69 -207 -27 -250 86 -10 26 -13 27 -53 21 -24 -4 -45 -8 -47 -10 -8 -7 30 -99 54 -130 57 -75 181 -112 280 -85 105 28 178 128 178 245 0 91 -35 152 -111 195 -15 9 -12 14 20 41 50 42 78 103 78 174 0 94 -50 165 -139 195 -46 15 -137 13 -185 -4z")

canvas.fill(path)
# Get the new path
print(canvas.get_path())

from ipycanvas.

Related Issues (20)

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.