Chaos game to get specific fractal












3












$begingroup$


In the wikipedia page for Chaos Game, you can see this fractal, which is the result of the rule:




A point inside a square repeatedly jumps half of the distance towards a randomly chosen vertex, but the currently chosen vertex cannot be 1 or 3 places, respectively away from the two previously chosen vertices.




However, that is unlikely since the rule implies that all the point will do is to get closer to vertex 1 or 3 (or 2 or 4), so that the image after some iterations would be a line joining both vertices.



Can you give a rule that produces the desired fractal?










share|cite|improve this question











$endgroup$












  • $begingroup$
    I think you may have misinterpreted that (very confusing) sentence; it's not that the next vertex must not be $1$ or $3$ places away from the current vertex, but that it cannot be $1$ place away from the current vertex, or $3$ places away from the previous vertex. This rule doesn't force it to get stuck on a diagonal.
    $endgroup$
    – Milo Brandt
    Dec 29 '17 at 16:51










  • $begingroup$
    @MiloBrandt Yes, but 1 place away and 3 places away are exactly the same thing, since vertex are in $mathbb{Z}_4$.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 16:12












  • $begingroup$
    @SergioEnriqueYarzaAcuña Not if you consider orientation. For example, 3 is one place away from 2, but three places away from 4. Thus if the last two vertices were $(1,4)$, then the next vertex cannot be 4 (as this would be 3 places away from 1), and it cannot be 1 (as this would be one place away from 4). Either of the other two remaining vertices are allowed.
    $endgroup$
    – Xander Henderson
    Dec 30 '17 at 16:28










  • $begingroup$
    @XanderHenderson If you check the rest of rules in the Wikipedia page, you'll see that whenever orientation is relevant, it is specified. However, if you consider orientation, you get the bottom-right figure in the first four for Fabio's partial answer.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 17:58










  • $begingroup$
    @SergioEnriqueYarzaAcuña If you look at the talk portion of the Wikipedia page, it is clear that noone really understands what that image is. The description of the image is inchoate, whether or not orientation matters.
    $endgroup$
    – Xander Henderson
    Dec 30 '17 at 20:03
















3












$begingroup$


In the wikipedia page for Chaos Game, you can see this fractal, which is the result of the rule:




A point inside a square repeatedly jumps half of the distance towards a randomly chosen vertex, but the currently chosen vertex cannot be 1 or 3 places, respectively away from the two previously chosen vertices.




However, that is unlikely since the rule implies that all the point will do is to get closer to vertex 1 or 3 (or 2 or 4), so that the image after some iterations would be a line joining both vertices.



Can you give a rule that produces the desired fractal?










share|cite|improve this question











$endgroup$












  • $begingroup$
    I think you may have misinterpreted that (very confusing) sentence; it's not that the next vertex must not be $1$ or $3$ places away from the current vertex, but that it cannot be $1$ place away from the current vertex, or $3$ places away from the previous vertex. This rule doesn't force it to get stuck on a diagonal.
    $endgroup$
    – Milo Brandt
    Dec 29 '17 at 16:51










  • $begingroup$
    @MiloBrandt Yes, but 1 place away and 3 places away are exactly the same thing, since vertex are in $mathbb{Z}_4$.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 16:12












  • $begingroup$
    @SergioEnriqueYarzaAcuña Not if you consider orientation. For example, 3 is one place away from 2, but three places away from 4. Thus if the last two vertices were $(1,4)$, then the next vertex cannot be 4 (as this would be 3 places away from 1), and it cannot be 1 (as this would be one place away from 4). Either of the other two remaining vertices are allowed.
    $endgroup$
    – Xander Henderson
    Dec 30 '17 at 16:28










  • $begingroup$
    @XanderHenderson If you check the rest of rules in the Wikipedia page, you'll see that whenever orientation is relevant, it is specified. However, if you consider orientation, you get the bottom-right figure in the first four for Fabio's partial answer.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 17:58










  • $begingroup$
    @SergioEnriqueYarzaAcuña If you look at the talk portion of the Wikipedia page, it is clear that noone really understands what that image is. The description of the image is inchoate, whether or not orientation matters.
    $endgroup$
    – Xander Henderson
    Dec 30 '17 at 20:03














3












3








3


1



$begingroup$


In the wikipedia page for Chaos Game, you can see this fractal, which is the result of the rule:




A point inside a square repeatedly jumps half of the distance towards a randomly chosen vertex, but the currently chosen vertex cannot be 1 or 3 places, respectively away from the two previously chosen vertices.




However, that is unlikely since the rule implies that all the point will do is to get closer to vertex 1 or 3 (or 2 or 4), so that the image after some iterations would be a line joining both vertices.



Can you give a rule that produces the desired fractal?










share|cite|improve this question











$endgroup$




In the wikipedia page for Chaos Game, you can see this fractal, which is the result of the rule:




A point inside a square repeatedly jumps half of the distance towards a randomly chosen vertex, but the currently chosen vertex cannot be 1 or 3 places, respectively away from the two previously chosen vertices.




However, that is unlikely since the rule implies that all the point will do is to get closer to vertex 1 or 3 (or 2 or 4), so that the image after some iterations would be a line joining both vertices.



Can you give a rule that produces the desired fractal?







stochastic-processes fractals chaos-theory






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 29 '17 at 3:10









Xander Henderson

14.3k103554




14.3k103554










asked Dec 29 '17 at 2:59









Sergio Enrique Yarza AcuñaSergio Enrique Yarza Acuña

695314




695314












  • $begingroup$
    I think you may have misinterpreted that (very confusing) sentence; it's not that the next vertex must not be $1$ or $3$ places away from the current vertex, but that it cannot be $1$ place away from the current vertex, or $3$ places away from the previous vertex. This rule doesn't force it to get stuck on a diagonal.
    $endgroup$
    – Milo Brandt
    Dec 29 '17 at 16:51










  • $begingroup$
    @MiloBrandt Yes, but 1 place away and 3 places away are exactly the same thing, since vertex are in $mathbb{Z}_4$.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 16:12












  • $begingroup$
    @SergioEnriqueYarzaAcuña Not if you consider orientation. For example, 3 is one place away from 2, but three places away from 4. Thus if the last two vertices were $(1,4)$, then the next vertex cannot be 4 (as this would be 3 places away from 1), and it cannot be 1 (as this would be one place away from 4). Either of the other two remaining vertices are allowed.
    $endgroup$
    – Xander Henderson
    Dec 30 '17 at 16:28










  • $begingroup$
    @XanderHenderson If you check the rest of rules in the Wikipedia page, you'll see that whenever orientation is relevant, it is specified. However, if you consider orientation, you get the bottom-right figure in the first four for Fabio's partial answer.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 17:58










  • $begingroup$
    @SergioEnriqueYarzaAcuña If you look at the talk portion of the Wikipedia page, it is clear that noone really understands what that image is. The description of the image is inchoate, whether or not orientation matters.
    $endgroup$
    – Xander Henderson
    Dec 30 '17 at 20:03


















  • $begingroup$
    I think you may have misinterpreted that (very confusing) sentence; it's not that the next vertex must not be $1$ or $3$ places away from the current vertex, but that it cannot be $1$ place away from the current vertex, or $3$ places away from the previous vertex. This rule doesn't force it to get stuck on a diagonal.
    $endgroup$
    – Milo Brandt
    Dec 29 '17 at 16:51










  • $begingroup$
    @MiloBrandt Yes, but 1 place away and 3 places away are exactly the same thing, since vertex are in $mathbb{Z}_4$.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 16:12












  • $begingroup$
    @SergioEnriqueYarzaAcuña Not if you consider orientation. For example, 3 is one place away from 2, but three places away from 4. Thus if the last two vertices were $(1,4)$, then the next vertex cannot be 4 (as this would be 3 places away from 1), and it cannot be 1 (as this would be one place away from 4). Either of the other two remaining vertices are allowed.
    $endgroup$
    – Xander Henderson
    Dec 30 '17 at 16:28










  • $begingroup$
    @XanderHenderson If you check the rest of rules in the Wikipedia page, you'll see that whenever orientation is relevant, it is specified. However, if you consider orientation, you get the bottom-right figure in the first four for Fabio's partial answer.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 17:58










  • $begingroup$
    @SergioEnriqueYarzaAcuña If you look at the talk portion of the Wikipedia page, it is clear that noone really understands what that image is. The description of the image is inchoate, whether or not orientation matters.
    $endgroup$
    – Xander Henderson
    Dec 30 '17 at 20:03
















$begingroup$
I think you may have misinterpreted that (very confusing) sentence; it's not that the next vertex must not be $1$ or $3$ places away from the current vertex, but that it cannot be $1$ place away from the current vertex, or $3$ places away from the previous vertex. This rule doesn't force it to get stuck on a diagonal.
$endgroup$
– Milo Brandt
Dec 29 '17 at 16:51




$begingroup$
I think you may have misinterpreted that (very confusing) sentence; it's not that the next vertex must not be $1$ or $3$ places away from the current vertex, but that it cannot be $1$ place away from the current vertex, or $3$ places away from the previous vertex. This rule doesn't force it to get stuck on a diagonal.
$endgroup$
– Milo Brandt
Dec 29 '17 at 16:51












$begingroup$
@MiloBrandt Yes, but 1 place away and 3 places away are exactly the same thing, since vertex are in $mathbb{Z}_4$.
$endgroup$
– Sergio Enrique Yarza Acuña
Dec 30 '17 at 16:12






$begingroup$
@MiloBrandt Yes, but 1 place away and 3 places away are exactly the same thing, since vertex are in $mathbb{Z}_4$.
$endgroup$
– Sergio Enrique Yarza Acuña
Dec 30 '17 at 16:12














$begingroup$
@SergioEnriqueYarzaAcuña Not if you consider orientation. For example, 3 is one place away from 2, but three places away from 4. Thus if the last two vertices were $(1,4)$, then the next vertex cannot be 4 (as this would be 3 places away from 1), and it cannot be 1 (as this would be one place away from 4). Either of the other two remaining vertices are allowed.
$endgroup$
– Xander Henderson
Dec 30 '17 at 16:28




$begingroup$
@SergioEnriqueYarzaAcuña Not if you consider orientation. For example, 3 is one place away from 2, but three places away from 4. Thus if the last two vertices were $(1,4)$, then the next vertex cannot be 4 (as this would be 3 places away from 1), and it cannot be 1 (as this would be one place away from 4). Either of the other two remaining vertices are allowed.
$endgroup$
– Xander Henderson
Dec 30 '17 at 16:28












$begingroup$
@XanderHenderson If you check the rest of rules in the Wikipedia page, you'll see that whenever orientation is relevant, it is specified. However, if you consider orientation, you get the bottom-right figure in the first four for Fabio's partial answer.
$endgroup$
– Sergio Enrique Yarza Acuña
Dec 30 '17 at 17:58




$begingroup$
@XanderHenderson If you check the rest of rules in the Wikipedia page, you'll see that whenever orientation is relevant, it is specified. However, if you consider orientation, you get the bottom-right figure in the first four for Fabio's partial answer.
$endgroup$
– Sergio Enrique Yarza Acuña
Dec 30 '17 at 17:58












$begingroup$
@SergioEnriqueYarzaAcuña If you look at the talk portion of the Wikipedia page, it is clear that noone really understands what that image is. The description of the image is inchoate, whether or not orientation matters.
$endgroup$
– Xander Henderson
Dec 30 '17 at 20:03




$begingroup$
@SergioEnriqueYarzaAcuña If you look at the talk portion of the Wikipedia page, it is clear that noone really understands what that image is. The description of the image is inchoate, whether or not orientation matters.
$endgroup$
– Xander Henderson
Dec 30 '17 at 20:03










2 Answers
2






active

oldest

votes


















3












$begingroup$

Partial answer. I wrote the following MATLAB function to produce those pretty pictures:



function chaosGame(forbidden, mode, side, points)
% CHAOSGAME play a chaos game
%
% https://en.wikipedia.org/wiki/Chaos_game
%
% A point inside a square repeatedly jumps half the distance
% towards a randomly chosen vertex, but the currently chosen
% vertex must obey the constraint specified by forbidden and
% mode.
%
% - forbidden is a row vector with values from {0,1,2,3,NaN}.
% - mode is either 'all' or 'any'
%
% If forbidden(k) is m, then the current vertex should not be
% m places away (counterclockwise) from the one chosen k
% turns before. If forbidden(k) is NaN, the vertex chosen
% k turns before imposes no constraint.
%
% If mode is 'all' all constraints specified by forbidden must
% be satisfied. If mode is 'any' at least one constraint must
% be satisfied. Using NaN with 'any' gives an unconstrained
% choice.

if nargin < 1 || isempty(forbidden)
forbidden = [1 3];
end
if nargin < 2 || isempty(mode)
mode = 'all';
end
if nargin < 3 || isempty(side)
side = 1000;
end
if nargin < 4 || isempty(points)
points = fix(side.^2);
end

switch mode
case {'all'}
compareall = true;
case {'any'}
compareall = false;
otherwise
error('mode should be either all or any')
end

% Start with a white canvas.
canvas = ones(side);
% List vertices from top left counterclockwise.
vertices = [1 1; 1 side; side side; side 1];
% Past vertex indices (which are in {0,1,2,3}) are initially
% invalid (-1) so that the first vertex choice is free.
past = -ones(size(forbidden));
% Pick random starting point inside the canvas.
p = side * rand(1,2);
canvas(fix(p(1)), fix(p(2))) = 0;

for n = 1:points
while 1
pick = randi([0 3]);
d = mod(pick + forbidden, 4);
if compareall
validchoice = all(d ~= past);
else
validchoice = any(d ~= past);
end
if validchoice
past = [pick past(1:end-1)];
break
end
end
vert = vertices(pick+1,:);
p = (vert + p) / 2;
canvas(fix(p(1)), fix(p(2))) = 0;
end
imshow(canvas,'InitialMagnification','fit')
end


This is what I got for forbidden set to $0$, $1$, $2$, and $[1,3]$ (from top to bottom, and from left to right):



enter image description here



I'm not sure the $[1,3]$ picture is what you describe, but it's definitely not the one on the Wikipedia page. The 'any' mode also produces some nice graphs:



enter image description here



As one would expect, there are more black points, but we are still far from the desired result.



(Note: the function also works with Octave (except for an inessential warning) but is much slower.)






share|cite|improve this answer









$endgroup$













  • $begingroup$
    Hi, I'm upvoting but not selecting because you're not giving the complete answer.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 16:16










  • $begingroup$
    @SergioEnriqueYarzaAcuña Agreed: not selecting is the right thing to do. BTW, the "talk" section of the Wikipedia page records another case of someone who could not reproduce the $[1,3]$ fractal. At this point, my script also deals with general regular polygons, and the same problem occurs with the pentagonal graphs: it reproduces the one with the simple $[0]$ constraint, but not the one with the $[1,4]$ constraint.
    $endgroup$
    – Fabio Somenzi
    Dec 30 '17 at 19:23



















0












$begingroup$

Dividing the image into 8×8 squares like a chessboard, we see that the two middle squares on each side are empty. That means each of the following triples of consecutive vertex moves must be disallowed:



↖↖↙, ↖↖↗, ↗↗↖, ↗↗↘, ↘↘↗, ↘↘↙, ↙↙↘, ↙↙↖.



In other words: “if the two previously chosen vertices were the same, then the currently chosen vertex cannot be 1 or 3 places away”.



Indeed, that rule reproduces the given picture perfectly.



result






share|cite|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "69"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2583781%2fchaos-game-to-get-specific-fractal%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3












    $begingroup$

    Partial answer. I wrote the following MATLAB function to produce those pretty pictures:



    function chaosGame(forbidden, mode, side, points)
    % CHAOSGAME play a chaos game
    %
    % https://en.wikipedia.org/wiki/Chaos_game
    %
    % A point inside a square repeatedly jumps half the distance
    % towards a randomly chosen vertex, but the currently chosen
    % vertex must obey the constraint specified by forbidden and
    % mode.
    %
    % - forbidden is a row vector with values from {0,1,2,3,NaN}.
    % - mode is either 'all' or 'any'
    %
    % If forbidden(k) is m, then the current vertex should not be
    % m places away (counterclockwise) from the one chosen k
    % turns before. If forbidden(k) is NaN, the vertex chosen
    % k turns before imposes no constraint.
    %
    % If mode is 'all' all constraints specified by forbidden must
    % be satisfied. If mode is 'any' at least one constraint must
    % be satisfied. Using NaN with 'any' gives an unconstrained
    % choice.

    if nargin < 1 || isempty(forbidden)
    forbidden = [1 3];
    end
    if nargin < 2 || isempty(mode)
    mode = 'all';
    end
    if nargin < 3 || isempty(side)
    side = 1000;
    end
    if nargin < 4 || isempty(points)
    points = fix(side.^2);
    end

    switch mode
    case {'all'}
    compareall = true;
    case {'any'}
    compareall = false;
    otherwise
    error('mode should be either all or any')
    end

    % Start with a white canvas.
    canvas = ones(side);
    % List vertices from top left counterclockwise.
    vertices = [1 1; 1 side; side side; side 1];
    % Past vertex indices (which are in {0,1,2,3}) are initially
    % invalid (-1) so that the first vertex choice is free.
    past = -ones(size(forbidden));
    % Pick random starting point inside the canvas.
    p = side * rand(1,2);
    canvas(fix(p(1)), fix(p(2))) = 0;

    for n = 1:points
    while 1
    pick = randi([0 3]);
    d = mod(pick + forbidden, 4);
    if compareall
    validchoice = all(d ~= past);
    else
    validchoice = any(d ~= past);
    end
    if validchoice
    past = [pick past(1:end-1)];
    break
    end
    end
    vert = vertices(pick+1,:);
    p = (vert + p) / 2;
    canvas(fix(p(1)), fix(p(2))) = 0;
    end
    imshow(canvas,'InitialMagnification','fit')
    end


    This is what I got for forbidden set to $0$, $1$, $2$, and $[1,3]$ (from top to bottom, and from left to right):



    enter image description here



    I'm not sure the $[1,3]$ picture is what you describe, but it's definitely not the one on the Wikipedia page. The 'any' mode also produces some nice graphs:



    enter image description here



    As one would expect, there are more black points, but we are still far from the desired result.



    (Note: the function also works with Octave (except for an inessential warning) but is much slower.)






    share|cite|improve this answer









    $endgroup$













    • $begingroup$
      Hi, I'm upvoting but not selecting because you're not giving the complete answer.
      $endgroup$
      – Sergio Enrique Yarza Acuña
      Dec 30 '17 at 16:16










    • $begingroup$
      @SergioEnriqueYarzaAcuña Agreed: not selecting is the right thing to do. BTW, the "talk" section of the Wikipedia page records another case of someone who could not reproduce the $[1,3]$ fractal. At this point, my script also deals with general regular polygons, and the same problem occurs with the pentagonal graphs: it reproduces the one with the simple $[0]$ constraint, but not the one with the $[1,4]$ constraint.
      $endgroup$
      – Fabio Somenzi
      Dec 30 '17 at 19:23
















    3












    $begingroup$

    Partial answer. I wrote the following MATLAB function to produce those pretty pictures:



    function chaosGame(forbidden, mode, side, points)
    % CHAOSGAME play a chaos game
    %
    % https://en.wikipedia.org/wiki/Chaos_game
    %
    % A point inside a square repeatedly jumps half the distance
    % towards a randomly chosen vertex, but the currently chosen
    % vertex must obey the constraint specified by forbidden and
    % mode.
    %
    % - forbidden is a row vector with values from {0,1,2,3,NaN}.
    % - mode is either 'all' or 'any'
    %
    % If forbidden(k) is m, then the current vertex should not be
    % m places away (counterclockwise) from the one chosen k
    % turns before. If forbidden(k) is NaN, the vertex chosen
    % k turns before imposes no constraint.
    %
    % If mode is 'all' all constraints specified by forbidden must
    % be satisfied. If mode is 'any' at least one constraint must
    % be satisfied. Using NaN with 'any' gives an unconstrained
    % choice.

    if nargin < 1 || isempty(forbidden)
    forbidden = [1 3];
    end
    if nargin < 2 || isempty(mode)
    mode = 'all';
    end
    if nargin < 3 || isempty(side)
    side = 1000;
    end
    if nargin < 4 || isempty(points)
    points = fix(side.^2);
    end

    switch mode
    case {'all'}
    compareall = true;
    case {'any'}
    compareall = false;
    otherwise
    error('mode should be either all or any')
    end

    % Start with a white canvas.
    canvas = ones(side);
    % List vertices from top left counterclockwise.
    vertices = [1 1; 1 side; side side; side 1];
    % Past vertex indices (which are in {0,1,2,3}) are initially
    % invalid (-1) so that the first vertex choice is free.
    past = -ones(size(forbidden));
    % Pick random starting point inside the canvas.
    p = side * rand(1,2);
    canvas(fix(p(1)), fix(p(2))) = 0;

    for n = 1:points
    while 1
    pick = randi([0 3]);
    d = mod(pick + forbidden, 4);
    if compareall
    validchoice = all(d ~= past);
    else
    validchoice = any(d ~= past);
    end
    if validchoice
    past = [pick past(1:end-1)];
    break
    end
    end
    vert = vertices(pick+1,:);
    p = (vert + p) / 2;
    canvas(fix(p(1)), fix(p(2))) = 0;
    end
    imshow(canvas,'InitialMagnification','fit')
    end


    This is what I got for forbidden set to $0$, $1$, $2$, and $[1,3]$ (from top to bottom, and from left to right):



    enter image description here



    I'm not sure the $[1,3]$ picture is what you describe, but it's definitely not the one on the Wikipedia page. The 'any' mode also produces some nice graphs:



    enter image description here



    As one would expect, there are more black points, but we are still far from the desired result.



    (Note: the function also works with Octave (except for an inessential warning) but is much slower.)






    share|cite|improve this answer









    $endgroup$













    • $begingroup$
      Hi, I'm upvoting but not selecting because you're not giving the complete answer.
      $endgroup$
      – Sergio Enrique Yarza Acuña
      Dec 30 '17 at 16:16










    • $begingroup$
      @SergioEnriqueYarzaAcuña Agreed: not selecting is the right thing to do. BTW, the "talk" section of the Wikipedia page records another case of someone who could not reproduce the $[1,3]$ fractal. At this point, my script also deals with general regular polygons, and the same problem occurs with the pentagonal graphs: it reproduces the one with the simple $[0]$ constraint, but not the one with the $[1,4]$ constraint.
      $endgroup$
      – Fabio Somenzi
      Dec 30 '17 at 19:23














    3












    3








    3





    $begingroup$

    Partial answer. I wrote the following MATLAB function to produce those pretty pictures:



    function chaosGame(forbidden, mode, side, points)
    % CHAOSGAME play a chaos game
    %
    % https://en.wikipedia.org/wiki/Chaos_game
    %
    % A point inside a square repeatedly jumps half the distance
    % towards a randomly chosen vertex, but the currently chosen
    % vertex must obey the constraint specified by forbidden and
    % mode.
    %
    % - forbidden is a row vector with values from {0,1,2,3,NaN}.
    % - mode is either 'all' or 'any'
    %
    % If forbidden(k) is m, then the current vertex should not be
    % m places away (counterclockwise) from the one chosen k
    % turns before. If forbidden(k) is NaN, the vertex chosen
    % k turns before imposes no constraint.
    %
    % If mode is 'all' all constraints specified by forbidden must
    % be satisfied. If mode is 'any' at least one constraint must
    % be satisfied. Using NaN with 'any' gives an unconstrained
    % choice.

    if nargin < 1 || isempty(forbidden)
    forbidden = [1 3];
    end
    if nargin < 2 || isempty(mode)
    mode = 'all';
    end
    if nargin < 3 || isempty(side)
    side = 1000;
    end
    if nargin < 4 || isempty(points)
    points = fix(side.^2);
    end

    switch mode
    case {'all'}
    compareall = true;
    case {'any'}
    compareall = false;
    otherwise
    error('mode should be either all or any')
    end

    % Start with a white canvas.
    canvas = ones(side);
    % List vertices from top left counterclockwise.
    vertices = [1 1; 1 side; side side; side 1];
    % Past vertex indices (which are in {0,1,2,3}) are initially
    % invalid (-1) so that the first vertex choice is free.
    past = -ones(size(forbidden));
    % Pick random starting point inside the canvas.
    p = side * rand(1,2);
    canvas(fix(p(1)), fix(p(2))) = 0;

    for n = 1:points
    while 1
    pick = randi([0 3]);
    d = mod(pick + forbidden, 4);
    if compareall
    validchoice = all(d ~= past);
    else
    validchoice = any(d ~= past);
    end
    if validchoice
    past = [pick past(1:end-1)];
    break
    end
    end
    vert = vertices(pick+1,:);
    p = (vert + p) / 2;
    canvas(fix(p(1)), fix(p(2))) = 0;
    end
    imshow(canvas,'InitialMagnification','fit')
    end


    This is what I got for forbidden set to $0$, $1$, $2$, and $[1,3]$ (from top to bottom, and from left to right):



    enter image description here



    I'm not sure the $[1,3]$ picture is what you describe, but it's definitely not the one on the Wikipedia page. The 'any' mode also produces some nice graphs:



    enter image description here



    As one would expect, there are more black points, but we are still far from the desired result.



    (Note: the function also works with Octave (except for an inessential warning) but is much slower.)






    share|cite|improve this answer









    $endgroup$



    Partial answer. I wrote the following MATLAB function to produce those pretty pictures:



    function chaosGame(forbidden, mode, side, points)
    % CHAOSGAME play a chaos game
    %
    % https://en.wikipedia.org/wiki/Chaos_game
    %
    % A point inside a square repeatedly jumps half the distance
    % towards a randomly chosen vertex, but the currently chosen
    % vertex must obey the constraint specified by forbidden and
    % mode.
    %
    % - forbidden is a row vector with values from {0,1,2,3,NaN}.
    % - mode is either 'all' or 'any'
    %
    % If forbidden(k) is m, then the current vertex should not be
    % m places away (counterclockwise) from the one chosen k
    % turns before. If forbidden(k) is NaN, the vertex chosen
    % k turns before imposes no constraint.
    %
    % If mode is 'all' all constraints specified by forbidden must
    % be satisfied. If mode is 'any' at least one constraint must
    % be satisfied. Using NaN with 'any' gives an unconstrained
    % choice.

    if nargin < 1 || isempty(forbidden)
    forbidden = [1 3];
    end
    if nargin < 2 || isempty(mode)
    mode = 'all';
    end
    if nargin < 3 || isempty(side)
    side = 1000;
    end
    if nargin < 4 || isempty(points)
    points = fix(side.^2);
    end

    switch mode
    case {'all'}
    compareall = true;
    case {'any'}
    compareall = false;
    otherwise
    error('mode should be either all or any')
    end

    % Start with a white canvas.
    canvas = ones(side);
    % List vertices from top left counterclockwise.
    vertices = [1 1; 1 side; side side; side 1];
    % Past vertex indices (which are in {0,1,2,3}) are initially
    % invalid (-1) so that the first vertex choice is free.
    past = -ones(size(forbidden));
    % Pick random starting point inside the canvas.
    p = side * rand(1,2);
    canvas(fix(p(1)), fix(p(2))) = 0;

    for n = 1:points
    while 1
    pick = randi([0 3]);
    d = mod(pick + forbidden, 4);
    if compareall
    validchoice = all(d ~= past);
    else
    validchoice = any(d ~= past);
    end
    if validchoice
    past = [pick past(1:end-1)];
    break
    end
    end
    vert = vertices(pick+1,:);
    p = (vert + p) / 2;
    canvas(fix(p(1)), fix(p(2))) = 0;
    end
    imshow(canvas,'InitialMagnification','fit')
    end


    This is what I got for forbidden set to $0$, $1$, $2$, and $[1,3]$ (from top to bottom, and from left to right):



    enter image description here



    I'm not sure the $[1,3]$ picture is what you describe, but it's definitely not the one on the Wikipedia page. The 'any' mode also produces some nice graphs:



    enter image description here



    As one would expect, there are more black points, but we are still far from the desired result.



    (Note: the function also works with Octave (except for an inessential warning) but is much slower.)







    share|cite|improve this answer












    share|cite|improve this answer



    share|cite|improve this answer










    answered Dec 29 '17 at 16:26









    Fabio SomenziFabio Somenzi

    6,42321321




    6,42321321












    • $begingroup$
      Hi, I'm upvoting but not selecting because you're not giving the complete answer.
      $endgroup$
      – Sergio Enrique Yarza Acuña
      Dec 30 '17 at 16:16










    • $begingroup$
      @SergioEnriqueYarzaAcuña Agreed: not selecting is the right thing to do. BTW, the "talk" section of the Wikipedia page records another case of someone who could not reproduce the $[1,3]$ fractal. At this point, my script also deals with general regular polygons, and the same problem occurs with the pentagonal graphs: it reproduces the one with the simple $[0]$ constraint, but not the one with the $[1,4]$ constraint.
      $endgroup$
      – Fabio Somenzi
      Dec 30 '17 at 19:23


















    • $begingroup$
      Hi, I'm upvoting but not selecting because you're not giving the complete answer.
      $endgroup$
      – Sergio Enrique Yarza Acuña
      Dec 30 '17 at 16:16










    • $begingroup$
      @SergioEnriqueYarzaAcuña Agreed: not selecting is the right thing to do. BTW, the "talk" section of the Wikipedia page records another case of someone who could not reproduce the $[1,3]$ fractal. At this point, my script also deals with general regular polygons, and the same problem occurs with the pentagonal graphs: it reproduces the one with the simple $[0]$ constraint, but not the one with the $[1,4]$ constraint.
      $endgroup$
      – Fabio Somenzi
      Dec 30 '17 at 19:23
















    $begingroup$
    Hi, I'm upvoting but not selecting because you're not giving the complete answer.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 16:16




    $begingroup$
    Hi, I'm upvoting but not selecting because you're not giving the complete answer.
    $endgroup$
    – Sergio Enrique Yarza Acuña
    Dec 30 '17 at 16:16












    $begingroup$
    @SergioEnriqueYarzaAcuña Agreed: not selecting is the right thing to do. BTW, the "talk" section of the Wikipedia page records another case of someone who could not reproduce the $[1,3]$ fractal. At this point, my script also deals with general regular polygons, and the same problem occurs with the pentagonal graphs: it reproduces the one with the simple $[0]$ constraint, but not the one with the $[1,4]$ constraint.
    $endgroup$
    – Fabio Somenzi
    Dec 30 '17 at 19:23




    $begingroup$
    @SergioEnriqueYarzaAcuña Agreed: not selecting is the right thing to do. BTW, the "talk" section of the Wikipedia page records another case of someone who could not reproduce the $[1,3]$ fractal. At this point, my script also deals with general regular polygons, and the same problem occurs with the pentagonal graphs: it reproduces the one with the simple $[0]$ constraint, but not the one with the $[1,4]$ constraint.
    $endgroup$
    – Fabio Somenzi
    Dec 30 '17 at 19:23











    0












    $begingroup$

    Dividing the image into 8×8 squares like a chessboard, we see that the two middle squares on each side are empty. That means each of the following triples of consecutive vertex moves must be disallowed:



    ↖↖↙, ↖↖↗, ↗↗↖, ↗↗↘, ↘↘↗, ↘↘↙, ↙↙↘, ↙↙↖.



    In other words: “if the two previously chosen vertices were the same, then the currently chosen vertex cannot be 1 or 3 places away”.



    Indeed, that rule reproduces the given picture perfectly.



    result






    share|cite|improve this answer









    $endgroup$


















      0












      $begingroup$

      Dividing the image into 8×8 squares like a chessboard, we see that the two middle squares on each side are empty. That means each of the following triples of consecutive vertex moves must be disallowed:



      ↖↖↙, ↖↖↗, ↗↗↖, ↗↗↘, ↘↘↗, ↘↘↙, ↙↙↘, ↙↙↖.



      In other words: “if the two previously chosen vertices were the same, then the currently chosen vertex cannot be 1 or 3 places away”.



      Indeed, that rule reproduces the given picture perfectly.



      result






      share|cite|improve this answer









      $endgroup$
















        0












        0








        0





        $begingroup$

        Dividing the image into 8×8 squares like a chessboard, we see that the two middle squares on each side are empty. That means each of the following triples of consecutive vertex moves must be disallowed:



        ↖↖↙, ↖↖↗, ↗↗↖, ↗↗↘, ↘↘↗, ↘↘↙, ↙↙↘, ↙↙↖.



        In other words: “if the two previously chosen vertices were the same, then the currently chosen vertex cannot be 1 or 3 places away”.



        Indeed, that rule reproduces the given picture perfectly.



        result






        share|cite|improve this answer









        $endgroup$



        Dividing the image into 8×8 squares like a chessboard, we see that the two middle squares on each side are empty. That means each of the following triples of consecutive vertex moves must be disallowed:



        ↖↖↙, ↖↖↗, ↗↗↖, ↗↗↘, ↘↘↗, ↘↘↙, ↙↙↘, ↙↙↖.



        In other words: “if the two previously chosen vertices were the same, then the currently chosen vertex cannot be 1 or 3 places away”.



        Indeed, that rule reproduces the given picture perfectly.



        result







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Jan 7 at 8:30









        Anders KaseorgAnders Kaseorg

        77849




        77849






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematics Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2583781%2fchaos-game-to-get-specific-fractal%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith