Tag Archives: krita

Lindenmayer brush for Krita

This term i had a course about fractals on the university. We also had to write code for a submission and the lecturer made the technique and topic free to choose. So I chose to make a lindenmayer brush for krita, because I planed to do so since the first university year, where I heard of lindenmayer systems the first time.

I quickly coded something together, so that I was able to prove, that my idea would work.

Lindenmayer systems are some kind of a grammar, they work like this: You have an alphabet of letters, in this case these letters are simple short lines, then you have productions and a rule: Always produce all letters. These productions eat one letter and produce ether no, one or several new letters. There are several classes of such productions, one of the simplest would be “A -> AA”. More sophisticated productions, like in the brush, can contain parameters, if clauses, calculations, random values etc. Basically it would be possible to have several different productions, but I chose to have only one and in turn make it more powerful.

Here is an example of a production, it is used in one of the brushes:

if{letter[branched] == false} {
newLetter = newLetter();
newLetter[position] = variant(letter[endPosition]);
newLetter[angle] = variant(newLetter[angleToSun]);
newLetter[length] = 5;
letter[branched] = bool(true);
}

if{letter[age] > 1} {
letter.delete();
}

It actually creates just a line.

At first the productions were plain C++ code, but that is very cumbersome, as you have to build, install and start krita for testing. The next thing I tried, was to use QtScript and write the productions in ECMAScript (also called JavaScript). It took about 5 to 7 hours until I proved, that it was way to slow.

So I decided to implement my own little scripting language. The interpreter is about 700 lines of code, including some tests. It’s certainly not as powerful, as ECMAScript, but it’s fast and okayish for this use case.

There is an if clause, which supports &&, there is a rand() function, a function for mixing angles, some very basic math, bool and float data types, you can create new letters and delete old ones. It’s possible to write new parameters (“branched” in the code above), edit some default ones (position, angle, length..), which will be used for drawing and access some computed ones (endPosition, angleToSun, distanceToSun, age..).

I have to write some documentation, expand the possibilities of the language and work on the configuration interface. But for now you can already test the current code, it’s in the krita-lbrush-adamc branch in the calligra repository.

Here is a final picture..

The presets for this brushes are included in the repository ๐Ÿ™‚

Krita GSoC: Colour selectors with Colourspaces support

Hi,
my last post was long ago, the reason were my exams which ended a week ago and which forced me to do some learning. But in the past week I started working on Krita again.

All selector types from this site are implemented now. All of them support colour spaces, which is important, if using cmyk. There is quite a difference in what you are probably used to, as you can see here:
colour selector types

This is of course still work in progress. I plan to change the layout of the selectors dynamically according to the space provided. For instance the horizontal slider of the wheel selector will be a vertical one, if the width is greater than the height. This way the widget will be very space efficient.

I also made the MyPaint shade selector colour space aware. Here is a direct comparison between cmyk at the top and rgb at the bottom.
my paint selector, cmyk and rgb
As you probably see, this widget is not antialiased. It’s not as simple as setting a flag in Qt, but during programming the standard selectors, I’ve learned, how to make it antialiased. So in the final version there will certainly be a MyPaint selector with antialiased edges. If I have time, I will also happily implement some of these ideas.

Krita GSoC: Layouting code for colour selector mostly done

One of my goals in my project was to create a colour selector, which has many features but uses little space. However it’s hard to select a colour, if the chooser is small, because 1. it’s small and 2. a small chooser with view pixels cannot show all colours.

I approached this from two sides: a space efficient and configurable layout, so that the user can select whichever size fits him best and an optional zoom, so that the user can make the widget small and yet simply make the chooser bigger, if he needs it.

Edit2:
The colour patches below the selectors represent common colours from the image and on the right there will be a history of last used colours..

So here are some screenshots, on how it looks like currently.
This is a ‘big’ layout,
'big' layout

‘small’ and space efficient,
'small', horizontal layout

a popup with a bigger selector,
popup (zoom)

and finally a page from the settings window.
a page from the settings window

Not all of the settings are connected already, the colour selector (triangle in the images) is just a dummy and the whole thing is not connected to the painting colour.
But I hope to get some comments on the layouting, maybe some more ideas and so on. I’ve just enabled building of this plugin in trunk, if you want to test it, you probably also have to enable this docker in settings menu -> dockers -> Color Selector Ng.

Edit:
This is still work in progress, next steps will be to gather some comments on usability, refine layouting and move on to implement pigment, colour selectors and so on. It’s not even half time of GSoC ๐Ÿ™‚

Krita GSoC: Implemented algorithm for extracting colours and ported MyPaint algorithm for shade selector

Hi,
i’ve implemented an algorithm to extract the most important colours of an image. Here is an example of what it does:

Here are more examples

The algorithm is a slightly modified version of median cut and it is quite the same as the one used in JFIF jpeg library for reducing colours and indexing images. There is a quite good and easy to understand paper from leptonica on this topic. Thanks to pippin for guiding me to median cut ๐Ÿ˜‰ .

I also ported the shade selector algorithm from MyPaint to Krita. This is already a docker in Krita, but it isn’t connected yet:
.

Also, Pigment is not yet used, which is important to support colour spaces properly. Anyway, the next step will be to implement all widgets with dummy graphics, so Pigment and connection must wait.

My Krita GSoC 2010

The title of my project isย “New Colour Choosers for Krita and Karbon”.

This sounds like an easy task – maybe it is, but it’s much work nevertheless. I won’t deliver only ordinary colour choosers, they will support colour spaces, various types (see here), harmonic colours, shades of current colours, shades of the current image and zoom for an accurate selection. If you are interested, here you can download the application for GSoC (including some mockups).

According to the time line the first task is ย to “Outline algorithms for drawing selector, computing shades and common colours”. To do this i will look at the existing selector of Krita and at MyPaint. Probably computing common colours will be the most interesting and most challenging part of this.