2
$\begingroup$

I am trying to show random points with different colors and sizes. However, the following code generates random points with the same color. I want them in different colors.

I think I have a problem with table management.

Please kindly have a look into it. My code is as follows:

bounds = {{-1, 1}, {-1, 1}, {-1, 1}};
ℛ = Cuboid @@ Transpose[bounds];
rp = RandomPoint[ℛ, 1000];

Graphics3D[
 Table[{Hue[RandomReal[]], PointSize[RandomReal[{0, 0.005}]], 
   Point[rp]}, {1000}]]
$\endgroup$
1
  • $\begingroup$ Look at Graphics3D[Table[{Hue[RandomReal[]], PointSize[RandomReal[{0, 0.005}]], Point[rp]}, {1}]] You are using the same 1000 point locations repeatedly. $\endgroup$
    – Bob Hanlon
    Oct 16, 2022 at 16:26

2 Answers 2

4
$\begingroup$
Graphics3D[{Hue[RandomReal[]], PointSize[RandomReal[{0, 0.005}]], 
    Point[#]} & /@ rp]

enter image description here

$\endgroup$
3
$\begingroup$

This could be one way:

bounds = {{-1, 1}, {-1, 1}, {-1, 1}};
ℛ = Cuboid @@ Transpose[bounds];
rp = RandomPoint[ℛ, 1000];

Graphics3D[{
  {RandomColor[]
     , AbsolutePointSize[RandomInteger[{1, 6}]]
     , Point[#]} & /@ rp
  , {Opacity[0.2], Lighter@Cyan, ℛ}
  }
 ]

enter image description here

$\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.