All Projects → spakin → SimpInkScr

spakin / SimpInkScr

Licence: GPL-3.0 license
Simple Inkscape Scripting

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to SimpInkScr

Vxr
General purpose engine written in C++ with emphasis on materials rendering (PBR, clear coat, anisotropy, iridescence)
Stars: ✭ 181 (+35.07%)
Mutual labels:  graphics-programming
Jkqtplotter
an extensive Qt5 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Stars: ✭ 246 (+83.58%)
Mutual labels:  graphics-programming
Real-Time-Rendering-4th-Bibliography-Collection
Real-Time Rendering 4th (RTR4) 参考文献合集典藏 | Collection of <Real-Time Rendering 4th (RTR4)> Bibliography / Reference
Stars: ✭ 2,806 (+1994.03%)
Mutual labels:  graphics-programming
Methanekit
🎲 Modern 3D graphics made simple with cross-platform C++17 meta-API on top of DirectX 12 & Metal (Vulkan is coming)
Stars: ✭ 197 (+47.01%)
Mutual labels:  graphics-programming
Shadered
Lightweight, cross-platform & full-featured shader IDE
Stars: ✭ 3,247 (+2323.13%)
Mutual labels:  graphics-programming
software-development-resources
Collection of links to great software development resources!
Stars: ✭ 20 (-85.07%)
Mutual labels:  graphics-programming
Tinykaboom
A brief computer graphics / rendering course
Stars: ✭ 2,077 (+1450%)
Mutual labels:  graphics-programming
UnityUtils
A library of C# utility classes for Unity
Stars: ✭ 88 (-34.33%)
Mutual labels:  graphics-programming
Arcane Engine
3D C/C++ Game Engine - Created By Brady Jessup
Stars: ✭ 242 (+80.6%)
Mutual labels:  graphics-programming
TerrainRendering
A simple terrain rendering project, with some neat optimizations such as baked lightmaps and fast ambient occclusion with heighmaps.
Stars: ✭ 29 (-78.36%)
Mutual labels:  graphics-programming
Mixture
Mixture is a powerful node-based tool crafted in unity to generate all kinds of textures in realtime
Stars: ✭ 209 (+55.97%)
Mutual labels:  graphics-programming
Vulkano
Safe and rich Rust wrapper around the Vulkan API
Stars: ✭ 2,950 (+2101.49%)
Mutual labels:  graphics-programming
vuo
A realtime visual programming language for interactive media.
Stars: ✭ 103 (-23.13%)
Mutual labels:  graphics-programming
Awesome Unity Shader
⛵ 关于炫酷的Unity3D Shader | About Cool Unity3D Shaders
Stars: ✭ 2,658 (+1883.58%)
Mutual labels:  graphics-programming
Vitro
Experimental C++20 multiplatform graphics engine.
Stars: ✭ 14 (-89.55%)
Mutual labels:  graphics-programming
Aether3d
Aether3D Game Engine
Stars: ✭ 177 (+32.09%)
Mutual labels:  graphics-programming
FreeOberon
Cross-platform IDE for development in Oberon programming language made in the classical FreePascal-like pseudo-graphic style.
Stars: ✭ 102 (-23.88%)
Mutual labels:  graphics-programming
Procedural-Terrain-Generator-OpenGL
Procedural terrain generator with tessellation | C++ OpenGL 4.1
Stars: ✭ 98 (-26.87%)
Mutual labels:  graphics-programming
Kuplung
OpenGL Model Viewer
Stars: ✭ 15 (-88.81%)
Mutual labels:  graphics-programming
baktsiu
An image viewer designed for comparing images and examining pixel differences
Stars: ✭ 22 (-83.58%)
Mutual labels:  graphics-programming

Simple Inkscape Scripting

Description

In the Inkscape vector-drawing program, how would you go about drawing 100 diamonds, each with a random color and placed at a random position on the page?

diamonds

Option 1: Draw, color, and place the diamonds manually. This is exceptionally tedious.

Option 2: Create an Inkscape extension to automate the process. This involves gaining familiarity with a large API and writing a substantial amount of setup code just to perform what ought to be a simple task.

Neither option is particularly enticing. This is why I created the Simple Inkscape Scripting extension for Inkscape. Simple Inkscape Scripting lets you create shapes in the current Inkscape canvas with a Python script plus a set of simple functions such as circle for drawing a circle and rect for drawing a rectangle. The picture shown above was created using just the following five lines of code:

for i in range(100):
    x, y = uniform(0, width), uniform(0, height)
    rect((-5, -5), (5, 5),
         transform='translate(%g, %g) scale(0.75, 1) rotate(45)' % (x, y),
         fill='#%02x%02x%02x' % (randrange(256), randrange(256), randrange(256)))

The first line is an ordinary Python for loop. The second line selects a position for the rectangle. Note that Simple Inkscape Scripting predefines width as the canvas width and height as the canvas height. The random package is imported into the current namespace so uniform can be invoked directly. The third line draws a 10×10 pixel rectangle centered on the origin. The fourth line rotates the rectangle by 45°, squeezes it horizontally into a lozenge, and moves it to the target position. The fifth line specifies a random fill color.

The diamonds drawn on the canvas are all ordinary Inkscape objects and can be further manipulated using any of the usual Inkscape tools.

In short, Simple Inkscape Scripting helps automate repetitive drawing tasks. Unlike writing a custom Inkscape extension, Simple Inkscape Scripting requires sufficiently little boilerplate code as to make its use worthwhile even for tasks that will be performed only once or twice.

Installation

First, identify your Inkscape extensions directory. This can be found in Inkscape's preferences: Go to EditPreferencesSystem and look in the User extensions field. On Linux, the extensions directory is typically $HOME/.config/inkscape/extensions/.

Second, install Simple Inkscape Scripting in that directory or any subdirectory. For example,

cd $HOME/.config/inkscape/extensions/
git clone https://github.com/spakin/SimpInkScr.git

will retrieve the code from GitHub. This later can be updated with

cd $HOME/.config/inkscape/extensions/SimpInkScr/
git pull

If Inkscape is already running, exit and restart it to make it look for new extensions.

Usage

Python code to Inkscape

Launch the Simple Inkscape Scripting extension from Inkscape via ExtensionsRenderSimple Inkscape Scripting…. This will bring up a dialog box that gives you the option to enter a filename for a Python program or enter Python code directly in a text box. These options are not mutually exclusive; if both are used, the Python code in the file will be executed first, followed by the Python code in the text box. This enables one, for example, to define functions in a file and invoke them with different parameters from the text box.

As an initial test, try entering

circle((100, 100), 50)

into the text box and clicking Apply then Close. This should create a black circle of radius 50 at position (100, 100).

Inkscape to Python code

Simple Inkscape Scripting can also save illustrations from the Inkscape GUI to a Python script that, when run from the Simple Inkscape Scripting extension, reproduces the original illustration. (Note, though, that not all Inkscape features are currently supported.) From FileSave a Copy…, simply select Simple Inkscape Scripting script (*.py) from the pull-down menu at the bottom of the dialog box. This can be useful, for instance, for manually drawing a complex object then using Simple Inkscape Scripting to replicate and transform it.

Documentation

Legal

Simple Inkscape Scripting is

Copyright © 2021–2022 Scott Pakin

All code is licensed under the GNU General Public License version 3. See the license file for details.

Author

Scott Pakin, [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].