1
$\begingroup$

I set up these:

T1 = AffineTransform[{{{1/3, 0}, {0, 1/3}}, {0, 0}}];
T2 = AffineTransform[{{{1/3, 0}, {0, 1/3}}, {1/3, 0}}];
T3 = AffineTransform[{{{1/3, 0}, {0, 1/3}}, {2/3, 0}}];
T4 = AffineTransform[{{{1/3, 0}, {0, 1/3}}, {0, 1/3}}]; 
T5 = AffineTransform[{{{1/3, 0}, {0, 1/3}}, {2/3, 1/3}}];
T6 = AffineTransform[{{{1/3, 0}, {0, 1/3}}, {0, 2/3}}];
T7 = AffineTransform[{{{1/3, 0}, {0, 1/3}}, {1/3, 2/3}}];
T8 = AffineTransform[{{{1/3, 0}, {0, 1/3}}, {2/3, 2/3}}];

Then I did this:

g1 = Graphics[{
   Rectangle[],
   Red, GeometricTransformation[
    Rectangle[], {T1, T2, T3, T4, T5, T6, T7, T8}]
   }]

Which worked nicely. My next thought was to apply the transformations to g1.

g2 = Graphics[{
   Rectangle[],
   Red, GeometricTransformation[g1, {T1, T2, T3, T4, T5, T6, T7, T8}]
   }]

But I got an error "Graphics is not a Graphics primitive or directive." What am I not understanding?

Thanks.

$\endgroup$
0

1 Answer 1

3
$\begingroup$

g2 just produces the same image g1 again

The new rectangles in g2 are not visible because they are all red. Change Red to a random color and they become visible:

g2 = Graphics[{Rectangle[], Hue[RandomReal[]], 
   GeometricTransformation[g1[[1]], {T1, T2, T3, T4, T5, T6, T7, T8}]}]

Mathematica graphics

What I want to do is apply the eight transformations to g1 again, to produce the second step of a Sierpinski Carpet.

g1 /. r : Rectangle[_] :> {Hue[RandomReal[]], 
   GeometricTransformation[r, {T1, T2, T3, T4, T5, T6, T7, T8}]}

Mathematica graphics

Grid[Partition[Nest[# /. r : Rectangle[_] :> 
     {Hue[RandomReal[]], GeometricTransformation[r, {T1, T2, T3, T4, T5, T6, T7, T8}]} &,
     g1, #] & /@ {1, 2, 3, 4}, 2]]

Mathematica graphics

Original post:

I got an error "Graphics is not a Graphics primitive or directive."

The first argument of GeometricTransformation should be a graphics primitive (such as Disk, Rectangle etc.). So GeometricTransformation[g1[[1]], {T1, T2, T3, T4, T5, T6, T7, T8}] works without complaint.

g2 = Graphics[{Rectangle[], Red, 
      GeometricTransformation[g1[[1]], {T1, T2, T3, T4, T5, T6, T7, T8}]}]

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ Sorry, this just produces the same image g1 again. What I want to do is apply the eight transformations to g1 again, to produce the second step of a Sierpinski Carpet. But thanks for the help. $\endgroup$
    – David
    Commented May 15, 2016 at 18:29
  • $\begingroup$ @David, please see the update. $\endgroup$
    – kglr
    Commented May 15, 2016 at 20:01
  • $\begingroup$ Absolutely awesome response! Thanks, this is so helpful. $\endgroup$
    – David
    Commented May 15, 2016 at 20:45
  • $\begingroup$ @David, great question. Thank you for the accept. $\endgroup$
    – kglr
    Commented May 15, 2016 at 20:53

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.