(Almost) Auto-generate colors

On March 8th, I had an implementation of automated drawing of surfaces with splines - why not write an article with colors.

It turned out something like this:



There will be more under the cut, take care of the traffic.

The algorithm that makes cubic curves has been described previously . Here we will try to apply it to get something floral-like. The only problem is how to select the input data.
The input data is a set of points with coordinates in three-dimensional space and a set of connections between them, such that topologically this design should be equivalent to a box, such as this:



(at the end it should be like this :)



So that the cubic surfaces when tensioned on the core look like a flower , it is necessary to arrange the points symmetrically on the circles circumscribed around the center of the flower. To solve this problem, a variation of “breadth-first search” was applied.

Assign to all points of weight. First, we assign the weights 0 and 1 to the extreme points (two identical weights should not be near). These will be the edges of the “petals”, 0 - the far, 1 - the nearest (“petals” in quotation marks, because there is no division into petals as such). Weigh further by assigning weight n + 2 to unweighted neighbors with weight n.

Weighted box:



Next, randomly select the distance r from the center of the flower for each weight category.
The logic here is the following: the greater the weight, the closer the point will need to be moved to the center, and inequalities should be fulfilled:

r0>r2>r4>...>r2n;  r1>r3>...>r2n+1;  r0>r1


where r is the distance from the center of the flower to points with the corresponding weight. Even weights are responsible for the central part of the “petal”, odd weights are responsible for the edges of the “petal”.

In order to arrange points on circles (and not on spheres), we also have to randomly select z-coordinates in such a way that z_n <r_n (if the center of the flower is at coordinate zero).



In the next step, we need to know the angles for the location of points on the circle:

ewithland mn-toaboutlandhewithtatabout taboutheto with atewithaboutm n,tabout αn=2π/mn


and then the coordinates for the i-th point of weight n, if it is even:

xi=rn2-zn2cos(iαn)


yi=rn2-zn2sin(iαn)


for odd:

xi=rn2-zn2cos(iαn+αn/2)


yi=rn2-zn2sin(iαn+αn/2)


In addition, the order in which we take the points is important - they must be “neighbors”.



After all these manipulations, a star-shaped structure is obtained on which splines can be pulled.

(top view, isometry, splines)





Such sepals can be randomized to 100,500, but to select suitable ones, to make several flowers, to select colors and core parameters better manually, therefore, the generation is semi-automatic.

(view of assembly software)













Congratulations on the International Women's Day to the beautiful half of the habrasociety! I hope you were beautiful.

All Articles