3
$\begingroup$

I should plot randomly oriented ellipses in rows and columns, at fixed nodes. Some rows should be grey, some black. Result should look like the following image (texture drawn by hand):

texture_draw_by_hand

I moved from a code like this:

dimensiontex = {400, 300};
nobj = 40; distanceobj = 5;
myrow = Table[{i, j}, {i, 1, nobj, distanceobj}, {j, 1, nobj, 
distanceobj}];

myobj = Graphics[Disk[{1, 1}, Offset[{10, 4}]]];
rotatemyobj = Rotate[myobj, RandomReal[{0, 2 Pi}]];
mytexture = 
ListPlot[myrow, Axes -> False, ImageSize -> {dimensiontex[[1]],dimensiontex[[2]]}, 
AspectRatio -> 1, PlotMarkers -> rotatemyobj]

but obviously the "random" orientation is the same for all objects and all rows are evenly spaced:

result

I guess I should use a Do loop, but how to manage rotation of the single ellipse? Any help is greatly appreciated

$\endgroup$
3
$\begingroup$

Here's one way:

dimensiontex = {400, 300};
nobj = 40; distanceobj = 5;
greys = RandomReal[{0, 1}, nobj];
rotatemyobj[c_] := Rotate[Graphics[{GrayLevel[c], Disk[{1, 1}, Offset[{10, 4}]]}], RandomReal[{0, 2 Pi}]];
tab = Table[rotatemyobj[greys[[i]]], {i, 1, nobj, distanceobj}, {j, 1, nobj, distanceobj}];
GraphicsGrid[tab]

enter image description here

Thanks to Rahul for more concise syntax.

$\endgroup$
2
$\begingroup$
rowEl[n_, color_] := 
  Rotate[Graphics@{color, Disk[{1, 1}, Offset[{10, 4}]]}, #] & /@ 
   RandomReal[{0, Pi}, n];
GraphicsGrid[
 rowEl @@@ 
  Transpose@{ConstantArray[5, 5], RandomChoice[{Black, Gray}, 5]}]

enter image description here

Alternatively, if you want to have finer control of distances between, you can avoid GraphicsGrid

rowEl2[n_, y_, color_] := 
  Graphics[{color, 
    Rotate[Disk[{1 + 4 #1, 4 (y - 1)}, {1, 0.4}], #2] & @@@ 
     Transpose@{Range[n], RandomReal[{0, Pi}, n]}}];
Show[rowEl2[5, #1, #2] & @@@ 
  Transpose@{Range[5], RandomChoice[{Black, Gray}, 5]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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