# Extracting polygon color parameter from another variable [closed]

I'm a beginner with Mathematica, so this may seem like a simple question, though it's got me totally stumped. I'm trying to display several polygons and have the color of each polygon depend on the value in some other variable (stscds). My thinking is that I should do something like this:

Show[Graphics[Table[{RGBColor[stscds[[i]],0,0,0.2],EdgeForm[Black],poly[[i]]}, {i,1,300,1}]]]

poly contains all of the polygons. Or possibly this:

megapol = Table[{RGBColor[stscds[[i]],0,0,0.2],EdgeForm[Black],poly[[i]]}, {i,1,300,1}] Graphics[megapol]

It doesn't like that I'm trying to pull the color parameter out of stscds (this variable is full of values between 1 and zero). It says 'Ignoring invalid graphics directive RGBColor[0,01 1,0,0]. Any idea how I might approach this problem?

Edit: Output of stscds:

{("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, \ ("1")/100, ("1")/100, ("1")/100, ("2")/100, ("2")/100, ("2")/100, \ ("2")/100, ("2")/100, ("2")/100, ("3")/100, ("4")/100, ("4")/100, \ ("4")/100, ("4")/100, ("4")/100, ("4")/100,....

-

## closed as off-topic by Michael E2, bobthechemist, Sjoerd C. de Vries, Simon Woods, AjasjaFeb 23 at 12:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, bobthechemist, Sjoerd C. de Vries, Simon Woods, Ajasja
If this question can be reworded to fit the rules in the help center, please edit the question.

How about including some sample of stscds contents? If the error actually has the format you posted, probably something whacked in the format, and you seem to be supplying too many arguments to RGBColor... –  rasher Feb 23 at 1:03
You're dividing a string... turn the ("x")/... into x/... –  rasher Feb 23 at 1:09
Ah, you're right. stscds was full of strings, which I didn't realize. I used ToExpression to convert it to numerical. Thanks a million rasher. –  Mas Feb 23 at 1:21

I post this as motivation for experimenting to get desired result. I have made no effort to create convex polygons or avoiding intersections. My main aim is to illustrate some coloring options:

1. Generate some polygons:

pol = RandomReal[{0, 1}, {10, 5, 2}]

2. Some coloring options:

Using ColorData

    Graphics@MapThread[{Opacity[0.5], ColorData["Rainbow"][#1],
Polygon@#2} &, {RandomReal[{0, 1}, 10], pol}]


Using RGBColor (random shades of Red)

    Graphics@MapThread[{Opacity[0.5], RGBColor[#1, 0, 0],
Polygon@#2} &, {RandomReal[{0, 1}, 10], pol}]


Using Hue

    Graphics@MapThread[{Opacity[0.5], Hue[#1],
Polygon@#2} &, {RandomReal[{0, 1}, 10], pol}]


There are a number of other approaches. I suggest looking at documentation and playing. I have merely used random coloring but the approch could be adapted to your user defined desired coloring after you choose a suitable color scheme.

A more specific example (with absolutely no political subtext in coloring):

 poly = CountryData[#, "SchematicPolygon"] & /@ {"UnitedStates",
Graphics@MapThread[{#1, #2} &, {{Red, Blue, Yellow}, poly}]


Using OP stscds

stscds = {("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/
100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, ("2")/100, ("2")/
100, ("2")/100, ("2")/100, ("2")/100, ("2")/100, ("3")/100, ("4")/
100, ("4")/100, ("4")/100, ("4")/100, ("4")/100, ("4")/100};
recode = MapAt[ToExpression, stscds, {All, 2}];
pg = Polygon /@ RandomReal[{0, 5}, {Length@recode, 3, 2}];