tikz: Jigsaw Puzzle Boundary Shape

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
13
down vote

favorite
4













This question led to a new package:
jigsaw




I would like to draw a jigsaw puzzle boundary layer, ideally connecting two half-circle segments. The two segments should be connected by a nicely curved typical jigsaw boundary like in the following picture:



Royalty free shutterstock image



I couldn't find any tikz boilerplate code for such a shape, besides a simplified version here on tex.sx



If you have already drawn such a shape, please share!







share|improve this question


























    up vote
    13
    down vote

    favorite
    4













    This question led to a new package:
    jigsaw




    I would like to draw a jigsaw puzzle boundary layer, ideally connecting two half-circle segments. The two segments should be connected by a nicely curved typical jigsaw boundary like in the following picture:



    Royalty free shutterstock image



    I couldn't find any tikz boilerplate code for such a shape, besides a simplified version here on tex.sx



    If you have already drawn such a shape, please share!







    share|improve this question
























      up vote
      13
      down vote

      favorite
      4









      up vote
      13
      down vote

      favorite
      4






      4






      This question led to a new package:
      jigsaw




      I would like to draw a jigsaw puzzle boundary layer, ideally connecting two half-circle segments. The two segments should be connected by a nicely curved typical jigsaw boundary like in the following picture:



      Royalty free shutterstock image



      I couldn't find any tikz boilerplate code for such a shape, besides a simplified version here on tex.sx



      If you have already drawn such a shape, please share!







      share|improve this question















      This question led to a new package:
      jigsaw




      I would like to draw a jigsaw puzzle boundary layer, ideally connecting two half-circle segments. The two segments should be connected by a nicely curved typical jigsaw boundary like in the following picture:



      Royalty free shutterstock image



      I couldn't find any tikz boilerplate code for such a shape, besides a simplified version here on tex.sx



      If you have already drawn such a shape, please share!









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 31 at 19:08









      samcarter

      74.1k785238




      74.1k785238










      asked Aug 16 at 14:45









      sebastian

      54948




      54948




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          12
          down vote



          accepted










          And a version with pics. That may make it a bit easier to build a full puzzle.



          documentclass[tikz,border=3.14mm]standalone
          begindocument
          tikzsetpics/.cd,
          jigsaw/.style=
          code=
          fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
          0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35)
          begintikzpicture
          draw (-2,-2) picjigsaw=blue (2,-2) picjigsaw=red
          (-2,2) pic[rotate=90]jigsaw=purple (2,2) pic[rotate=90]jigsaw=green!60!black;
          endtikzpicture
          enddocument


          enter image description here



          UPDATE: With multipurpose jigsaw pics: the syntax is



          picmultipurpose jigsaw=fill <color> and <left>/<top>/<right>/<bottom>


          where <color> determines the fill color and the other arguments specify the lug: -1 means that lug goes in, 1 that the lug goes out and 0 means no lug. (Also tried to improve on the colors. ;-)



          documentclass[x11names, svgnames, dvipsnames,tikz,border=3.14mm]standalone
          begindocument
          tikzsetpics/.cd,
          jigsaw/.style=
          code=
          fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
          0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35) ,
          multipurpose jigsaw/.style args=fill #1 and #2/#3/#4/#5
          code= (2,0.35)
          to[out=-90,in=270+#4*45] (2-#4*0.5,0.45)
          arc(90-#4*45:(#4+1)*180-90+#4*45:0.6 and 0.45*sqrt(2))
          to[out=90-#4*45,in=90] (2,-0.35)
          % order : left/top/right/bottom and -1 is out, 1 is in, 0 none
          begintikzpicture
          draw (-4,-4) picmultipurpose jigsaw=fill FireBrick and 0/-1/1/0
          (0,-4) picmultipurpose jigsaw=fill Blue and -1/-1/1/0
          (4,-4) picmultipurpose jigsaw=fill ForestGreen and -1/1/0/0
          (-4,0) picmultipurpose jigsaw=fill ForestGreen and 0/1/-1/1
          (0,0) picmultipurpose jigsaw=fill FireBrick and 1/-1/1/1
          (4,0) picmultipurpose jigsaw=fill Blue and -1/1/0/-1
          (-4,4) picmultipurpose jigsaw=fill Blue and 0/0/1/-1
          (0,4) picmultipurpose jigsaw=fill ForestGreen and -1/0/1/1
          (4,4) picmultipurpose jigsaw=fill FireBrick and -1/0/0/-1;
          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer






















          • Also a great solution, thanks! If I only could accept several answers.
            – sebastian
            Aug 17 at 12:04

















          up vote
          23
          down vote













          Based on a single side, one can easily draw jigsaw pieces. In the following example, the macro piece can be used to draw a piece of the desired shape. For all four sides it can be controlled if the nose should face outward (-1) or inward (1) or a straight line (0).



          documentclassstandalone

          usepackagetikz

          newcommandside[1]
          (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
          (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
          (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
          (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
          (1.0,#1*0.00)


          newcommandpiece[4]
          draw
          side#1
          [rotate around=90:(0.5,0.5)] side#2
          [rotate around=180:(0.5,0.5)] side#3
          [rotate around=270:(0.5,0.5)] side#4;


          begindocument

          begintikzpicture[scale=3]
          piece1111
          endtikzpicture

          begintikzpicture[scale=3]
          piece1-111
          endtikzpicture


          begintikzpicture[scale=3]
          piece1-1-11
          endtikzpicture


          begintikzpicture[scale=3]
          piece1-1-1-1
          endtikzpicture


          begintikzpicture[scale=3]
          piece-1-1-1-1
          endtikzpicture


          begintikzpicture[scale=3]
          piece-11-11
          endtikzpicture

          enddocument


          enter image description here



          These pieces can also be used to build a puzzle:



          documentclassstandalone

          usepackagetikz

          newcommandside[1]
          (0.5,0.5) --
          (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
          (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
          (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
          (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
          (1.0,#1*0.00)


          newcommandpiece[5][white]
          fill[#1]
          side#2
          [rotate around=90:(0.5,0.5)] side#3
          [rotate around=180:(0.5,0.5)] side#4
          [rotate around=270:(0.5,0.5)] side#5
          -- cycle;


          begindocument

          begintikzpicture

          beginscope
          piece[red]1100
          endscope
          beginscope[xshift=1cm]
          piece[blue]1-1-10
          endscope
          beginscope[xshift=2cm]
          piece[green]1010
          endscope

          beginscope[yshift=-1cm]
          piece[green]1-10-1
          endscope
          beginscope[xshift=1cm,yshift=-1cm]
          piece[red]1-11-1
          endscope
          beginscope[xshift=2cm,yshift=-1cm]
          piece[blue]-101-1
          endscope

          beginscope[yshift=-2cm]
          piece[blue]0-10-1
          endscope
          beginscope[xshift=1cm,yshift=-2cm]
          piece[green]0-11-1
          endscope
          beginscope[xshift=2cm,yshift=-2cm]
          piece[red]0011
          endscope

          endtikzpicture

          enddocument


          enter image description here



          Or to produce a random puzzle:



          documentclassstandalone

          usepackagetikz
          pgfmathparseint(random(1,120))

          newcommandside[1]
          (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
          (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
          (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
          (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
          (1.0,#1*0.00)


          newcommandpiece[2]
          draw[ultra thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


          pgfmathdeclarerandomlistinout-11

          begindocument

          begintikzpicture[scale=5]

          defxmax10
          defymax10


          foreach x in 0,...,xmax
          foreach y in 0,...,ymax

          ifnumy=0
          defbottom0
          else
          pgfmathrandomitembottominout%
          fi

          ifnumx=xmax
          defright0
          else
          pgfmathrandomitemrightinout%
          fi

          beginscope[xshift=x cm, yshift=y cm]
          piecebottomright
          endscope



          draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

          endtikzpicture

          enddocument


          enter image description here



          With background image



          documentclassstandalone

          usepackagetikz
          pgfmathparseint(random(1,120))

          newcommandside[1]
          (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
          (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
          (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
          (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
          (1.0,#1*0.00)


          newcommandpiece[2]
          draw[thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


          pgfmathdeclarerandomlistinout-11

          begindocument

          begintikzpicture

          node at (5.5,4) includegraphics[width=11cm,height=8cm]example-image-duck;

          defxmax10
          defymax7


          foreach x in 0,...,xmax
          foreach y in 0,...,ymax

          ifnumy=0
          defbottom0
          else
          pgfmathrandomitembottominout%
          fi

          ifnumx=xmax
          defright0
          else
          pgfmathrandomitemrightinout%
          fi

          beginscope[xshift=x cm, yshift=y cm]
          piecebottomright
          endscope



          draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

          endtikzpicture

          enddocument


          enter image description here






          share|improve this answer






















          • I didn't see your update till now. Coincidently we have the same conventions for in and out. Weird. ;-) ;-)
            – marmot
            Aug 16 at 17:16










          • @marmot 50:50 chance :)
            – samcarter
            Aug 16 at 17:20










          • Yes, and how many % to use integers for that? ;-)
            – marmot
            Aug 16 at 17:21






          • 1




            @marmot 100%, it is so convenient to control the direction by simply multiplying :)
            – samcarter
            Aug 16 at 17:24










          • great solution, thank you!
            – sebastian
            Aug 17 at 12:03

















          up vote
          6
          down vote













          An option using [out=Angle,in=Angle,out looseness=Value,in looseness=Value] and coordinate calculations to draw rotated shape; then other tricks to control sizes, angles ,positions and colors.



          RESULT:



          enter image description here



          MWE:



          documentclass[border=10pt]standalone
          usepackagetikz
          usetikzlibraryarrows.meta,calc,fit,shapes

          begindocument
          begintikzpicture
          defJigzawPiece(#1)[#2]#3#4
          beginscope[shift=(#1),rotate=#4,transform shape]
          coordinate (a) at (0:#2);coordinate (b) at (90:#2);coordinate (c) at (180:#2);coordinate (d) at (270:#2);
          foreach nodA/nodB in a/b,b/c,c/d,d/a
          coordinate (nodAnodB1) at ($ (nodA)!0.4!(nodB) $);
          coordinate (nodAnodB2) at ($ (nodA)!0.6!(nodB) $);
          coordinate (nodAnodB3) at ($ (nodA)!0.5!(nodB) $);
          coordinate (nodAnodB4) at ($(nodAnodB3)!0.5*#2 cm!90:(nodA)$);
          coordinate (nodAnodB5) at ($(nodAnodB3)!-0.5*#2 cm!90:(nodA)$);

          draw[fill=#3]
          (a) -- (ab1)
          to [out=133,in=-45,out looseness=1,in looseness=2] (ab5)
          to [out=135,in=-45,out looseness=2,in looseness=1] (ab2) --
          (b) -- (bc1)
          to [out=-135,in=45,out looseness=1,in looseness=2] (bc4)
          to [out=-135,in=45,out looseness=2,in looseness=1] (bc2) --
          (c) -- (cd1)
          to [out=-45,in=135,out looseness=1,in looseness=2] (cd4)
          to [out=-45,in=135,out looseness=2,in looseness=1] (cd2) --
          (d) -- (da1)
          to [out=45,in=-135,out looseness=1,in looseness=2] (da5)
          to [out=45,in=-135,out looseness=2,in looseness=1] (da2) --(a);
          endscope


          foreach x in 0,1,...,7
          foreach y in 0,1,...,5
          pgfmathparse0.9*rnd+0.3
          definecolorRcolorrgbpgfmathresult,pgfmathresult,pgfmathresult % from https://tex.stackexchange.com/a/37279/154390
          JigzawPiece(x,y)[0.5]blue!50!Rcolor0
          JigzawPiece(x+0.5,y+0.5)[0.5]blue!30!Rcolor0


          foreach ang [count=j from 0] in 0,90,180,270
          JigzawPiece(0.5+j*2,7)[1]redang


          foreach ang [count=j from 0] in -45,45,45,-45,-45
          JigzawPiece(0.5+j*1.4142,9)[1]redang

          endtikzpicture

          enddocument





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "85"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f446292%2ftikz-jigsaw-puzzle-boundary-shape%23new-answer', 'question_page');

            );

            Post as a guest






























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            12
            down vote



            accepted










            And a version with pics. That may make it a bit easier to build a full puzzle.



            documentclass[tikz,border=3.14mm]standalone
            begindocument
            tikzsetpics/.cd,
            jigsaw/.style=
            code=
            fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
            0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35)
            begintikzpicture
            draw (-2,-2) picjigsaw=blue (2,-2) picjigsaw=red
            (-2,2) pic[rotate=90]jigsaw=purple (2,2) pic[rotate=90]jigsaw=green!60!black;
            endtikzpicture
            enddocument


            enter image description here



            UPDATE: With multipurpose jigsaw pics: the syntax is



            picmultipurpose jigsaw=fill <color> and <left>/<top>/<right>/<bottom>


            where <color> determines the fill color and the other arguments specify the lug: -1 means that lug goes in, 1 that the lug goes out and 0 means no lug. (Also tried to improve on the colors. ;-)



            documentclass[x11names, svgnames, dvipsnames,tikz,border=3.14mm]standalone
            begindocument
            tikzsetpics/.cd,
            jigsaw/.style=
            code=
            fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
            0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35) ,
            multipurpose jigsaw/.style args=fill #1 and #2/#3/#4/#5
            code= (2,0.35)
            to[out=-90,in=270+#4*45] (2-#4*0.5,0.45)
            arc(90-#4*45:(#4+1)*180-90+#4*45:0.6 and 0.45*sqrt(2))
            to[out=90-#4*45,in=90] (2,-0.35)
            % order : left/top/right/bottom and -1 is out, 1 is in, 0 none
            begintikzpicture
            draw (-4,-4) picmultipurpose jigsaw=fill FireBrick and 0/-1/1/0
            (0,-4) picmultipurpose jigsaw=fill Blue and -1/-1/1/0
            (4,-4) picmultipurpose jigsaw=fill ForestGreen and -1/1/0/0
            (-4,0) picmultipurpose jigsaw=fill ForestGreen and 0/1/-1/1
            (0,0) picmultipurpose jigsaw=fill FireBrick and 1/-1/1/1
            (4,0) picmultipurpose jigsaw=fill Blue and -1/1/0/-1
            (-4,4) picmultipurpose jigsaw=fill Blue and 0/0/1/-1
            (0,4) picmultipurpose jigsaw=fill ForestGreen and -1/0/1/1
            (4,4) picmultipurpose jigsaw=fill FireBrick and -1/0/0/-1;
            endtikzpicture
            enddocument


            enter image description here






            share|improve this answer






















            • Also a great solution, thanks! If I only could accept several answers.
              – sebastian
              Aug 17 at 12:04














            up vote
            12
            down vote



            accepted










            And a version with pics. That may make it a bit easier to build a full puzzle.



            documentclass[tikz,border=3.14mm]standalone
            begindocument
            tikzsetpics/.cd,
            jigsaw/.style=
            code=
            fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
            0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35)
            begintikzpicture
            draw (-2,-2) picjigsaw=blue (2,-2) picjigsaw=red
            (-2,2) pic[rotate=90]jigsaw=purple (2,2) pic[rotate=90]jigsaw=green!60!black;
            endtikzpicture
            enddocument


            enter image description here



            UPDATE: With multipurpose jigsaw pics: the syntax is



            picmultipurpose jigsaw=fill <color> and <left>/<top>/<right>/<bottom>


            where <color> determines the fill color and the other arguments specify the lug: -1 means that lug goes in, 1 that the lug goes out and 0 means no lug. (Also tried to improve on the colors. ;-)



            documentclass[x11names, svgnames, dvipsnames,tikz,border=3.14mm]standalone
            begindocument
            tikzsetpics/.cd,
            jigsaw/.style=
            code=
            fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
            0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35) ,
            multipurpose jigsaw/.style args=fill #1 and #2/#3/#4/#5
            code= (2,0.35)
            to[out=-90,in=270+#4*45] (2-#4*0.5,0.45)
            arc(90-#4*45:(#4+1)*180-90+#4*45:0.6 and 0.45*sqrt(2))
            to[out=90-#4*45,in=90] (2,-0.35)
            % order : left/top/right/bottom and -1 is out, 1 is in, 0 none
            begintikzpicture
            draw (-4,-4) picmultipurpose jigsaw=fill FireBrick and 0/-1/1/0
            (0,-4) picmultipurpose jigsaw=fill Blue and -1/-1/1/0
            (4,-4) picmultipurpose jigsaw=fill ForestGreen and -1/1/0/0
            (-4,0) picmultipurpose jigsaw=fill ForestGreen and 0/1/-1/1
            (0,0) picmultipurpose jigsaw=fill FireBrick and 1/-1/1/1
            (4,0) picmultipurpose jigsaw=fill Blue and -1/1/0/-1
            (-4,4) picmultipurpose jigsaw=fill Blue and 0/0/1/-1
            (0,4) picmultipurpose jigsaw=fill ForestGreen and -1/0/1/1
            (4,4) picmultipurpose jigsaw=fill FireBrick and -1/0/0/-1;
            endtikzpicture
            enddocument


            enter image description here






            share|improve this answer






















            • Also a great solution, thanks! If I only could accept several answers.
              – sebastian
              Aug 17 at 12:04












            up vote
            12
            down vote



            accepted







            up vote
            12
            down vote



            accepted






            And a version with pics. That may make it a bit easier to build a full puzzle.



            documentclass[tikz,border=3.14mm]standalone
            begindocument
            tikzsetpics/.cd,
            jigsaw/.style=
            code=
            fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
            0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35)
            begintikzpicture
            draw (-2,-2) picjigsaw=blue (2,-2) picjigsaw=red
            (-2,2) pic[rotate=90]jigsaw=purple (2,2) pic[rotate=90]jigsaw=green!60!black;
            endtikzpicture
            enddocument


            enter image description here



            UPDATE: With multipurpose jigsaw pics: the syntax is



            picmultipurpose jigsaw=fill <color> and <left>/<top>/<right>/<bottom>


            where <color> determines the fill color and the other arguments specify the lug: -1 means that lug goes in, 1 that the lug goes out and 0 means no lug. (Also tried to improve on the colors. ;-)



            documentclass[x11names, svgnames, dvipsnames,tikz,border=3.14mm]standalone
            begindocument
            tikzsetpics/.cd,
            jigsaw/.style=
            code=
            fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
            0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35) ,
            multipurpose jigsaw/.style args=fill #1 and #2/#3/#4/#5
            code= (2,0.35)
            to[out=-90,in=270+#4*45] (2-#4*0.5,0.45)
            arc(90-#4*45:(#4+1)*180-90+#4*45:0.6 and 0.45*sqrt(2))
            to[out=90-#4*45,in=90] (2,-0.35)
            % order : left/top/right/bottom and -1 is out, 1 is in, 0 none
            begintikzpicture
            draw (-4,-4) picmultipurpose jigsaw=fill FireBrick and 0/-1/1/0
            (0,-4) picmultipurpose jigsaw=fill Blue and -1/-1/1/0
            (4,-4) picmultipurpose jigsaw=fill ForestGreen and -1/1/0/0
            (-4,0) picmultipurpose jigsaw=fill ForestGreen and 0/1/-1/1
            (0,0) picmultipurpose jigsaw=fill FireBrick and 1/-1/1/1
            (4,0) picmultipurpose jigsaw=fill Blue and -1/1/0/-1
            (-4,4) picmultipurpose jigsaw=fill Blue and 0/0/1/-1
            (0,4) picmultipurpose jigsaw=fill ForestGreen and -1/0/1/1
            (4,4) picmultipurpose jigsaw=fill FireBrick and -1/0/0/-1;
            endtikzpicture
            enddocument


            enter image description here






            share|improve this answer














            And a version with pics. That may make it a bit easier to build a full puzzle.



            documentclass[tikz,border=3.14mm]standalone
            begindocument
            tikzsetpics/.cd,
            jigsaw/.style=
            code=
            fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
            0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35)
            begintikzpicture
            draw (-2,-2) picjigsaw=blue (2,-2) picjigsaw=red
            (-2,2) pic[rotate=90]jigsaw=purple (2,2) pic[rotate=90]jigsaw=green!60!black;
            endtikzpicture
            enddocument


            enter image description here



            UPDATE: With multipurpose jigsaw pics: the syntax is



            picmultipurpose jigsaw=fill <color> and <left>/<top>/<right>/<bottom>


            where <color> determines the fill color and the other arguments specify the lug: -1 means that lug goes in, 1 that the lug goes out and 0 means no lug. (Also tried to improve on the colors. ;-)



            documentclass[x11names, svgnames, dvipsnames,tikz,border=3.14mm]standalone
            begindocument
            tikzsetpics/.cd,
            jigsaw/.style=
            code=
            fill[#1] (-2,-0.35) to[out=90,in=135] (-1.5,-0.45) arc(-135:135:0.6 and
            0.45*sqrt(2)) to[out=-135,in=-90] (-2,0.35) ,
            multipurpose jigsaw/.style args=fill #1 and #2/#3/#4/#5
            code= (2,0.35)
            to[out=-90,in=270+#4*45] (2-#4*0.5,0.45)
            arc(90-#4*45:(#4+1)*180-90+#4*45:0.6 and 0.45*sqrt(2))
            to[out=90-#4*45,in=90] (2,-0.35)
            % order : left/top/right/bottom and -1 is out, 1 is in, 0 none
            begintikzpicture
            draw (-4,-4) picmultipurpose jigsaw=fill FireBrick and 0/-1/1/0
            (0,-4) picmultipurpose jigsaw=fill Blue and -1/-1/1/0
            (4,-4) picmultipurpose jigsaw=fill ForestGreen and -1/1/0/0
            (-4,0) picmultipurpose jigsaw=fill ForestGreen and 0/1/-1/1
            (0,0) picmultipurpose jigsaw=fill FireBrick and 1/-1/1/1
            (4,0) picmultipurpose jigsaw=fill Blue and -1/1/0/-1
            (-4,4) picmultipurpose jigsaw=fill Blue and 0/0/1/-1
            (0,4) picmultipurpose jigsaw=fill ForestGreen and -1/0/1/1
            (4,4) picmultipurpose jigsaw=fill FireBrick and -1/0/0/-1;
            endtikzpicture
            enddocument


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 16 at 17:14

























            answered Aug 16 at 16:06









            marmot

            55.2k459119




            55.2k459119











            • Also a great solution, thanks! If I only could accept several answers.
              – sebastian
              Aug 17 at 12:04
















            • Also a great solution, thanks! If I only could accept several answers.
              – sebastian
              Aug 17 at 12:04















            Also a great solution, thanks! If I only could accept several answers.
            – sebastian
            Aug 17 at 12:04




            Also a great solution, thanks! If I only could accept several answers.
            – sebastian
            Aug 17 at 12:04










            up vote
            23
            down vote













            Based on a single side, one can easily draw jigsaw pieces. In the following example, the macro piece can be used to draw a piece of the desired shape. For all four sides it can be controlled if the nose should face outward (-1) or inward (1) or a straight line (0).



            documentclassstandalone

            usepackagetikz

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[4]
            draw
            side#1
            [rotate around=90:(0.5,0.5)] side#2
            [rotate around=180:(0.5,0.5)] side#3
            [rotate around=270:(0.5,0.5)] side#4;


            begindocument

            begintikzpicture[scale=3]
            piece1111
            endtikzpicture

            begintikzpicture[scale=3]
            piece1-111
            endtikzpicture


            begintikzpicture[scale=3]
            piece1-1-11
            endtikzpicture


            begintikzpicture[scale=3]
            piece1-1-1-1
            endtikzpicture


            begintikzpicture[scale=3]
            piece-1-1-1-1
            endtikzpicture


            begintikzpicture[scale=3]
            piece-11-11
            endtikzpicture

            enddocument


            enter image description here



            These pieces can also be used to build a puzzle:



            documentclassstandalone

            usepackagetikz

            newcommandside[1]
            (0.5,0.5) --
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[5][white]
            fill[#1]
            side#2
            [rotate around=90:(0.5,0.5)] side#3
            [rotate around=180:(0.5,0.5)] side#4
            [rotate around=270:(0.5,0.5)] side#5
            -- cycle;


            begindocument

            begintikzpicture

            beginscope
            piece[red]1100
            endscope
            beginscope[xshift=1cm]
            piece[blue]1-1-10
            endscope
            beginscope[xshift=2cm]
            piece[green]1010
            endscope

            beginscope[yshift=-1cm]
            piece[green]1-10-1
            endscope
            beginscope[xshift=1cm,yshift=-1cm]
            piece[red]1-11-1
            endscope
            beginscope[xshift=2cm,yshift=-1cm]
            piece[blue]-101-1
            endscope

            beginscope[yshift=-2cm]
            piece[blue]0-10-1
            endscope
            beginscope[xshift=1cm,yshift=-2cm]
            piece[green]0-11-1
            endscope
            beginscope[xshift=2cm,yshift=-2cm]
            piece[red]0011
            endscope

            endtikzpicture

            enddocument


            enter image description here



            Or to produce a random puzzle:



            documentclassstandalone

            usepackagetikz
            pgfmathparseint(random(1,120))

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[2]
            draw[ultra thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


            pgfmathdeclarerandomlistinout-11

            begindocument

            begintikzpicture[scale=5]

            defxmax10
            defymax10


            foreach x in 0,...,xmax
            foreach y in 0,...,ymax

            ifnumy=0
            defbottom0
            else
            pgfmathrandomitembottominout%
            fi

            ifnumx=xmax
            defright0
            else
            pgfmathrandomitemrightinout%
            fi

            beginscope[xshift=x cm, yshift=y cm]
            piecebottomright
            endscope



            draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

            endtikzpicture

            enddocument


            enter image description here



            With background image



            documentclassstandalone

            usepackagetikz
            pgfmathparseint(random(1,120))

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[2]
            draw[thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


            pgfmathdeclarerandomlistinout-11

            begindocument

            begintikzpicture

            node at (5.5,4) includegraphics[width=11cm,height=8cm]example-image-duck;

            defxmax10
            defymax7


            foreach x in 0,...,xmax
            foreach y in 0,...,ymax

            ifnumy=0
            defbottom0
            else
            pgfmathrandomitembottominout%
            fi

            ifnumx=xmax
            defright0
            else
            pgfmathrandomitemrightinout%
            fi

            beginscope[xshift=x cm, yshift=y cm]
            piecebottomright
            endscope



            draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

            endtikzpicture

            enddocument


            enter image description here






            share|improve this answer






















            • I didn't see your update till now. Coincidently we have the same conventions for in and out. Weird. ;-) ;-)
              – marmot
              Aug 16 at 17:16










            • @marmot 50:50 chance :)
              – samcarter
              Aug 16 at 17:20










            • Yes, and how many % to use integers for that? ;-)
              – marmot
              Aug 16 at 17:21






            • 1




              @marmot 100%, it is so convenient to control the direction by simply multiplying :)
              – samcarter
              Aug 16 at 17:24










            • great solution, thank you!
              – sebastian
              Aug 17 at 12:03














            up vote
            23
            down vote













            Based on a single side, one can easily draw jigsaw pieces. In the following example, the macro piece can be used to draw a piece of the desired shape. For all four sides it can be controlled if the nose should face outward (-1) or inward (1) or a straight line (0).



            documentclassstandalone

            usepackagetikz

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[4]
            draw
            side#1
            [rotate around=90:(0.5,0.5)] side#2
            [rotate around=180:(0.5,0.5)] side#3
            [rotate around=270:(0.5,0.5)] side#4;


            begindocument

            begintikzpicture[scale=3]
            piece1111
            endtikzpicture

            begintikzpicture[scale=3]
            piece1-111
            endtikzpicture


            begintikzpicture[scale=3]
            piece1-1-11
            endtikzpicture


            begintikzpicture[scale=3]
            piece1-1-1-1
            endtikzpicture


            begintikzpicture[scale=3]
            piece-1-1-1-1
            endtikzpicture


            begintikzpicture[scale=3]
            piece-11-11
            endtikzpicture

            enddocument


            enter image description here



            These pieces can also be used to build a puzzle:



            documentclassstandalone

            usepackagetikz

            newcommandside[1]
            (0.5,0.5) --
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[5][white]
            fill[#1]
            side#2
            [rotate around=90:(0.5,0.5)] side#3
            [rotate around=180:(0.5,0.5)] side#4
            [rotate around=270:(0.5,0.5)] side#5
            -- cycle;


            begindocument

            begintikzpicture

            beginscope
            piece[red]1100
            endscope
            beginscope[xshift=1cm]
            piece[blue]1-1-10
            endscope
            beginscope[xshift=2cm]
            piece[green]1010
            endscope

            beginscope[yshift=-1cm]
            piece[green]1-10-1
            endscope
            beginscope[xshift=1cm,yshift=-1cm]
            piece[red]1-11-1
            endscope
            beginscope[xshift=2cm,yshift=-1cm]
            piece[blue]-101-1
            endscope

            beginscope[yshift=-2cm]
            piece[blue]0-10-1
            endscope
            beginscope[xshift=1cm,yshift=-2cm]
            piece[green]0-11-1
            endscope
            beginscope[xshift=2cm,yshift=-2cm]
            piece[red]0011
            endscope

            endtikzpicture

            enddocument


            enter image description here



            Or to produce a random puzzle:



            documentclassstandalone

            usepackagetikz
            pgfmathparseint(random(1,120))

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[2]
            draw[ultra thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


            pgfmathdeclarerandomlistinout-11

            begindocument

            begintikzpicture[scale=5]

            defxmax10
            defymax10


            foreach x in 0,...,xmax
            foreach y in 0,...,ymax

            ifnumy=0
            defbottom0
            else
            pgfmathrandomitembottominout%
            fi

            ifnumx=xmax
            defright0
            else
            pgfmathrandomitemrightinout%
            fi

            beginscope[xshift=x cm, yshift=y cm]
            piecebottomright
            endscope



            draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

            endtikzpicture

            enddocument


            enter image description here



            With background image



            documentclassstandalone

            usepackagetikz
            pgfmathparseint(random(1,120))

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[2]
            draw[thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


            pgfmathdeclarerandomlistinout-11

            begindocument

            begintikzpicture

            node at (5.5,4) includegraphics[width=11cm,height=8cm]example-image-duck;

            defxmax10
            defymax7


            foreach x in 0,...,xmax
            foreach y in 0,...,ymax

            ifnumy=0
            defbottom0
            else
            pgfmathrandomitembottominout%
            fi

            ifnumx=xmax
            defright0
            else
            pgfmathrandomitemrightinout%
            fi

            beginscope[xshift=x cm, yshift=y cm]
            piecebottomright
            endscope



            draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

            endtikzpicture

            enddocument


            enter image description here






            share|improve this answer






















            • I didn't see your update till now. Coincidently we have the same conventions for in and out. Weird. ;-) ;-)
              – marmot
              Aug 16 at 17:16










            • @marmot 50:50 chance :)
              – samcarter
              Aug 16 at 17:20










            • Yes, and how many % to use integers for that? ;-)
              – marmot
              Aug 16 at 17:21






            • 1




              @marmot 100%, it is so convenient to control the direction by simply multiplying :)
              – samcarter
              Aug 16 at 17:24










            • great solution, thank you!
              – sebastian
              Aug 17 at 12:03












            up vote
            23
            down vote










            up vote
            23
            down vote









            Based on a single side, one can easily draw jigsaw pieces. In the following example, the macro piece can be used to draw a piece of the desired shape. For all four sides it can be controlled if the nose should face outward (-1) or inward (1) or a straight line (0).



            documentclassstandalone

            usepackagetikz

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[4]
            draw
            side#1
            [rotate around=90:(0.5,0.5)] side#2
            [rotate around=180:(0.5,0.5)] side#3
            [rotate around=270:(0.5,0.5)] side#4;


            begindocument

            begintikzpicture[scale=3]
            piece1111
            endtikzpicture

            begintikzpicture[scale=3]
            piece1-111
            endtikzpicture


            begintikzpicture[scale=3]
            piece1-1-11
            endtikzpicture


            begintikzpicture[scale=3]
            piece1-1-1-1
            endtikzpicture


            begintikzpicture[scale=3]
            piece-1-1-1-1
            endtikzpicture


            begintikzpicture[scale=3]
            piece-11-11
            endtikzpicture

            enddocument


            enter image description here



            These pieces can also be used to build a puzzle:



            documentclassstandalone

            usepackagetikz

            newcommandside[1]
            (0.5,0.5) --
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[5][white]
            fill[#1]
            side#2
            [rotate around=90:(0.5,0.5)] side#3
            [rotate around=180:(0.5,0.5)] side#4
            [rotate around=270:(0.5,0.5)] side#5
            -- cycle;


            begindocument

            begintikzpicture

            beginscope
            piece[red]1100
            endscope
            beginscope[xshift=1cm]
            piece[blue]1-1-10
            endscope
            beginscope[xshift=2cm]
            piece[green]1010
            endscope

            beginscope[yshift=-1cm]
            piece[green]1-10-1
            endscope
            beginscope[xshift=1cm,yshift=-1cm]
            piece[red]1-11-1
            endscope
            beginscope[xshift=2cm,yshift=-1cm]
            piece[blue]-101-1
            endscope

            beginscope[yshift=-2cm]
            piece[blue]0-10-1
            endscope
            beginscope[xshift=1cm,yshift=-2cm]
            piece[green]0-11-1
            endscope
            beginscope[xshift=2cm,yshift=-2cm]
            piece[red]0011
            endscope

            endtikzpicture

            enddocument


            enter image description here



            Or to produce a random puzzle:



            documentclassstandalone

            usepackagetikz
            pgfmathparseint(random(1,120))

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[2]
            draw[ultra thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


            pgfmathdeclarerandomlistinout-11

            begindocument

            begintikzpicture[scale=5]

            defxmax10
            defymax10


            foreach x in 0,...,xmax
            foreach y in 0,...,ymax

            ifnumy=0
            defbottom0
            else
            pgfmathrandomitembottominout%
            fi

            ifnumx=xmax
            defright0
            else
            pgfmathrandomitemrightinout%
            fi

            beginscope[xshift=x cm, yshift=y cm]
            piecebottomright
            endscope



            draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

            endtikzpicture

            enddocument


            enter image description here



            With background image



            documentclassstandalone

            usepackagetikz
            pgfmathparseint(random(1,120))

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[2]
            draw[thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


            pgfmathdeclarerandomlistinout-11

            begindocument

            begintikzpicture

            node at (5.5,4) includegraphics[width=11cm,height=8cm]example-image-duck;

            defxmax10
            defymax7


            foreach x in 0,...,xmax
            foreach y in 0,...,ymax

            ifnumy=0
            defbottom0
            else
            pgfmathrandomitembottominout%
            fi

            ifnumx=xmax
            defright0
            else
            pgfmathrandomitemrightinout%
            fi

            beginscope[xshift=x cm, yshift=y cm]
            piecebottomright
            endscope



            draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

            endtikzpicture

            enddocument


            enter image description here






            share|improve this answer














            Based on a single side, one can easily draw jigsaw pieces. In the following example, the macro piece can be used to draw a piece of the desired shape. For all four sides it can be controlled if the nose should face outward (-1) or inward (1) or a straight line (0).



            documentclassstandalone

            usepackagetikz

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[4]
            draw
            side#1
            [rotate around=90:(0.5,0.5)] side#2
            [rotate around=180:(0.5,0.5)] side#3
            [rotate around=270:(0.5,0.5)] side#4;


            begindocument

            begintikzpicture[scale=3]
            piece1111
            endtikzpicture

            begintikzpicture[scale=3]
            piece1-111
            endtikzpicture


            begintikzpicture[scale=3]
            piece1-1-11
            endtikzpicture


            begintikzpicture[scale=3]
            piece1-1-1-1
            endtikzpicture


            begintikzpicture[scale=3]
            piece-1-1-1-1
            endtikzpicture


            begintikzpicture[scale=3]
            piece-11-11
            endtikzpicture

            enddocument


            enter image description here



            These pieces can also be used to build a puzzle:



            documentclassstandalone

            usepackagetikz

            newcommandside[1]
            (0.5,0.5) --
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[5][white]
            fill[#1]
            side#2
            [rotate around=90:(0.5,0.5)] side#3
            [rotate around=180:(0.5,0.5)] side#4
            [rotate around=270:(0.5,0.5)] side#5
            -- cycle;


            begindocument

            begintikzpicture

            beginscope
            piece[red]1100
            endscope
            beginscope[xshift=1cm]
            piece[blue]1-1-10
            endscope
            beginscope[xshift=2cm]
            piece[green]1010
            endscope

            beginscope[yshift=-1cm]
            piece[green]1-10-1
            endscope
            beginscope[xshift=1cm,yshift=-1cm]
            piece[red]1-11-1
            endscope
            beginscope[xshift=2cm,yshift=-1cm]
            piece[blue]-101-1
            endscope

            beginscope[yshift=-2cm]
            piece[blue]0-10-1
            endscope
            beginscope[xshift=1cm,yshift=-2cm]
            piece[green]0-11-1
            endscope
            beginscope[xshift=2cm,yshift=-2cm]
            piece[red]0011
            endscope

            endtikzpicture

            enddocument


            enter image description here



            Or to produce a random puzzle:



            documentclassstandalone

            usepackagetikz
            pgfmathparseint(random(1,120))

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[2]
            draw[ultra thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


            pgfmathdeclarerandomlistinout-11

            begindocument

            begintikzpicture[scale=5]

            defxmax10
            defymax10


            foreach x in 0,...,xmax
            foreach y in 0,...,ymax

            ifnumy=0
            defbottom0
            else
            pgfmathrandomitembottominout%
            fi

            ifnumx=xmax
            defright0
            else
            pgfmathrandomitemrightinout%
            fi

            beginscope[xshift=x cm, yshift=y cm]
            piecebottomright
            endscope



            draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

            endtikzpicture

            enddocument


            enter image description here



            With background image



            documentclassstandalone

            usepackagetikz
            pgfmathparseint(random(1,120))

            newcommandside[1]
            (0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
            (0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
            (0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
            (0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
            (1.0,#1*0.00)


            newcommandpiece[2]
            draw[thick] side#1 [rotate around=90:(0.5,0.5)] side#2;


            pgfmathdeclarerandomlistinout-11

            begindocument

            begintikzpicture

            node at (5.5,4) includegraphics[width=11cm,height=8cm]example-image-duck;

            defxmax10
            defymax7


            foreach x in 0,...,xmax
            foreach y in 0,...,ymax

            ifnumy=0
            defbottom0
            else
            pgfmathrandomitembottominout%
            fi

            ifnumx=xmax
            defright0
            else
            pgfmathrandomitemrightinout%
            fi

            beginscope[xshift=x cm, yshift=y cm]
            piecebottomright
            endscope



            draw (0,0) -- (0,ymax+1) -- (xmax+1,ymax+1);

            endtikzpicture

            enddocument


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 17 at 13:17

























            answered Aug 16 at 15:00









            samcarter

            74.1k785238




            74.1k785238











            • I didn't see your update till now. Coincidently we have the same conventions for in and out. Weird. ;-) ;-)
              – marmot
              Aug 16 at 17:16










            • @marmot 50:50 chance :)
              – samcarter
              Aug 16 at 17:20










            • Yes, and how many % to use integers for that? ;-)
              – marmot
              Aug 16 at 17:21






            • 1




              @marmot 100%, it is so convenient to control the direction by simply multiplying :)
              – samcarter
              Aug 16 at 17:24










            • great solution, thank you!
              – sebastian
              Aug 17 at 12:03
















            • I didn't see your update till now. Coincidently we have the same conventions for in and out. Weird. ;-) ;-)
              – marmot
              Aug 16 at 17:16










            • @marmot 50:50 chance :)
              – samcarter
              Aug 16 at 17:20










            • Yes, and how many % to use integers for that? ;-)
              – marmot
              Aug 16 at 17:21






            • 1




              @marmot 100%, it is so convenient to control the direction by simply multiplying :)
              – samcarter
              Aug 16 at 17:24










            • great solution, thank you!
              – sebastian
              Aug 17 at 12:03















            I didn't see your update till now. Coincidently we have the same conventions for in and out. Weird. ;-) ;-)
            – marmot
            Aug 16 at 17:16




            I didn't see your update till now. Coincidently we have the same conventions for in and out. Weird. ;-) ;-)
            – marmot
            Aug 16 at 17:16












            @marmot 50:50 chance :)
            – samcarter
            Aug 16 at 17:20




            @marmot 50:50 chance :)
            – samcarter
            Aug 16 at 17:20












            Yes, and how many % to use integers for that? ;-)
            – marmot
            Aug 16 at 17:21




            Yes, and how many % to use integers for that? ;-)
            – marmot
            Aug 16 at 17:21




            1




            1




            @marmot 100%, it is so convenient to control the direction by simply multiplying :)
            – samcarter
            Aug 16 at 17:24




            @marmot 100%, it is so convenient to control the direction by simply multiplying :)
            – samcarter
            Aug 16 at 17:24












            great solution, thank you!
            – sebastian
            Aug 17 at 12:03




            great solution, thank you!
            – sebastian
            Aug 17 at 12:03










            up vote
            6
            down vote













            An option using [out=Angle,in=Angle,out looseness=Value,in looseness=Value] and coordinate calculations to draw rotated shape; then other tricks to control sizes, angles ,positions and colors.



            RESULT:



            enter image description here



            MWE:



            documentclass[border=10pt]standalone
            usepackagetikz
            usetikzlibraryarrows.meta,calc,fit,shapes

            begindocument
            begintikzpicture
            defJigzawPiece(#1)[#2]#3#4
            beginscope[shift=(#1),rotate=#4,transform shape]
            coordinate (a) at (0:#2);coordinate (b) at (90:#2);coordinate (c) at (180:#2);coordinate (d) at (270:#2);
            foreach nodA/nodB in a/b,b/c,c/d,d/a
            coordinate (nodAnodB1) at ($ (nodA)!0.4!(nodB) $);
            coordinate (nodAnodB2) at ($ (nodA)!0.6!(nodB) $);
            coordinate (nodAnodB3) at ($ (nodA)!0.5!(nodB) $);
            coordinate (nodAnodB4) at ($(nodAnodB3)!0.5*#2 cm!90:(nodA)$);
            coordinate (nodAnodB5) at ($(nodAnodB3)!-0.5*#2 cm!90:(nodA)$);

            draw[fill=#3]
            (a) -- (ab1)
            to [out=133,in=-45,out looseness=1,in looseness=2] (ab5)
            to [out=135,in=-45,out looseness=2,in looseness=1] (ab2) --
            (b) -- (bc1)
            to [out=-135,in=45,out looseness=1,in looseness=2] (bc4)
            to [out=-135,in=45,out looseness=2,in looseness=1] (bc2) --
            (c) -- (cd1)
            to [out=-45,in=135,out looseness=1,in looseness=2] (cd4)
            to [out=-45,in=135,out looseness=2,in looseness=1] (cd2) --
            (d) -- (da1)
            to [out=45,in=-135,out looseness=1,in looseness=2] (da5)
            to [out=45,in=-135,out looseness=2,in looseness=1] (da2) --(a);
            endscope


            foreach x in 0,1,...,7
            foreach y in 0,1,...,5
            pgfmathparse0.9*rnd+0.3
            definecolorRcolorrgbpgfmathresult,pgfmathresult,pgfmathresult % from https://tex.stackexchange.com/a/37279/154390
            JigzawPiece(x,y)[0.5]blue!50!Rcolor0
            JigzawPiece(x+0.5,y+0.5)[0.5]blue!30!Rcolor0


            foreach ang [count=j from 0] in 0,90,180,270
            JigzawPiece(0.5+j*2,7)[1]redang


            foreach ang [count=j from 0] in -45,45,45,-45,-45
            JigzawPiece(0.5+j*1.4142,9)[1]redang

            endtikzpicture

            enddocument





            share|improve this answer
























              up vote
              6
              down vote













              An option using [out=Angle,in=Angle,out looseness=Value,in looseness=Value] and coordinate calculations to draw rotated shape; then other tricks to control sizes, angles ,positions and colors.



              RESULT:



              enter image description here



              MWE:



              documentclass[border=10pt]standalone
              usepackagetikz
              usetikzlibraryarrows.meta,calc,fit,shapes

              begindocument
              begintikzpicture
              defJigzawPiece(#1)[#2]#3#4
              beginscope[shift=(#1),rotate=#4,transform shape]
              coordinate (a) at (0:#2);coordinate (b) at (90:#2);coordinate (c) at (180:#2);coordinate (d) at (270:#2);
              foreach nodA/nodB in a/b,b/c,c/d,d/a
              coordinate (nodAnodB1) at ($ (nodA)!0.4!(nodB) $);
              coordinate (nodAnodB2) at ($ (nodA)!0.6!(nodB) $);
              coordinate (nodAnodB3) at ($ (nodA)!0.5!(nodB) $);
              coordinate (nodAnodB4) at ($(nodAnodB3)!0.5*#2 cm!90:(nodA)$);
              coordinate (nodAnodB5) at ($(nodAnodB3)!-0.5*#2 cm!90:(nodA)$);

              draw[fill=#3]
              (a) -- (ab1)
              to [out=133,in=-45,out looseness=1,in looseness=2] (ab5)
              to [out=135,in=-45,out looseness=2,in looseness=1] (ab2) --
              (b) -- (bc1)
              to [out=-135,in=45,out looseness=1,in looseness=2] (bc4)
              to [out=-135,in=45,out looseness=2,in looseness=1] (bc2) --
              (c) -- (cd1)
              to [out=-45,in=135,out looseness=1,in looseness=2] (cd4)
              to [out=-45,in=135,out looseness=2,in looseness=1] (cd2) --
              (d) -- (da1)
              to [out=45,in=-135,out looseness=1,in looseness=2] (da5)
              to [out=45,in=-135,out looseness=2,in looseness=1] (da2) --(a);
              endscope


              foreach x in 0,1,...,7
              foreach y in 0,1,...,5
              pgfmathparse0.9*rnd+0.3
              definecolorRcolorrgbpgfmathresult,pgfmathresult,pgfmathresult % from https://tex.stackexchange.com/a/37279/154390
              JigzawPiece(x,y)[0.5]blue!50!Rcolor0
              JigzawPiece(x+0.5,y+0.5)[0.5]blue!30!Rcolor0


              foreach ang [count=j from 0] in 0,90,180,270
              JigzawPiece(0.5+j*2,7)[1]redang


              foreach ang [count=j from 0] in -45,45,45,-45,-45
              JigzawPiece(0.5+j*1.4142,9)[1]redang

              endtikzpicture

              enddocument





              share|improve this answer






















                up vote
                6
                down vote










                up vote
                6
                down vote









                An option using [out=Angle,in=Angle,out looseness=Value,in looseness=Value] and coordinate calculations to draw rotated shape; then other tricks to control sizes, angles ,positions and colors.



                RESULT:



                enter image description here



                MWE:



                documentclass[border=10pt]standalone
                usepackagetikz
                usetikzlibraryarrows.meta,calc,fit,shapes

                begindocument
                begintikzpicture
                defJigzawPiece(#1)[#2]#3#4
                beginscope[shift=(#1),rotate=#4,transform shape]
                coordinate (a) at (0:#2);coordinate (b) at (90:#2);coordinate (c) at (180:#2);coordinate (d) at (270:#2);
                foreach nodA/nodB in a/b,b/c,c/d,d/a
                coordinate (nodAnodB1) at ($ (nodA)!0.4!(nodB) $);
                coordinate (nodAnodB2) at ($ (nodA)!0.6!(nodB) $);
                coordinate (nodAnodB3) at ($ (nodA)!0.5!(nodB) $);
                coordinate (nodAnodB4) at ($(nodAnodB3)!0.5*#2 cm!90:(nodA)$);
                coordinate (nodAnodB5) at ($(nodAnodB3)!-0.5*#2 cm!90:(nodA)$);

                draw[fill=#3]
                (a) -- (ab1)
                to [out=133,in=-45,out looseness=1,in looseness=2] (ab5)
                to [out=135,in=-45,out looseness=2,in looseness=1] (ab2) --
                (b) -- (bc1)
                to [out=-135,in=45,out looseness=1,in looseness=2] (bc4)
                to [out=-135,in=45,out looseness=2,in looseness=1] (bc2) --
                (c) -- (cd1)
                to [out=-45,in=135,out looseness=1,in looseness=2] (cd4)
                to [out=-45,in=135,out looseness=2,in looseness=1] (cd2) --
                (d) -- (da1)
                to [out=45,in=-135,out looseness=1,in looseness=2] (da5)
                to [out=45,in=-135,out looseness=2,in looseness=1] (da2) --(a);
                endscope


                foreach x in 0,1,...,7
                foreach y in 0,1,...,5
                pgfmathparse0.9*rnd+0.3
                definecolorRcolorrgbpgfmathresult,pgfmathresult,pgfmathresult % from https://tex.stackexchange.com/a/37279/154390
                JigzawPiece(x,y)[0.5]blue!50!Rcolor0
                JigzawPiece(x+0.5,y+0.5)[0.5]blue!30!Rcolor0


                foreach ang [count=j from 0] in 0,90,180,270
                JigzawPiece(0.5+j*2,7)[1]redang


                foreach ang [count=j from 0] in -45,45,45,-45,-45
                JigzawPiece(0.5+j*1.4142,9)[1]redang

                endtikzpicture

                enddocument





                share|improve this answer












                An option using [out=Angle,in=Angle,out looseness=Value,in looseness=Value] and coordinate calculations to draw rotated shape; then other tricks to control sizes, angles ,positions and colors.



                RESULT:



                enter image description here



                MWE:



                documentclass[border=10pt]standalone
                usepackagetikz
                usetikzlibraryarrows.meta,calc,fit,shapes

                begindocument
                begintikzpicture
                defJigzawPiece(#1)[#2]#3#4
                beginscope[shift=(#1),rotate=#4,transform shape]
                coordinate (a) at (0:#2);coordinate (b) at (90:#2);coordinate (c) at (180:#2);coordinate (d) at (270:#2);
                foreach nodA/nodB in a/b,b/c,c/d,d/a
                coordinate (nodAnodB1) at ($ (nodA)!0.4!(nodB) $);
                coordinate (nodAnodB2) at ($ (nodA)!0.6!(nodB) $);
                coordinate (nodAnodB3) at ($ (nodA)!0.5!(nodB) $);
                coordinate (nodAnodB4) at ($(nodAnodB3)!0.5*#2 cm!90:(nodA)$);
                coordinate (nodAnodB5) at ($(nodAnodB3)!-0.5*#2 cm!90:(nodA)$);

                draw[fill=#3]
                (a) -- (ab1)
                to [out=133,in=-45,out looseness=1,in looseness=2] (ab5)
                to [out=135,in=-45,out looseness=2,in looseness=1] (ab2) --
                (b) -- (bc1)
                to [out=-135,in=45,out looseness=1,in looseness=2] (bc4)
                to [out=-135,in=45,out looseness=2,in looseness=1] (bc2) --
                (c) -- (cd1)
                to [out=-45,in=135,out looseness=1,in looseness=2] (cd4)
                to [out=-45,in=135,out looseness=2,in looseness=1] (cd2) --
                (d) -- (da1)
                to [out=45,in=-135,out looseness=1,in looseness=2] (da5)
                to [out=45,in=-135,out looseness=2,in looseness=1] (da2) --(a);
                endscope


                foreach x in 0,1,...,7
                foreach y in 0,1,...,5
                pgfmathparse0.9*rnd+0.3
                definecolorRcolorrgbpgfmathresult,pgfmathresult,pgfmathresult % from https://tex.stackexchange.com/a/37279/154390
                JigzawPiece(x,y)[0.5]blue!50!Rcolor0
                JigzawPiece(x+0.5,y+0.5)[0.5]blue!30!Rcolor0


                foreach ang [count=j from 0] in 0,90,180,270
                JigzawPiece(0.5+j*2,7)[1]redang


                foreach ang [count=j from 0] in -45,45,45,-45,-45
                JigzawPiece(0.5+j*1.4142,9)[1]redang

                endtikzpicture

                enddocument






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 16 at 17:31









                J Leon V.

                6,041527




                6,041527



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f446292%2ftikz-jigsaw-puzzle-boundary-shape%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery