Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

[VB6] Cairo BRUSH

$
0
0
I present the class I have named cCairoBrush.
It is not entirely complete, in fact initially I had thought of not posting it in CodeBank, but then I changed my mind because it seemed good enough and interesting enough.

What is it about?
The class is for drawing fairly advanced strokes.

Cairo in RC6 is very complete and implements for example these types of "strokes":




I found myself in need of a tool to draw something more advanced than this last image. I built the class cCairoBrush.

In the first stage it more or less replicated Cairo's cc.Polygon.


The curve is defined by a sequence of points (Addable via BRUSH.Addpoint)

This was achieved by automatically computing the control points between the nodal points by bringing this code into VB6:
"Draw a Smooth Curve through a Set of 2D Points with Bezier Primitives."



Sucessively I made each dot/knot have in its own color, and from one dot to another there was a gentle transition of color.



In addition to the color transition there can also be opacity transition (alpha) defined at each nodal point.



Then I added another property to each node that I called Radius , maybe half width would be more correct.




Finally I added another property, which is the outer (boundary) opacity. (Called BorderAlpha)

However, this still does not work very well , in fact you can see a darker curve centrally (a spine) that is not very pleasing.


The code was written quite hastily, so perhaps it is a bit convoluted but I think it may be of interest.


For example in these videos you can see my use of it:





Final Notes:
- To draw such "complex" curves, I have intensively used the cCairoPattern classes as explained in this example:
https://www.vbforums.com/showthread....=1#post5540317

You can see on the left how it is possible to draw a patch with four curves and four corners of different colors.

When there is no BorderAlpha (BorderAlpha =1) each curve between two nodal points is drawn with 1 of these patches.
When BorderAlpha is present (BorderAlpha <>1), each curve between two nodal points takes 2 Pieces, one on one side and one on the other.

The code ( and subsequent updates of mine) is on GitHub
DOWNLOAD here: https://github.com/miorsoft/VB6-cCairoBrush

Aesthetic improvements to the final result and/or speedup of execution made by others will be appreciated.

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>