Message Boards Message Boards

How do I get the Graphics command to work inside a Do loop?

Posted 10 years ago

In the code below, I define the symbol "drawCommand" to draw a white square with a black border and then a symbol "printCommand" to print a value. These work as expected until put inside a Do loop. Then the printCommand executes but drawCommand doesn't. The output can be seen in the attached .pdf file.
Can anyone tell me how to get this to work?
Much obliged, larry.c

border = Rectangle[{-1, -1}, {1, 1}];
drawCommand := Graphics[{EdgeForm[Thick], White, border}];
drawCommand 

timeValue = "global value";
printCommand := Print["   timeValue = ", timeValue ];
printCommand

Print["Begin Loop"];
Do[drawCommand; printCommand  , {timeValue , 0, 01., .2}]
Print["End Loop"];

drawCommand 
printCommand
Attachments:
POSTED BY: Larry Cuba
3 Replies
POSTED BY: Jason Grigsby

Print and Graphics interact with the front end differently. Print writes to standard out whereas Graphics produces possible output. The Do loop withholds output from its first argument. Try the following:

drawn = ConstantArray[Null, 5]

Do[drawn[[iter]] = drawCommand, {iter, 1, 5}]

drawn
POSTED BY: Jason Grigsby
Posted 10 years ago

Thanks, Jason.

Is there a way to achieve this by Appending to a list instead of using a fixed length array? I don't know how large an array I will ultimately need in my actual application.

Also, is there somewhere in the documentation that explains these concepts of "Graphics produces possible output" and "Do loop withholds output"?

They're new to me.

Thanks again for your help.

POSTED BY: Larry Cuba
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract