time delay within a loop

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

time delay within a loop

Postby Stu on Mon Apr 25, 2016 9:42 am

Is there a way to introduce a delay into a program so that if the program generates a series of pictures or other graphics you can have a pause to allow each display to remain on the screen for a while before the next one is shown? (Hopefully, the method would be something other than a do-nothing loop that just wastes time.)
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: time delay within a loop

Postby StefanoLanzavecchia on Mon Apr 25, 2016 9:56 am

There's:
      ⎕DL

Documentation: Delay.
User avatar
StefanoLanzavecchia
 
Posts: 84
Joined: Fri Oct 03, 2008 9:37 am

Re: time delay within a loop

Postby Stu on Mon Apr 25, 2016 10:59 pm

Great, it does exactly what I wanted! I didn't realize it would be that easy.

Thanks.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: time delay within a loop

Postby AndyS|Dyalog on Tue Apr 26, 2016 10:50 am

If your code to display images involves creating forms etc, you might like to consider using a Timer object. Then you could have both a button which changes image when you click it, and a Timer event callback which changes the image too .. bit more complex, since you probably want to reset the timer if you've just clicked the button, but it might make for a nicer front-end. This would mean that you can manually change images sooner than the delay that you specify ..
User avatar
AndyS|Dyalog
 
Posts: 235
Joined: Tue May 12, 2009 6:06 pm

Re: time delay within a loop

Postby Stu on Wed Apr 27, 2016 4:13 am

The button idea will be really nice if I ever learn how to make a GUI for my program, which is a sort of Spirograph on steroids. With the current version of the program, I've found that I have to be fairly careful about the rate at which the display changes. If I allow less than about 4 seconds per picture, the interpreter will sometimes hang. Many of the pictures are quite intricate, so I imagine that the computation of one picture may be incomplete when the program tries to start computing the next one.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: time delay within a loop

Postby Stu on Mon May 02, 2016 11:42 pm

I've got my first GUI up and running, using edit fields to enter data. But there's one edit field that should really be a button, where up means 0 and depressed means 1. I started looking at the Dyalog Interfaces Guide, and it appears I need something like

'F'⎕WC'Form' 'ToolControl: Radio Buttons'
'F.TB'⎕WC'ToolControl'

but I'm not sure what else I need to make the button work.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: time delay within a loop

Postby Vince|Dyalog on Tue May 03, 2016 9:32 am

Hi Stu,

A good resource for our GUI is wtutor and wtutor95. They are quite old workspaces though.

)load wtutor
or
)load wtutor95

A radio button is usually part of a group and you can only select one.

wtutor has this example:
      'MEAL' ⎕WC 'Form' 'The Star of India' (64 38)(30 60)
'MEAL.CUR' ⎕WC 'Group' 'Curries' (5 5)(90 40)
'MEAL.CUR.CM' ⎕WC 'Button' 'Chicken Madras' (15 10) ('Style' 'Radio')
'MEAL.CUR.LP' ⎕WC 'Button' 'Lamb Pasanda' (30 10) ('Style' 'Radio')
'MEAL.CUR.PV' ⎕WC 'Button' 'Pork Vindaloo' (45 10) ('Style' 'Radio')
'MEAL.CUR.PD' ⎕WC 'Button' 'Prawn Dhansak' (60 10) ('Style' 'Radio')
'MEAL.CUR.RG' ⎕WC 'Button' 'Rogan Josh' (75 10) ('Style' 'Radio')


Do you need it to be part of a toolcontrol?

Regards,

Vince
Vince|Dyalog
 
Posts: 335
Joined: Wed Oct 01, 2008 9:39 am

Re: time delay within a loop

Postby Stu on Tue May 03, 2016 4:43 pm

Hi Vince,

What I need is a single button that will change the value of a variable, whose default value is 0, to 1. The button should remain down, like a radio button, until it is pressed again, which sets the variable back to zero. The button should be like an ON/OFF switch. I also couldn't see how to associate a radio button with the function that changes the value of a variable (I do know how to do that for a "regular" button).

If you have time to look at my program, I could send it to you. You could run it to see how it works and why I'd like to have that button.

-Stu

P.S.: Is there really an Indian dish called "Josh Rogan"?
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: time delay within a loop

Postby AndyS|Dyalog on Wed May 04, 2016 2:04 pm

Radio buttons are usually used in groups of two or more - something like the following:
Code: Select all
      ⎕fx'cb msg'  'msg'
      'f'⎕wc'form'
      'f.g1'⎕wc'Group'
      'f.g1.b1'⎕WC'Button' 'Vindaloo'('Posn' 60 20)('Style' 'Radio')('Event' 'Select' 'cb')
      'f.g1.b2'⎕WC'Button' 'Rogan Josh'('Posn' 20 20)('Style' 'Radio')('Event' 'Select' 'cb')

A set of Radio buttons needs to have the same parent, so I have used a group here to achieve that.

I think you actually need a Check button .. that displays a tick (or not) to indicate whether it's "on" or "off".
So something like the following will do ..
Code: Select all
      'f'⎕wc'Form'
      ⎕fx'cb2 msg' '⎕←myvar←(⊃msg)⎕wg''State'''
      'f.b'⎕wc'Button' 'Pressed' ('Style' 'Check')('Event' 'Select' 'cb2')

Then when you repeatedly click on the button, you'll see that its State changes.

Rogan Josh is one of the staples of Indian restaurants here in the UK - and the love of curry is in the DNA of Dyalog Ltd. Actually, the love of good food in general is in the DNA of Dyalog, but a beer and a Ruby come near the top of the list !
User avatar
AndyS|Dyalog
 
Posts: 235
Joined: Tue May 12, 2009 6:06 pm

Re: time delay within a loop

Postby Stu on Wed May 04, 2016 7:33 pm

The interface I have working currently is below. I'd like to replace the last two lines with a check button, but I haven't been able to figure out how to substitute your code for those lines (I'm still learning how to make a GUI).

TITLE←'xshapes'
'APP'⎕WC'Form'TITLE(68 50)(30 33)

'APP.LD'⎕WC'Label' 'Delay'(10 10)
'APP.D'⎕WC'Edit' ''(10 17)(⍬ 20)('FieldType' 'Numeric')
'APP.LI'⎕WC'Label' 'Iterations'(25 10)
'APP.I'⎕WC'Edit' ''(25 17)(⍬ 20)('FieldType' 'Numeric')
'APP.LR'⎕WC'Label' 'Random'(40 10)
'APP.R'⎕WC'Edit' ''(40 20)(⍬ 3)('FieldType' 'Numeric')

GB←'Button' 'GO'(70 27)('Event' 'Select' 'loop')
'APP.GO'⎕WC GB

IB←'Button' ' ? '(40 17)('Event' 'Select' 'RAND')
'APP.IR'⎕WC IB

===========================================================================================
I make my own curried dishes with supermarket "curry powder." I also bought bottles of "Vindaloo Curry Seasoning" and "Balti Curry Seasoning," but I didn't like the flavor of those. If you've eaten out in the USA, you've undoubtedly observed that the tastes of Americans generally run to very bland food (enormous portions of meat accompanied by overcooked vegetables).
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Next

Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest