0

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?

MaxJ
  • 1,535
  • 1
  • 10
  • 16
  • it works fine if you remove & /@ col at the end of the first line. – kglr Jun 03 '14 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" – MaxJ Jun 03 '14 at 20:17
  • 2
    I think it is because your colors is a string; to change it to a color directive use ToExpression@colors... – kglr Jun 03 '14 at 20:25
  • 1
    Or just color = << "http://pastebin.com/raw.php?i=GXbeGrcD". –  Jun 03 '14 at 20:25
  • Thank you, but this does not work for many lines of text with different colors? I need to address different colors through colors[[i]] @kguler : Is that above what you meant? It does not work either. – MaxJ Jun 03 '14 at 20:33
  • 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 03 '14 at 20:40
  • I edited the file so it contains more than one argument. I can have it look like I want so this way is not fixed. And one rectangle one color. – MaxJ Jun 03 '14 at 21:17
  • @user3683367, you need use colors = ToExpression@colors; or colors=Toexpression[dummy[[1]]]... – kglr Jun 03 '14 at 21:27

1 Answers1

3

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

kglr
  • 394,356
  • 18
  • 477
  • 896
  • Yes this is exactly what I wanted. Would you recommend using "Thread" or "Sequence" like in the following question: http://mathematica.stackexchange.com/questions/48818/animation-of-moving-rectangles-in-2d-from-data-file – MaxJ Jun 03 '14 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... – kglr Jun 03 '14 at 21:52