Coder Social home page Coder Social logo

penkit's Introduction

Penkit

Penkit is a library of utility functions generating pen plots from Python/numpy.

Installation

Requirements: Python 2.7 or 3.x, numpy, scipy. Preview modules require ipython or matplotlib.

# pip install penkit

Documentation

Examples

Grid Surface Projection

from penkit.textures import make_grid_texture
from penkit.textures.util import rotate_texture
from penkit.surfaces import make_noise_surface
from penkit.write import write_plot
from penkit.projection import project_and_occlude_texture

# create a texture
grid_density = 68
texture = make_grid_texture(grid_density, grid_density, 100)

# rotate the texture
texture = rotate_texture(texture, rotation=65)

# create the surface
surface = make_noise_surface(blur=28, seed=12345) * 10

# project the texture onto the surface
proj = project_and_occlude_texture(texture, surface, angle=69)

# plot the result
write_plot([proj], 'examples/grid_surface.svg')

Hilbert Curve Surface Projection

from penkit.fractal import hilbert_curve
from penkit.textures.util import fit_texture, rotate_texture
from penkit.surfaces import make_noise_surface
from penkit.projection import project_and_occlude_texture
from penkit.write import write_plot

# create a texture
texture = hilbert_curve(7)

# rotate the texture
texture = rotate_texture(texture, 30)
texture = fit_texture(texture)

# create the surface
surface = make_noise_surface(blur=30) * 5

# project the texture onto the surface
proj = project_and_occlude_texture(texture, surface, 50)

# plot the result
write_plot([proj], 'examples/hilbert_surface.svg')


https://travis-ci.org/paulgb/penkit.svg?branch=master

penkit's People

Contributors

djma avatar lr1729 avatar paulgb avatar the-metalgamer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

penkit's Issues

Text in SVG - the result is mirror-inverted

Good Morning

This is more a note than an issue,
therefore I selected an issue title which describes the visible result so it hopefully gets found by other users who have similar results.

Thank you very much!

for sharing your knowledge in your Blog and your source code!,
it is always amazing to see how mathematicians miraculously simplify complex problems and develop solutions with surprisingly few lines of code.
Even your SVG drawing visualizer is great and the result can be interpreted very fast.

The issue: penkit-optimize removes the source file <svg …> and <g transform=…> elements

I tried to use penkit-optimize with AxiDraw, the handwriting machine to optimize one page filled with Text (which was converted from the TTF outline Text to Single Stroke with created 2650 SVG Path elements) and the result is great:

InitialCost / GreedyCost = 19.47
InitialCost / VRPOptimizationCost = 22.05
Plotting time of the example below: 06:55 reduced to 01:51. Amazing.

Unfortunately, the result is mirror-inverted.

Ex - penkit-optimize - Text, John C  Lennox, Original vs Optimized

I've analyzed the issue and found that penkit-optimize removes the original <svg …> and <g transform=…> elements. My source file (from Inkscape) has this SVG definition:

<svg xmlns="http://www.w3.org/2000/svg" 
  width="210.000000mm" height="297.000000mm" 
  viewBox="0.000000 -0.000000 9921.000000 14031.000000">
  <g transform="matrix(1,0,0,-1,0,14031.000000)">

Because the source uses <g transform=…> and penkit-optimize removes those elements, the result is mirrored.

Yesterday I tried to fix it and to make penkit-optimize compatible with the latest Google OR-Tools 7.3, but failed to start your Python Package from the command line :-(.
Starting Python scripts is often a big annoyance for non Python developers. Because I don't know Python, I probably wouldn't have reached my goal within a useful time anyway.

RuntimeError: SWIG std::function invocation failed.

Hitting an error whenever i'm not using greedy:

Initial cost: 1175670.59166
Cost after greedy optimization: 51105.4291514
Traceback (most recent call last):
  File "/usr/local/bin/penkit-optimize", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/penkit_optimize/cli.py", line 79, in main
    run_optimizer(**vars(args))
  File "/usr/local/lib/python2.7/site-packages/penkit_optimize/cli.py", line 33, in run_optimizer
    vrp_solution = vrp_solver(path_graph, greedy_solution, runtime)
  File "/usr/local/lib/python2.7/site-packages/penkit_optimize/vrp_solver.py", line 58, in vrp_solver
    search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()
RuntimeError: SWIG std::function invocation failed.

Any ideas to why invocation failed?

How can I define stroke width?

I want to generate an SVG to an A4 page with a stroke of 0.1mm

I can set the page with something like
write_plot([proj], name, unit='mm', width=297.0, height=210.0)

But how can I set the stroke?

TypeError: Wrong number or type of arguments

I am on win 10, and I'm getting:

TypeError: Wrong number or type of arguments for overloaded function 'new_RoutingModel'.
  Possible C/C++ prototypes are:
    operations_research::RoutingModel::RoutingModel(operations_research::RoutingIndexManager const &)
    operations_research::RoutingModel::RoutingModel(operations_research::RoutingIndexManager const &,operations_research::RoutingModelParameters const &)

Any suggestions?
Thanks

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.