# Display a triangle that rotates at certain rate when space bar is held down?

This question is a follow up on: Open a pop up window that runs a calculation in loop until it is closed?

How can I open a pop up to show a picture of a triangle that rotates by 2 PI/100 around its center every Pause[1/1000] seconds as long as the space bar is held down? Is this possible in mathematica? (An answer where it constantly rotates regardless of key strokes interests me too.) What I am trying to get at is that I would like to have a honest infinite while loop of regular commands sent to the pop up window that terminates only when the pop up is closed.

EDIT

Maybe I should just stop simplifying and ask the actual case that I am eventually interested in. I want to display two images, one on top of the other and call an external function each loop. If the function gives back 1 one of the images jumps up and down, if the function returns 0, both images are static. How would one go about writing this?

• I'd leave this open. Disregarding the edit, there is an accepted answer that does most of what was requested. In any case, the proposed close reason of "unclear" need not apply, when it turned out to be clear enough for at least someone to answer and get accepted. I'd, maybe, hint on reading up on Refresh, which is what comes to my mind when an updating image could be desired. – LLlAMnYP Aug 21 '15 at 10:05

No spacebar ...

CreateDialog[
{a = Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}];
Dynamic[ First@{Graphics[a = Rotate[a, 2 Pi/100], PlotRange -> {{-2, 2}, {-1, 3}}],
Pause[1/100];}],
DefaultButton[]}, Modal -> True]


• O my! I lost my center! – Dr. belisarius Aug 21 '15 at 3:48
• Somehow the rotation stops for a moment when I mouse over the triangle, and then the triangle starts jumping out of frame... No idea why this happens. – Kagaratsch Aug 21 '15 at 3:50
• Ok, since I do not completely understand the syntax above, may I ask for one last alteration? Would the same code work in a situation where I want to display two images, one on top of the other and call an external function each loop. If the function gives back 1 one of the images jumps up and down, if the function returns 0, both images are static? – Kagaratsch Aug 21 '15 at 3:53
• Sorry, it seems I am changing the scope again, but I don't want to spam the site with too many questions on pop ups... – Kagaratsch Aug 21 '15 at 4:00
• @Kagaratsch Before asking another question or changing the scope you should try to understand the answer above. Mathematica is a wild beast and you need to take your time for taming it – Dr. belisarius Aug 21 '15 at 4:03