HTBasic Help
×
Menu
Index

Example: Lissajous Patterns

 
10     ! *********************************************************************
20     ! Example: Lissajous Patterns
30     !
40     ! This example plots one sine wave vs. another. The phase
50     ! and ratio of frequencies are varied. The resulting curves
60     ! are Lissajous curves.
70     !
80     ! ***************************************************************
90     !
100   ! Set up an XY display for the curves
110   ! Most of the attributes are programmed outside the loop
120   !
130   ASSIGN @Lissajous TO WIDGET "XY GRAPH";SET ("TITLE":" Example: Lissajous Patterns","TRACE COUNT":1,"POINT CAPACITY":512,"HEIGHT":250,"WIDTH":250,"X":100,"Y":100)
140   CONTROL @Lissajous;SET ("TRACE BACKGROUND":9,"TRACE PEN":0)
150   CONTROL @Lissajous;SET ("SYSTEM MENU":"Quit")
160   ON EVENT @Lissajous,"SYSTEM MENU" GOTO Finis
170   !
180   ! Set the limits in the graph to -1 to +1 for both axes
190   !
200   CONTROL @Lissajous;SET ("CURRENT AXIS":"X","ORIGIN":-1,"RANGE":2,"SHOW NUMBERING":0,"SHOW TICKS":0)
210   CONTROL @Lissajous;SET ("CURRENT AXIS":"Y","ORIGIN":-1,"RANGE":2,"SHOW NUMBERING":0,"SHOW TICKS":0)
220   !
230   ! Two string displays which show the current values of the loop veriables
240   !
250   ASSIGN @Show_phase TO WIDGET "STRING";SET ("TITLE":"  Phase","X":50,"Y":10)
260   ASSIGN @Show_ratio TO WIDGET "STRING";SET ("TITLE":"  Ratio","X":250,"Y":10)
270   !
280   ! Calculate the reference sine wave and set the X data to it
290   !
300   INTEGER I,N
310   N=50
320   ALLOCATE F1(N),F2(N)
330   ALLOCATE Fbig(0:N*2)
340   FOR I=0 TO N
350     F1(I)=SIN(I*2*PI/N)
360   NEXT I
370   CONTROL @Lissajous;SET ("X DATA":F1(*))
380   !
390   ! The Ratio variable is used the vary the ratio of the frequencies
400   ! of the two sine waves
410   !
420   LOOP
430     FOR Ratio=1 TO 5
440       Tmp1=(2*PI/N)*Ratio
450       FOR I=0 TO N*2
460         Fbig(I)=SIN(I*Tmp1)
470       NEXT I
480       CONTROL @Show_ratio;SET ("VALUE":VAL$(Ratio))
490   !
500   ! This loop offsets the phase of the second sine wave
510   !
520       FOR Phase=0 TO N-1
530         CONTROL @Show_phase;SET ("VALUE":VAL$(Phase))
540         Start=Phase/360*N
550         Start=Phase
560         MAT F2=Fbig(Start:Start+N)
570         CONTROL @Lissajous;SET ("Y DATA":F2(*))
580         WAIT .1
590       NEXT Phase
600     NEXT Ratio
610   END LOOP
620 Finis:   !
630   ASSIGN @Lissajous TO *         ! Delete XY GRAPH widget
640   END