lundi 24 septembre 2018

convert unknown code to python for random mandala designs

There is a code on this website that I have no idea what language it is in. https://mathematica.stackexchange.com/questions/136974/code-that-generates-a-mandala

I would like to convert it to python. But I have no idea how to start on this project. what module are needed how to script it correctly.

Clear[MakeSeedSegment]
MakeSeedSegment[radius_, angle_, n_Integer: 10, connectingFunc_: Polygon, keepGridPoints_: False] :=
  Block[{t},
   t = Table[
     Line[{radius*r*{Cos[angle], Sin[angle]}, {radius*r, 0}}], {r, 0, 1, 1/n}];
   Join[If[TrueQ[keepGridPoints], t, {}], {GrayLevel[0.25], 
     connectingFunc@
      RandomSample[Flatten[t /. Line[{x_, y_}] :> {x, y}, 1]]}]
   ];

seed = MakeSeedSegment[10, \[Pi]/12, 10];
Graphics[seed, Frame -> True]

Clear[MakeSymmetric]
MakeSymmetric[seed_] := {seed, 
   GeometricTransformation[seed, ReflectionTransform[{0, 1}]]};

seed = MakeSymmetric[seed];
Graphics[seed, Frame -> True]

Clear[MakeMandala]
MakeMandala[opts : OptionsPattern[]] :=     
  MakeMandala[
   MakeSymmetric[
    MakeSeedSegment[20, \[Pi]/12, 12, 
     RandomChoice[{Line, Polygon, BezierCurve, 
       FilledCurve[BezierCurve[#]] &}], False]], \[Pi]/6, opts];
MakeMandala[seed_, angle_?NumericQ, opts : OptionsPattern[]] :=
  Graphics[GeometricTransformation[seed, 
    Table[RotationMatrix[a], {a, 0, 2 \[Pi] - angle, angle}]], opts];

n = 12;
Multicolumn@
 MapThread[
  If[#1,
    MakeMandala[MakeSeedSegment[10, #2, #3], #2],
    MakeMandala[MakeSymmetric[MakeSeedSegment[10, #2, #3, #4, False]],
      2 #2]
    ] &, {RandomChoice[{False, True}, n], 
   RandomChoice[{\[Pi]/7, \[Pi]/8, \[Pi]/6}, n], 
   RandomInteger[{8, 14}, n], 
   RandomChoice[{Line, Polygon, BezierCurve, FilledCurve[BezierCurve[#]] &}, n]}]

With my work schedule I have no time figure this problem out at this moment or spend weeks dissecting the code line by line and googling it. It would be nice to have this code available on python and share it with the community. Your help is much appreciated.




Aucun commentaire:

Enregistrer un commentaire