A (hopefully) helpful start for the quality seexprt script:
Script
# Basic usage of the inbuilt seexpr voronoi function.
# This just exposes each of the variables in the voronoi function for editing. Also adds rotation and scaling.
# UV vector manipulation
# ----------------------
# Construction of the UV vector. $u and $v are the normalized x and y coordinates for the image. This gives non-square results by default, so we calculate the ratio and then multiply the relevant dimension with said ratio to get a square result from the algorithms.
# The zCoordinate can be set manually in many of the inbuilt noise functions, as these produce 3d noise, but we have a 2d plane. So allowing people to manipulate the last dimension manually allows them to access other slices of the 3d noise.
$ratio = $h/$w;
$zCoord = 0; #0.0, 1.0
$uv = [$u, $v*$ratio, zCoord];
# We multiply the subdivisions with the uv vector to give a sense of zooming out.
$subdivisions = 10; # 1, 100;
$uv *= $subdivisions;
# We also rotate the uv coordinate around the z-axis, [0,0,1].
$rotation = 0; #0, 359;
$uv = rotate($uv, [0,0,1], rad(rotation));
# Voronoi Function
# ----------------
# The type of voronoi algorithm as explain in the manual.
$type = 1; #1, 5
# The jitter, low jitter gives almost grid like appearance, high jitter a
$jitter = 1; #0.0, 1.0
# Some variables for introducing some fractal brownian motion into the voronoi cells.
# The strength of the FBM effect.
$fbmScale = 0;
# Controls the frequencies.
$fbmOctaves = 4; #0, 10
# Spacing between the frequencies - a value of 2 means each octave is twice the previous frequency.
$fbmLacunarity = 2; #0, 10;
# controls how much each frequency is scaled relative to the previous frequency.
$fbmGain = 0.5; #0, 10.0
# Finally we input all the variables into the function to get a factor.
$directionForCell = cvoronoi($uv, $type, $jitter, $fbmScale, $fbmOctaves, $fbmLacunarity, $fbmGain);
# Color
# -----
# We put the factor into a gradient to get the color.
#$color = ccurve($fac,0,[0.141,0.059,0.051],4,0.709957,[1,1,0],4,1,[0.976,0.976,0.976],4,0.212121,[0.333333,0,0],4,0.519481,[1,0.333333,0],4);
$lineColor = [0,0,0];
$backgroundColor = [1,1,1];
# ok, so we have u and v
# we need lines in a specific direction
# let's say, first line
# with offset from the first
$diff = [0.12,0.12,0.1]; # 0.0, 1.0
# offset = direction from the cvoronoi
# first rotate the uv to by $directionForCell to get a random rotation of the lines
$rotaHere = ($directionForCell[0] + $directionForCell[1] + $directionForCell[1])/3*360;
$uv = rotate($uv, [0,0,1], rad($rotaHere));
# then check for lines
# subtract $directionForCell to get a random offset
$newuv = $uv - $directionForCell;
# now check the difference from this pixel to the desired lines (distances between lines are in "diff" variable)
$mult = [floor($newuv[0]/$diff[0]), floor($newuv[1]/$diff[1])];
$newuv = [$newuv[0] - $mult[0]*$diff[0], $newuv[1] - $mult[1]*$diff[1]];
# not perfect because it only checks for one side, and there is no anti-aliasing, could be better to use a gradient and check for abs, but whatever
$color = $backgroundColor;
if ($newuv[0] < 0.01)
{
$color = $lineColor;
}
if ($newuv[1] < 0.01)
{
$color = $lineColor;
}
# return the color.
$color
The result is very obviously not ideal now:
What probably needs to be done:
- overlapping on edges (could be done by checking neighbouring pixels for other voronoi cells, and calculating lines for them, too)
- a third line to get a higher density
- possibility to turn off second (and third, if implemented) line from the settings
- possibility to have different angles between the first, second and third lines (if needed)
- antialiasing and considering both sides of the lines
About the script:
- it was made on a base of @wolthera 's voronoi script
- the important part starts from the “cvoronoi” call; the previous ones are just to make nice toggles for the user to make the cells bigger, smaller, rotate them, get a different random result etc.
- I added comments which hopefully will help you understand it (note: nearly all comments before
cvoronoi
call are Wolthera’s, not mine)