3
$\begingroup$

I have been making cantor type sets. I have the following code, how to lower the position of gray lines a bit so that I can see the intersection.

The code is:

cantorRule = Line[{{a_, n_}, {b_, n_}}] :> With[{d = b - a, np = n - 0.1`},
   {Line[{{a, np}, {a + (3 d)/4, np}}], Line[{{b - d/2, np}, {b, np}}]}
  ]
label = # /. l : Line[p : {{_, _}, {_, _}}] :> {l, Black, Text[Rationalize[#[[1]]], Offset[{0, -20}, #], {Center, Top}] & /@ p} &;
lines = Flatten@NestList[# /. cantorRule &, Line[{{0., 0}, {1., 0}}], 6];
coloredlines = Flatten[Riffle[{Black, Gray}, #] & /@ Partition[lines, 2, 2, {-1, 1}, {}]];
Graphics[{CapForm["Butt"], Thickness[.05], coloredlines}]
$\endgroup$
2
  • 1
    $\begingroup$ I have removed your commented code. Feel free to put that back in if you want, but I assume that since it's commented, it's unnecessary to your question, and so it doesn't need to be included.) $\endgroup$
    – march
    Aug 26, 2019 at 17:43
  • $\begingroup$ @march yes, sorry for that. How can I shift the grey lines bit down so that the intersection can be identified? $\endgroup$
    – Praveen
    Aug 26, 2019 at 17:46

1 Answer 1

3
$\begingroup$
s = .02;
coloredlines = Riffle[{Black, Gray}, #] & /@ Partition[lines, 2, 2, {-1, 1}, {}];

coloredlines2 = MapAt[# /.  Line[{{a_, b_}, {c_, b_}}] :> Line[{{a, b - s}, {c, b - s}}] &,
  coloredlines, {All, 3 ;;}];

Graphics[{CapForm["Butt"], Thickness[.05], coloredlines2}]

enter image description here

You can also use

coloredlines3 = MapAt[# /. l_Line :> Translate[l, {0, -s}]&, coloredlines, {All, 3 ;;}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.