Skip to main content
added 21 characters in body
Source Link
Volker
  • 950
  • 6
  • 14

You need to have a function that returns a list, where the first element is the color and the second element the sphere. Then you apply that function to your list of spheres. Afterwards you flatten the result such that it's compatible with Graphics3D.

coloredSphere[coordinates_] := {RGBColor[Sequence @@ RandomInteger[{0, 1}, 3]], Sphere[coordinates[[;; 3]], coordinates[[4]]]}; Graphics3D[Flatten[coloredSphereGraphics3D[coloredSphere /@ listOfSpheres]]listOfSpheres] 

enter image description here

Also, you might want to use RandomReal instead of RandomInteger, but that's up to you.

Edit: The Flatten inside Graphics3D is not even necessary, as I realized by reading the other reply.

You need to have a function that returns a list, where the first element is the color and the second element the sphere. Then you apply that function to your list of spheres. Afterwards you flatten the result such that it's compatible with Graphics3D.

coloredSphere[coordinates_] := {RGBColor[Sequence @@ RandomInteger[{0, 1}, 3]], Sphere[coordinates[[;; 3]], coordinates[[4]]]}; Graphics3D[Flatten[coloredSphere /@ listOfSpheres]] 

Also, you might want to use RandomReal instead of RandomInteger, but that's up to you.

You need to have a function that returns a list, where the first element is the color and the second element the sphere. Then you apply that function to your list of spheres.

coloredSphere[coordinates_] := {RGBColor[Sequence @@ RandomInteger[{0, 1}, 3]], Sphere[coordinates[[;; 3]], coordinates[[4]]]}; Graphics3D[coloredSphere /@ listOfSpheres] 

enter image description here

Also, you might want to use RandomReal instead of RandomInteger, but that's up to you.

Edit: The Flatten inside Graphics3D is not even necessary, as I realized by reading the other reply.

Source Link
Volker
  • 950
  • 6
  • 14

You need to have a function that returns a list, where the first element is the color and the second element the sphere. Then you apply that function to your list of spheres. Afterwards you flatten the result such that it's compatible with Graphics3D.

coloredSphere[coordinates_] := {RGBColor[Sequence @@ RandomInteger[{0, 1}, 3]], Sphere[coordinates[[;; 3]], coordinates[[4]]]}; Graphics3D[Flatten[coloredSphere /@ listOfSpheres]] 

Also, you might want to use RandomReal instead of RandomInteger, but that's up to you.