Procedural texture generator (example and wishes)

I’ve found it:

## CC-BY copyright @tiar@krita-artists.org

$a = 100; # 5, 1000
$thickness = 10; # 1, 50

$direction = 0; # 0, 1
$border = [0.533333,0.215686,0.152941];
$background = [1,1,1];

# for ease of use later
$th = $thickness/2;


# create a variable that will be added to everything
# that doesn't need a widget
# 0 + 0, because it needs to be 0 to not impact anything
# and needs to be an expression to not create a widget
$nowidget = 0 + 0;



$x = $u*$w;
$y = $v*$h;

if($direction)
{
    $tmp = $x;
    $x = $y;
    $y = $tmp;
}

$h = $a*sqrt(3)/2;
$xrest = $x%(3*$a);
$yrest = $y%(2*$h);

# now we're just in the rectangle 3a, 2h
$isborder = 0 + $nowidget;

# all horizontal
if($xrest > $a - $th && $xrest < 2*$a + $th && ($yrest < $th || $yrest > 2*$h - $th)) {
    $isborder = 1 + $nowidget;
}

if($xrest < $a/2 + $th || $xrest > 2.5*$a - $th) {
    if($yrest > $h - $th && $yrest < $h + $th) {
        $isborder = 1 + $nowidget;
    }
}

# top-left, bottom-right
$d0 = sqrt($xrest*$xrest + $yrest*$yrest);
if($d0 > $a - $th && $d0 < 2*$a + $th) {
    # to get the thickness right, we need to use
    # equation for a line with two points
    # and the distance from this line
    # here line:
    # 0.5*a*y - h*x = 0
    # and distance:
    # 
    
    $dp = abs(-$h*$xrest + 0.5*$a*$yrest)/sqrt($h*$h - 0.25*$a*$a);
    if($dp < $th) {
        $isborder = 1 + $nowidget;
    }
}

$d0 = sqrt(($xrest-2*$a)*(($xrest-2*$a)) + $yrest*$yrest);
if($d0 < $a + $th) {
    $xtemp = $xrest - 2*$a;
    $dp = abs(-$h*$xtemp + 0.5*$a*$yrest)/sqrt($h*$h - 0.25*$a*$a);
    if($dp < $th) {
        $isborder = 1 + $nowidget;
    }
}

# top-right, bottom-left
$d0 = sqrt(($xrest-$a)*(($xrest-$a)) + $yrest*$yrest);
if($d0 < $a + $th) {
    $dp = abs(-$h*$xrest - 0.5*$a*$yrest + $a*$h)/sqrt($h*$h + 0.25*$a*$a);
    if($dp < $th) {
        $isborder = 1 + $nowidget;
    }
}

$d0 = sqrt(($xrest-3*$a)*(($xrest-3*$a)) + ($yrest)*($yrest));
if($d0 < 2*$a + $th && $d0 > $a - $th) {
    $xtemp = $xrest - 2*$a;
    $dp = abs(-$h*$xtemp - 0.5*$a*$yrest + $a*$h)/sqrt($h*$h + 0.25*$a*$a);
    if($dp < $th) {
        $isborder = 1 + $nowidget;
    }
}


# setting up colors
if($isborder) {
    $color = $border;
}
else 
{
    $color = $background;
}

$color
1 Like