Recent

Author Topic: Random Carpet Designs: Lazzed Conversion from JavaScript gives incorrect pattern  (Read 1729 times)

majolika

  • Jr. Member
  • **
  • Posts: 73
the order of the colors
I call this "palette". :)
I create the palettes with this cycle
    for n := High(plttpatt) downto 0 do begin
and use it with this cycle
    for c := High(plttpatt) downto 0 do begin
The order is the same.

Not sure why you said: TList needed, or something that could be a recursively nested dynamic array  as Seeds is a dynamic array created here:  SetLength(seeds, Length(plttpatt));   ?
Array Seeds saves the paletttes for this particular level of recursion.
On the 0 level of recursion we use given palette (in other words, the given order of colors placed on the given pattern) to draw colors.
On the higher levels of recursion we use given palette to draw previously saved palettes.
For the 5x5 carpet it means that on the 1st level Seeds remembers the palettes for every 1/25 part of carpet but completely forget it when it's back on the 2nd level.
Look:

drawCarpet(5x5):
   drawPalette, 2nd level — the whole carpet
      create 6 seeds and save it in Seeds
      drawPalette. 1st level — 1/25 part of carpet
         create 6 seeds and save it in Seeds
         drawPalette, 0 level — draw "pixels" aka rectangles
      back to the 1st level and draw next palette from Seeds
   back to the 2nd level and — boom! — we create new 6 seeds and save it in Seeds

Of course you can use array of Seeds but this will works only for 2 levels of recursion depth. What if you'll need to go deeper? :)

P.S.
But maybe I'm wrong... Try to use array of Seeds.
« Last Edit: February 14, 2025, 02:15:07 pm by majolika »
Lazarus 3.8 (rev lazarus_3_8) FPC 3.2.2 x86_64-win64-win32/win64

majolika

  • Jr. Member
  • **
  • Posts: 73
By the way, did you mention the const in JS source?
I don't know JS but I suppose it prevents seeds of rewriting when procedure dives up on the higher level of recursion.
That's why my version creates carpet with 25 different — let's call it "blocks" — of carpet.
Lazarus 3.8 (rev lazarus_3_8) FPC 3.2.2 x86_64-win64-win32/win64

Boleeman

  • Hero Member
  • *****
  • Posts: 840
Decided to simplify things with just a 9 block carpet pattern.

The pattern looks more like a table clothe pattern, as it only has 3 colors.

Made a JavaScript version and it works well and saves to very small size, as it has only 3 colors and few pixel positions.

I then tried a Lazarus version, but still no pattern conforming to the pattern map array at level 2.


majolika

  • Jr. Member
  • **
  • Posts: 73
I then tried a Lazarus version, but still no pattern conforming to the pattern map array at level 2.
I suppose you get it wrong. Level 3 will be a carpet of 25 blocks of carpets (if we talk about 5x5 pattern).
Lazarus 3.8 (rev lazarus_3_8) FPC 3.2.2 x86_64-win64-win32/win64

Boleeman

  • Hero Member
  • *****
  • Posts: 840
majolika, I ended up making a 3x3 version to try to further simplify the coding.

Sort of got it working (conforming to the pattern map array) for the simplified 3x3 = 9 Blocks version, but I have extra colors.
Comparing it to the JavaScript version output, the overall patterns look quite different.

What is happening is when I use Round (and also with Trunc) in:

        X := x0patt + pi * Round(Power(SizeFactor, seRecLevel.Value + 1 ));
        Y := y0patt + pj * Round(Power(SizeFactor, seRecLevel.Value + 1 ));

and in

      NewX := x + i * Round(Power(SizeFactor, RecIndex ));
      NewY := y + j * Round(Power(SizeFactor, RecIndex ));


It seems to be interfering with DrawPattern(NewX, NewY, RecIndex - 1, Seeds[Pattern[i, j]]);   and adding extra colors.

I have Indigo, clRed, clYellow in Colors: array[0..2] of TColor = (TColor($82004B), clRed, clYellow); but there are extra colors appearing on the TPaintbox canvas.

« Last Edit: February 15, 2025, 09:23:42 am by Boleeman »

 

TinyPortal © 2005-2018