0
|
11117 Views
|
5 Replies
|
2 Total Likes
View groups...
Share

# Displaying Graphics Objects in Loops - How?

Posted 9 years ago
 this is a very simple question ... hopefully someone has a quick answer. suppose I define a simple graphics object and display it ... for example ... obj = Line[ { {-3, -1}, {3, -1} } ] ; Graphics[obj]  these 2 lines of code work fine - and I get a Line in Mathematica. Now ... I want to do the same thing inside a loop, such as a For Loop. But Mathematica gives no output. WHY?? Even if I add a Show command outside the Graphics statement, this still does not work. For [ j = 1, j < 3, j++, Graphics[obj] ]  thanks, Pete
5 Replies
Sort By:
Posted 9 years ago
 You can use the command Table as following obj = Line[{{-3, -1}, {3, -1}}]; Table[Graphics[obj], {i, 1, 3}] I think you want to do something like this Table[Graphics[Line[{{-3, -1}, {i, -1}}], Axes -> True], {i, 1, 3}] I hope you've given any idea to solve your problem
Posted 9 years ago
 thanks for your reply!I didn't do a very good job of explaining my exact problem. It is not possible for me to eliminate the FOR Loop because there are other statements inside that loop. For simplicity, I did not show them. But the FOR Loop is running a simulation, and each time the loop completes an iteration - I would like to show the Graphics.I did discover that if I put a Print statement around the Graphics, Mathematica will show the results Print[ Graphics[obj] ] The only problem with the Print statement is that it looks as if part of the Graphics is cut off ... Mathematica is not displaying the full region defined by the graphics. Perhaps there is some sort of option with Print that tells the software to expand the boundaries so that all graphics objects will be displayed? BTW, I know you are wondering why I do a simulation with a FOR Loop. The answer is ... for very large and complicated simulations, I have found it helpful to control the main iteration (over time) with a simple FOR Loop. It actually makes the calculations much easier to de-bug when you are trying to work out what happened at any specific place in a given iteration. :-) thanks, Pete
Posted 9 years ago
 Rather than use Print, put the Graphics into a TextCell and use CellPrint as in this example: For[i = 0, i < 5, i++, CellPrint[ TextCell[Graphics[{Line[{{-3, -1}, {3, -1 + i}}]}], "Text"]]] ; 
Posted 9 years ago