Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I just tried something straightforward (for me):

dummy = Import["http://pastebin.com/raw.php?i=g8D7NprC", "List"] & /@ col;
colors = dummy[[1]];
ToExpression@colors;
Graphics[{colors, Rectangle[{0, 0}]}]

Is it not possible to import color data from a file?

share|improve this question
    
it works fine if you remove & /@ col at the end of the first line. –  kguler Jun 3 at 20:10
    
Ok I don't know much but now there is nothing happening. No output at all. Which is very weird when it works fine with you. It states "RGBColor[0, 0, 1] is not a Graphics primitive or directive" –  user3683367 Jun 3 at 20:17
2  
I think it is because your colors is a string; to change it to a color directive use ToExpression@colors... –  kguler Jun 3 at 20:25
1  
Or just color = << "http://pastebin.com/raw.php?i=GXbeGrcD". –  Rahul Jun 3 at 20:25
1  
@user3683367 - you oversimplified your question. what does your file to be imported REALLY look like? does it contain DIFFERENT colors, a list of colors ? But even in this case: How, exactly, do you want to color ONE rectangle with these different colors? –  eldo Jun 3 at 20:40

1 Answer 1

up vote 3 down vote accepted

I think you need something like the following:

 dummy = Import["http://pastebin.com/raw.php?i=g8D7NprC", "List"];
 colors = ToExpression /@ dummy;
 Graphics[Thread[{colors, Rectangle/@ RandomInteger[10, {5, 2}]}]]

enter image description here

share|improve this answer
    
Yes this is exactly what I wanted. Would you recommend using "Thread" or "Sequence" like in the following question: mathematica.stackexchange.com/questions/48818/… –  user3683367 Jun 3 at 21:38
1  
@user3683367, you probably will be using this in an animation similar to the linked question; so i would recommend using the same setup... that is, {colors[[t]],Rectangle @@ (rectCoords[[t]])} with t the index you use in Animate or Table... –  kguler Jun 3 at 21:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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