1
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – LLlAMnYP
    Aug 21, 2015 at 10:05

1 Answer 1

1
$\begingroup$

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]

Mathematica graphics

$\endgroup$
7
  • $\begingroup$ O my! I lost my center! $\endgroup$ Aug 21, 2015 at 3:48
  • $\begingroup$ 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. $\endgroup$
    – Kagaratsch
    Aug 21, 2015 at 3:50
  • $\begingroup$ 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? $\endgroup$
    – Kagaratsch
    Aug 21, 2015 at 3:53
  • $\begingroup$ 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... $\endgroup$
    – Kagaratsch
    Aug 21, 2015 at 4:00
  • 1
    $\begingroup$ @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 $\endgroup$ Aug 21, 2015 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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