Animation: Difference between revisions

55,744 bytes added ,  6 months ago
m
→‎{{header|Wren}}: Changed to Wren S/H
m (removed trailing newlines in Elm solution)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(18 intermediate revisions by 11 users not shown)
Line 1:
{{task|Temporal media}}
[[Category:GUI]]
[[Category:Animation]]
{{task|Temporal media}}
{{requires|Graphics}}
 
Line 13 ⟶ 14:
When the user clicks on the (windowed) text, it should reverse its direction.
<br><br>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang="aarch64 assembly">
/* Programme assembleur ARM Raspberry ou Android */
/* programme animletter64.s */
/* REMARK: This program was written for android with the termux app.
It works very well on raspberry pi but in this case the memory access relocation instructions
can be simplified.
For simplicity, this program does not use X11 structure definitions.
*/
 
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/* constantes X11 */
.equ KeyPressed, 2
.equ ButtonPress, 4
.equ MotionNotify, 6
.equ EnterNotify, 7
.equ LeaveNotify, 8
.equ Expose, 12
.equ ClientMessage, 33
.equ KeyPressMask, 1
.equ ButtonPressMask, 4
.equ ButtonReleaseMask, 8
.equ ExposureMask, 1<<15
.equ StructureNotifyMask, 1<<17
.equ EnterWindowMask, 1<<4
.equ LeaveWindowMask, 1<<5
.equ ConfigureNotify, 22
 
.equ GCForeground, 1<<2
.equ GCBackground, 1<<3
.equ GCLine_width, 1<<4
.equ GCLine_style, 1<<5
.equ GCFont, 1<<14
 
.equ CWBackPixel, 1<<1
.equ CWBorderPixel, 1<<3
.equ CWEventMask, 1<<11
.equ CWX, 1<<0
.equ CWY, 1<<1
.equ CWWidth, 1<<2
.equ CWHeight, 1<<3
.equ CWBorderWidth, 1<<4
.equ CWSibling, 1<<5
.equ CWStackMode, 1<<6
 
 
/* constantes program */
.equ WINDOWWIDTH, 400
.equ WINDOWHEIGHT, 300
 
/*********************************/
/* initialized datas */
/*********************************/
.data
szWindowName: .asciz "Windows Raspberry"
szRetourLigne: .asciz "\n"
szMessDebutPgm: .asciz "Program start. \n"
szMessFinPgm: .asciz "Program end OK.\n"
szMessErreur: .asciz "Server X not found.\n"
szMessErrfen: .asciz "Can not create window.\n"
szMessErreurX11: .asciz "Error call function X11. \n"
szMessErrGc: .asciz "Can not create graphics context.\n"
szTitreFenRed: .asciz "Pi"
szTexte1: .asciz "Hello world! "
.equ LGTEXTE1, . - szTexte1
 
szLibDW: .asciz "WM_DELETE_WINDOW" // special label for correct close error
 
.align 8
stXGCValues: .quad 0,0,0xFFA0A0A0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 // for foreground color gris1
//stXGCValues: .quad 0,0,0x00000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 // for foreground color black
stXGCValues1: .quad 0,0,0x00FFFFFF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 // for foreground color white
stXGCValues2: .quad 0,0,0x0000FF00,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 // for foreground color green
 
 
/*********************************/
/* no initialized datas */
/*********************************/
.bss
.align 8
sZoneConv: .skip 24
qDisplay: .skip 8 // Display address
qEcran: .skip 8 // Screen address
ptGC1: .skip 8 // Graphic Context pointer
qSens: .skip 8 // direction
qKey: .skip 8 // touch value
wmDeleteMessage: .skip 8 // ident close message
stEvent: .skip 400 // event structure
sBuffer: .skip 80
sbuffer1: .skip 80
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // programm entry
adr x0,qOfszMessDebutPgm
ldr x1,[x0]
add x0,x0,x1
bl affichageMess
/* Attention x28 display address
x27 window ident
x26 ident GC1
x24 ident GC2
*/
mov x0,#0 // open X server
bl XOpenDisplay
cbz x0,99f // no X server ?
adr x1,qOfqDisplay // ok
ldr x2,[x1]
add x2,x2,x1
str x0,[x2] // store DISPLAY address
mov x28,x0 // and register 28
ldr x2,[x0,264] // load screen address in display structure
adr x3,qOfqEcran
ldr x1,[x3]
add x1,x1,x3
str x2,[x1] // store default_screen
 
mov x2,x0
ldr x0,[x2,#232] // screens list address
ldr x5,[x0,#+88] // white pixel
ldr x3,[x0,#+96] // black pixel
ldr x4,[x0,#+56] // bits par pixel
ldr x1,[x0,#+16] // root windows
/*****************************/
/* WINDOW CREATION */
/*****************************/
mov x0,x28 // display address
mov x2,#10 // position X
mov x3,#20 // position Y
mov x4,WINDOWWIDTH // width
mov x5,WINDOWHEIGHT // height
mov x6,1 // bordure width
mov x7,0 // pixel bordure = black
ldr x8,qGris1 // background color
str x8,[sp,-16]! // by stack parameter
bl XCreateSimpleWindow
add sp,sp,16 // stack alignement (one parameter)
cbz x0,98f // create error ?
mov x27,x0 // save ident window
/*****************************/
/* add window property */
/*****************************/
mov x0,x28 // display address
mov x1,x27 // window address
adr x2,qOfszWindowName // window name
ldr x5,[x2]
add x2,x2,x5
adr x3,qOfszTitreFenRed // window name reduced
ldr x5,[x3]
add x3,x3,x5
mov x4,#0 // parameters not use
mov x5,#0
mov x6,#0
mov x7,#0
bl XSetStandardProperties
/**************************************/
/* for correction window close error */
/**************************************/
mov x0,x28 // display address
adr x1,qOfszLibDW // atom address
ldr x5,[x1]
add x1,x1,x5
mov x2,#1 // False créate atom if not exists
bl XInternAtom
cmp x0,#0 // error X11 ?
ble 97f // Modif avril 22 pour android (ble pour raspberry)
adr x1,qOfwmDeleteMessage // recept address
ldr x5,[x1]
add x1,x1,x5
str x0,[x1]
mov x2,x1 // return address
mov x0,x28 // display address
mov x1,x27 // window address
mov x3,#1 // number of protocols
bl XSetWMProtocols
cmp x0,#0 // error X11 ?
ble 97f
mov x0,x28 // Display address
mov x1,x27 // window ident
bl creationGC
/****************************/
/* window display on screen */
/****************************/
mov x0,x28 // display address
mov x1,x27 // window ident
bl XMapWindow
 
// authorization of seizures
mov x0,x28 // display address
mov x1,x27 // window ident
ldr x2,qSaisieMask // autorizations mask
bl XSelectInput
adr x0,qOfszTexte1 // string address
ldr x4,[x0]
add x0,x0,x4
adr x1,qOfsbuffer1 // buffer address
ldr x4,[x1]
add x1,x1,x4
mov x2,#0
1: // loop copy character
ldrb w3,[x0,x2]
strb w3,[x1,x2]
cmp x3,#0
beq 2f
add x2,x2,#1
b 1b
2:
/****************************/
/* Events loop */
/****************************/
3:
mov x0,x28 // display address
bl XPending // loading the number of events
cmp x0,#0
bne 4f // a event is occurring
adr x3,qOfsbuffer1
ldr x5,[x3]
add x3,x3,x5
mov x0,x28 // display address
mov x1,x27 // window ident
mov x2,x26 // graphic context
bl animate // string display and move
b 3b // and loop
 
4:
mov x0,x28 // adresse du display
adr x1,qOfstEvent // adresse structure evenements
ldr x2,[x1]
add x1,x1,x2
mov x25,x1 // save adresse structure evenement
bl XNextEvent
ldr w0,[x25] // code évenement
cmp x0,#KeyPressed // appui touche ?
bne 5f
// cas d'une touche
mov x0,x25
adr x1,qOfsBuffer // adresse buffer
ldr x2,[x1]
add x1,x1,x2
mov x2,#255
adr x3,qOfqKey // adresse zone clé
ldr x4,[x3]
add x3,x3,x4
mov x4,#0
bl XLookupString // recup touche dans buffer
cmp x0,#1 // touche caractères ?
bne 6f
 
adr x0,qOfsBuffer // adresse du buffer
ldr x2,[x0]
add x0,x0,x2
ldrb w0,[x0] // charge le 1er caractère du buffer
cmp w0,#0x71 // caractere q ?
beq 7f // oui -> fin
b 6f
5:
/************************************/
/* clic mouse button */
/************************************/
cmp x0,ButtonPress // clic mouse buton
bne 51f
adr x0,qOfstEvent
ldr x5,[x0]
add x0,x0,x5
ldr w1,[x0,#+64] // position X mouse clic
ldr w2,[x0,#+68] // position Y
mov x0,x1
mov x0,x2
cmp x1,#50 // test if position clic is on the screen string approx.
blt 6f
cmp x1,#150
bgt 6f
cmp x2,#80
blt 6f
cmp x2,#105
bgt 6f
adr x1,qOfqSens // load direction
ldr x2,[x1]
add x1,x1,x2
ldr x2,[x1]
cmp x2,#0 // direction inversion
cset x2,eq
str x2,[x1]
b 6f
51:
cmp x0,#ClientMessage // code for close window within error
bne 6f
adr x0,qOfstEvent
ldr x5,[x0]
add x0,x0,x5
ldr x1,[x0,#+56] // code message address
adr x2,qOfwmDeleteMessage // equal code window créate ???
ldr x5,[x2]
add x2,x2,x5
ldr x2,[x2]
cmp x1,x2
beq 7f // yes -> end window
6:
b 3b // else events loop
7: // end program
mov x0,x28 // display address
mov x1,x24
bl XFreeGC // liberation GC1
mov x0,x28 // display address
mov x1,x26
bl XFreeGC // liberation GC2
 
mov x0,x28 // display address
mov x1,x27 // window ident
bl XDestroyWindow
mov x0,x28 // display address
bl XCloseDisplay // connexion X11Server Close
adr x0,qOfszMessFinPgm
ldr x1,[x0]
add x0,x0,x1
bl affichageMess
b 100f
97:
adr x0,qOfszMessErreurX11 // X11 error
ldr x1,[x0]
add x0,x0,x1
bl affichageMess
b 100f
98: // erreur creation fenêtre mais ne sert peut être à rien car erreur directe X11
adr x0,qOfszMessErrfen
ldr x1,[x0]
add x0,x0,x1
bl affichageMess
b 100f
99: // erreur car pas de serveur X
adr x0,qOfszMessErreur
ldr x1,[x0]
add x0,x0,x1
bl affichageMess
b 100f
 
 
100: // fin standard du programme
mov x0,0 // code retour
mov x8,EXIT // system call "Exit"
svc #0
qOfszMessDebutPgm: .quad szMessDebutPgm - .
qOfszMessFinPgm: .quad szMessFinPgm - .
qOfszRetourLigne: .quad szRetourLigne - .
qOfqDisplay: .quad qDisplay - .
qGris: .quad 0xF0F0F0F0
qGris1: .quad 0xFFA0A0A0
qOfszMessErreur: .quad szMessErreur - .
qOfszMessErrfen: .quad szMessErrfen - .
qOfszMessErreurX11: .quad szMessErreurX11 - .
qOfwmDeleteMessage: .quad wmDeleteMessage - .
qOfszLibDW: .quad szLibDW - .
qOfszTitreFenRed: .quad szTitreFenRed - .
qOfszWindowName: .quad szWindowName - .
qOfstEvent: .quad stEvent - .
qOfqEcran: .quad qEcran - .
qOfsBuffer: .quad sBuffer - .
qOfsbuffer1: .quad sbuffer1 - .
qOfqKey: .quad qKey - .
qSaisieMask: .quad StructureNotifyMask|ExposureMask|KeyPressMask|ButtonPressMask
qOfszTexte1: .quad szTexte1 - .
 
/***********************************************************/
/* Context Graphic création ***/
/***********************************************************/
/* x0 Display */
/* x1 window */
/* CAUTION : not standard use registers : return ident GC in x24 and x26 !! */
creationGC:
stp x20,lr,[sp,-16]! // save registres
stp x21,x22,[sp,-16]! // save registres
mov x20,x0
mov x21,x1
// Context Graphic création
adr x3,qOfstXGCValues2 // green color in foreground
ldr x5,[x3]
add x3,x3,x5 // this parameter is used by XcreateGC
str x4,[x3,#120] // store ident font in offset 120
mov x0,x20 // display address
mov x1,x21 // window ident
mov x2,#GCForeground // green color in foreground and font
bl XCreateGC
cmp x0,#0
beq 99f // création not OK
adr x1,qOfptGC1 // store ident graphic context
ldr x2,[x1]
add x1,x1,x2
str x0,[x1]
mov x26,x0
// création contexte 2
adr x3,qOfstXGCValues // gris1 color in foreground
ldr x5,[x3]
add x3,x3,x5 // this parameter is used by XcreateGC
mov x0,x20 // display address
mov x1,x21 // window ident
mov x2,#GCForeground // gris1 foreground
bl XCreateGC
cmp x0,#0
beq 99f // création not OK
mov x24,x0
b 100f
99: // erreur création GC
adr x0,qOfszMessErreurGC
ldr x1,[x0]
add x0,x0,x1
bl affichageMess
mov x0,#0
100:
ldp x21,x22,[sp],16 // restaur des 2 registres
ldp x20,lr,[sp],16 // restaur des 2 registres
ret // retour adresse lr x30
qGcmask1: .quad GCForeground|GCBackground
qOfszMessErreurGC: .quad szMessErrGc - .
qOfptGC1: .quad ptGC1 - .
qOfstXGCValues: .quad stXGCValues - .
qOfstXGCValues1: .quad stXGCValues1 - .
qOfstXGCValues2: .quad stXGCValues2 - .
/******************************************************************/
/* animate letters */
/******************************************************************/
/* x0 contains display address */
/* x1 window ident */
/* x2 graphic context */
/* x3 string address */
animate:
stp x20,lr,[sp,-16]! // save registres
stp x21,x22,[sp,-16]! // save registres
mov x20,x3 // save string address
mov x21,x0 // save display
mov x22,x1 // save window
mov x23,x2 // save GC
mov x0,x2
// erase text in the windows
mov x0,x21 // display address
mov x1,x22 // window ident
mov x2,x24 // graphic context
mov x3,#50 // position x
mov x4,#100 // position Y
mov x5,x20 // string address
mov x6,#LGTEXTE1 - 1 // string lenght
bl XDrawString
mov x0,#LGTEXTE1 -2 // string length
adr x1,qOfqSens // load direction
ldr x2,[x1]
add x1,x1,x2
ldr x2,[x1]
cmp x2,#0 // test direction
bne 2f
ldrb w9,[x20,x0] // last character
sub x1,x0,#1
1: // loop to move character one position
ldrb w2,[x20,x1]
strb w2,[x20,x0]
sub x0,x0,#1
subs x1,x1,#1
bge 1b
add x1,x1,#1
strb w9,[x20,x1] // last character -> first character
b 4f
2:
ldrb w9,[x20] // first character
mov x1,#1
sub x2,x1,#1
3: // loop to move character
ldrb w3,[x20,x1]
strb w3,[x20,x2]
add x2,x2,#1
add x1,x1,#1
cmp x1,x0
ble 3b
strb w9,[x20,x2] // first character -> last character
 
4:
// display text in the windows
mov x0,x21 // display address
mov x1,x22 // window ident
mov x2,x23 // graphic context
mov x3,#50 // position x
mov x4,#100 // position Y
mov x5,x20 // string address
mov x6,#LGTEXTE1 - 1 // string lenght
bl XDrawString
mov x0,#20 // timeout 5s approx.
bl delay
 
100:
ldp x21,x22,[sp],16 // restaur des 2 registres
ldp x20,lr,[sp],16 // restaur des 2 registres
ret // retour adresse lr x30
qOfqSens: .quad qSens - .
/******************************************************************/
/* timeout */
/******************************************************************/
/* x0 contains delay */
delay:
stp x1,lr,[sp,-16]! // save registres
ldr x1,qCst50000000
mul x0,x1,x0
1:
subs x0,x0,#1
bge 1b
ldp x1,lr,[sp],16 // restaur registers
ret
qCst50000000: .quad 50000000
 
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC DrawWindow(BYTE x,y,len)
BYTE i
 
Line 99 ⟶ 634:
 
CRSINH=0 ;show cursor
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Animation.png Screenshot from Atari 8-bit computer]
 
=={{header|ActionScript}}==
<langsyntaxhighlight ActionScriptlang="actionscript">//create the text box
var textBox:TextField = new TextField();
addChild(textBox);
Line 125 ⟶ 660:
//event handler to register clicks
textBox.addEventListener(MouseEvent.MOUSE_DOWN, function(){goingRight = !goingRight;});
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
Line 132 ⟶ 667:
 
animation.adb:
<langsyntaxhighlight Adalang="ada">with Gtk.Main;
with Gtk.Handlers;
with Gtk.Label;
Line 223 ⟶ 758:
Gtk.Window.Show_All (Widget => Main_Window);
Gtk.Main.Main;
end Animation;</langsyntaxhighlight>
 
=={{header|Applesoft BASIC}}==
<syntaxhighlight lang="gwbasic"> 10 LET T$ = "HELLO WORLD! ":P = 1:L = LEN (T$):T$ = T$ + T$
20 D = 1: VTAB INT (( PEEK (35) - PEEK (34)) / 2) + 1: FOR R = 1 TO 0 STEP 0
30 HTAB INT (( PEEK (33) - L) / 2) + 1: PRINT MID$ (T$,P,L);
40 P = P + D: IF P > L THEN P = 1
50 IF P < 1 THEN P = L
60 R = PEEK (49152) < 128: FOR I = 1 TO 5:B = PEEK (49249) > 127: IF B < > BO THEN BO = B: IF B = 0 THEN D = - D
70 NEXT I,R:R = PEEK (49168)</syntaxhighlight>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI or android 32 bits with termux application */
/* program animLetter.s */
 
/* compile with as */
/* link with gcc and options -lX11 -L/usr/lpp/X11/lib */
 
/* REMARK: This program was written for android with the termux app.
It works very well on raspberry pi but in this case the memory access relocation instructions
can be simplified.
*/
 
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes */
/************************************/
.include "../constantes.inc"
 
/********************************************/
/*Constantes */
/********************************************/
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/* constantes X11 */
.equ KeyPressed, 2
.equ ButtonPress, 4
.equ MotionNotify, 6
.equ EnterNotify, 7
.equ LeaveNotify, 8
.equ Expose, 12
.equ ClientMessage, 33
.equ KeyPressMask, 1
.equ ButtonPressMask, 4
.equ ButtonReleaseMask, 8
.equ ExposureMask, 1<<15
.equ StructureNotifyMask, 1<<17
.equ EnterWindowMask, 1<<4
.equ LeaveWindowMask, 1<<5
.equ ConfigureNotify, 22
 
.equ GCForeground, 1<<2
.equ GCFont, 1<<14
 
/* constantes program */
.equ WINDOWWIDTH, 400
.equ WINDOWHEIGHT, 300
 
/*******************************************/
/* DONNEES INITIALISEES */
/*******************************************/
.data
szWindowName: .asciz "Windows Raspberry"
szRetourligne: .asciz "\n"
szMessDebutPgm: .asciz "Program start. \n"
szMessErreur: .asciz "Server X not found.\n"
szMessErrfen: .asciz "Can not create window.\n"
szMessErreurX11: .asciz "Error call function X11. \n"
szMessErrGc: .asciz "Can not create graphics context.\n"
szMessErrFont: .asciz "Font not found.\n"
szTitreFenRed: .asciz "Pi"
szTexte1: .asciz "Hello world! "
.equ LGTEXTE1, . - szTexte1
szTexte2: .asciz "Press q for close window or clic X in system menu."
.equ LGTEXTE2, . - szTexte2
szLibDW: .asciz "WM_DELETE_WINDOW" @ special label for correct close error
 
szfontname: .asciz "-*-helvetica-bold-*-normal-*-12-*" @ for font test
szfontname2: .asciz "-*-fixed-*-*-*-*-13-*-*-*-*-*"
.align 4
stXGCValues: .int 0,0,0xFFA0A0A0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 @ for foreground color gris1
//stXGCValues: .int 0,0,0x00000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 @ for foreground color black
stXGCValues1: .int 0,0,0x00FFFFFF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 @ for foreground color white
stXGCValues2: .int 0,0,0x0000FF00,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 @ for foreground color green
/*******************************************/
/* DONNEES NON INITIALISEES */
/*******************************************/
.bss
.align 4
ptDisplay: .skip 4 @ pointer display
ptEcranDef: .skip 4 @ pointer screen default
ptFenetre: .skip 4 @ pointer window
ptGC: .skip 4 @ pointer graphic context
ptGC1: .skip 4 @ pointer graphic context
ptFont: .skip 4 @ pointer font
key: .skip 4 @ key code
wmDeleteMessage: .skip 8 @ ident close message
event: .skip 400 @ TODO: event size ??
PrpNomFenetre: .skip 100 @ window name proprety
buffer: .skip 500
sbuffer1: .skip 500
iWhite: .skip 4 @ rgb code for white pixel
iBlack: .skip 4 @ rgb code for black pixel
iSens: .skip 4 @ direction of travel
/**********************************************/
/* -- Code section */
/**********************************************/
.text
.global main
iOfWhite: .int iWhite - .
iOfBlack: .int iBlack - .
iOfszMessDebutPgm: .int szMessDebutPgm - .
iOfptDisplay: .int ptDisplay - .
iOfptEcranDef: .int ptEcranDef - .
iOfszLibDW: .int szLibDW - .
main: @ entry of program
adr r0,iOfszMessDebutPgm @
ldr r1,[r0]
add r0,r1
bl affichageMess @ display start message on console linux
/* attention r6 pointer display*/
/* attention r8 pointer graphic context 1 */
/* attention r9 ident window */
/* attention r10 pointer graphic context 2 */
/*****************************/
/* OPEN SERVER X11 */
/*****************************/
mov r0,#0
bl XOpenDisplay @ open X server
cmp r0,#0 @ error ?
beq erreurServeur
adr r2,iOfptDisplay
ldr r1,[r2]
add r1,r2
str r0,[r1] @ store display address
 
mov r6,r0 @ and in register r6
ldr r2,[r0,#+132] @ load default_screen
adr r1,iOfptEcranDef
ldr r3,[r1]
add r1,r3
str r2,[r1] @ store default_screen
mov r2,r0
ldr r0,[r2,#+140] @ load pointer screen list
ldr r5,[r0,#+52] @ load value white pixel
adr r4,iOfWhite @ and store in memory
ldr r3,[r4]
add r4,r3
str r5,[r4]
ldr r7,[r0,#+56] @ load value black pixel
adr r4,iOfBlack @ and store in memory
ldr r5,[r4]
add r4,r5
str r7,[r4]
ldr r4,[r0,#+28] @ load bits par pixel
ldr r1,[r0,#+8] @ load root windows
/**************************/
/* CREATE WINDOW */
/**************************/
mov r0,r6 @ address display
mov r2,#0 @ window position X
mov r3,#0 @ window position Y
mov r8,#0 @ for stack alignement
push {r8}
push {r7} @ background = black pixel
push {r5} @ border = white pixel
mov r8,#2 @ border size
push {r8}
mov r8,#WINDOWHEIGHT @ height
push {r8}
mov r8,#WINDOWWIDTH @ width
push {r8}
bl XCreateSimpleWindow
add sp,#24 @ stack alignement 6 push (4 bytes * 6)
cmp r0,#0 @ error ?
beq erreurF
 
adr r1,iOfptFenetre
ldr r3,[r1]
add r1,r3
str r0,[r1] @ store window address in memory
mov r9,r0 @ and in register r9
/*****************************/
/* add window property */
/*****************************/
mov r0,r6 @ display address
mov r1,r9 @ window address
adr r2,iOfszWindowName @ window name
ldr r5,[r2]
add r2,r5
adr r3,iOfszTitreFenRed @ window name reduced
ldr r5,[r3]
add r3,r5
mov r4,#0
push {r4} @ parameters not use
push {r4}
push {r4}
push {r4}
bl XSetStandardProperties
add sp,sp,#16 @ stack alignement for 4 push
/**************************************/
/* for correction window close error */
/**************************************/
mov r0,r6 @ display address
adr r1,iOfszLibDW @ atom address
ldr r5,[r1]
add r1,r5
mov r2,#1 @ False créate atom if not exists
bl XInternAtom
cmp r0,#0 @ error X11 ?
blt erreurX11 @ Modif avril 22 pour android (ble pour raspberry)
adr r1,iOfwmDeleteMessage @ recept address
ldr r5,[r1]
add r1,r5
str r0,[r1]
mov r2,r1 @ return address
mov r0,r6 @ display address
mov r1,r9 @ window address
mov r3,#1 @ number of protocols
bl XSetWMProtocols
cmp r0,#0 @ error X11 ?
ble erreurX11
/***********************************/
/* load font */
/* remark : see font list X11 on your system */
/***********************************/
mov r0,r6 @ display address
bl loadFont
 
/**********************************/
/* create graphic context */
/**********************************/
mov r0,r6 @ display address
mov r1,r9 @ window address
bl createContextGraphic
 
/****************************/
/* modif window background */
/****************************/
mov r0,r6 @ display address
mov r1,r9 @ window address
ldr r2,iGris1 @ background color
bl XSetWindowBackground
cmp r0,#0 @ error ?
ble erreurX11
/***************************/
/* OUF!! window display */
/***************************/
mov r0,r6 @ display address
mov r1,r9 @ window address
bl XMapWindow
@ copy text in buffer
adr r0,iOfszTexte1 @ string address
ldr r5,[r0]
add r0,r5
adr r1,iOfsbuffer1 @ buffer address
ldr r5,[r1]
add r1,r5
mov r2,#0
1: @ loop copy character
ldrb r3,[r0,r2]
strb r3,[r1,r2]
cmp r3,#0
addne r2,r2,#1
bne 1b
/****************************/
/* Autorisations */
/****************************/
mov r0,r6 @ display address
mov r1,r9 @ window address
ldr r2,iFenetreMask @ autorisation mask
bl XSelectInput
cmp r0,#0 @ error ?
ble erreurX11
/****************************/
/* Events loop */
/****************************/
1:
mov r0,r6 @ display address
bl XPending @ loading the number of events
cmp r0,#0
bne 2f @ a event is occurring
adr r3,iOfsbuffer1
ldr r5,[r3]
add r3,r5
mov r0,r6 @ display address
mov r1,r9 @ window ident
mov r2,r8 @ graphic context
bl animate @ string display and move
b 1b
2:
mov r0,r6 @ display address
adr r1,iOfevent @ events address
ldr r5,[r1]
add r1,r5
bl XNextEvent @ event ?
adr r0,iOfevent
ldr r5,[r0]
add r0,r5
ldr r0,[r0] @ code event
cmp r0,#KeyPressed @ key ?
bne 2f
adr r0,iOfevent @ yes read key in buffer
ldr r5,[r0]
add r0,r5
adr r1,iOfbuffer
ldr r5,[r1]
add r1,r5
mov r2,#255
adr r3,iOfkey
ldr r5,[r3]
add r3,r5
mov r4,#0
push {r4} @ stack alignement
push {r4}
bl XLookupString
add sp,#8 @ stack alignement 2 push
cmp r0,#1 @ is character key ?
bne 2f
adr r0,iOfbuffer @ yes -> load first buffer character
ldr r5,[r0]
add r0,r5
ldrb r0,[r0]
cmp r0,#0x71 @ character q for quit
beq 5f @ yes -> end
b 4f
2:
/************************************/
/* clic mouse button */
/************************************/
cmp r0,#ButtonPress @ clic mouse buton
bne 3f
adr r0,iOfevent
ldr r5,[r0]
add r0,r5
ldr r1,[r0,#+32] @ position X mouse clic
ldr r2,[r0,#+36] @ position Y
cmp r1,#50 @ test if position clic is on the screen string approx.
blt 4f
cmp r1,#150
bgt 4f
cmp r2,#80
blt 4f
cmp r2,#105
bgt 4f
adr r1,iOfiSens @ load direction
ldr r2,[r1]
add r1,r2
ldr r2,[r1]
cmp r2,#0 @ direction inversion
moveq r2,#1
movne r2,#0
str r2,[r1]
b 4f
3:
cmp r0,#ClientMessage @ code for close window within error
bne 4f
adr r0,iOfevent
ldr r5,[r0]
add r0,r5
ldr r1,[r0,#+28] @ code message address
adr r2,iOfwmDeleteMessage @ equal code window créate ???
ldr r5,[r2]
add r2,r5
ldr r2,[r2]
cmp r1,r2
beq 5f @ yes -> end window
 
4: @ loop for other event
b 1b
iOfptFenetre: .int ptFenetre - .
iOfszWindowName: .int szWindowName - .
iOfszTitreFenRed: .int szTitreFenRed - .
/***********************************/
/* Close window -> free ressources */
/***********************************/
5:
mov r0,r6 @ display address
adr r1,iOfptGC
ldr r5,[r1]
add r1,r5
ldr r1,[r1] @ load context graphic address
bl XFreeGC
mov r0,r6 @ display address
adr r1,iOfptGC1
ldr r5,[r1]
add r1,r5
ldr r1,[r1] @ load context graphic address
bl XFreeGC
cmp r0,#0
blt erreurX11
mov r0,r6 @ display address
mov r1,r9 @ window address
bl XDestroyWindow
cmp r0,#0
blt erreurX11
mov r0,r6 @ display address
bl XCloseDisplay
cmp r0,#0
blt erreurX11
mov r0,#0 @ return code OK
b 100f
 
erreurF: @ create error window but possible not necessary. Display error by server
adr r1,iOfszMessErrfen
ldr r5,[r1]
add r1,r5
bl displayError
mov r0,#1 @ return error code
b 100f
erreurGC: @ error create graphic context
adr r1,iOfszMessErrGc
ldr r5,[r1]
add r1,r5
bl displayError
mov r0,#1
b 100f
erreurX11: @ erreur X11
adr r1,iOfszMessErreurX11
ldr r5,[r1]
add r1,r5
bl displayError
mov r0,#1
b 100f
erreurServeur: @ error no found X11 server see doc putty and Xming
adr r1,iOfszMessErreur
ldr r5,[r1]
add r1,r5
bl displayError
mov r0,#1
b 100f
 
100: @ standard end of the program
mov r7, #EXIT
svc 0
 
iOfevent: .int event - .
iOfbuffer: .int buffer - .
iOfsbuffer1: .int sbuffer1 - .
iOfkey: .int key - .
iOfszMessErreurX11: .int szMessErreurX11 - .
iOfszMessErreur: .int szMessErreur - .
iOfszMessErrfen: .int szMessErrfen - .
iOfszTexte1: .int szTexte1 - .
iOfszTexte2: .int szTexte2 - .
iOfPrpNomFenetre: .int PrpNomFenetre - .
iOfwmDeleteMessage: .int wmDeleteMessage - .
 
iFenetreMask: .int KeyPressMask|ButtonPressMask|StructureNotifyMask
iGris1: .int 0xFFA0A0A0
iOfiSens: .int iSens - .
/******************************************************************/
/* load font */
/******************************************************************/
/* r0 contains display */
loadFont:
push {r1-r2,lr} @ save registers
adr r1,iOfszfontname @ font name
ldr r2,[r1]
add r1,r2
bl XLoadQueryFont
cmp r0,#0
beq 99f @ font not find
adr r1,iOfptFont
ldr r2,[r1]
add r1,r2
str r0,[r1]
mov r0,#0
b 100f
99:
adr r1,iOfszMessErrFont
ldr r5,[r1]
add r1,r5
bl displayError
mov r0,#1
100:
pop {r1-r2,pc} @ restaur registers
iOfszfontname: .int szfontname2 - .
iOfptFont: .int ptFont - .
iOfszMessErrFont: .int szMessErrFont - .
/******************************************************************/
/* Context Graphic création */
/******************************************************************/
/* r0 contains display */
/* r1 window address */
/* REMARKS : no standard use registers return GC1 in r8 and GC2 in r10 */
createContextGraphic:
push {r1-r7,lr} @ save registers
/**********************************/
/* create graphic context */
/**********************************/
mov r6,r0 @ save display address
mov r7,r1 @ save window address
adr r3,iOfptFont @ font pointer
ldr r1,[r3]
add r3,r1
ldr r3,[r3]
ldr r4,[r3,#4] @ load font ident
adr r3,iOfstXGCValues2 @ green color in foreground
ldr r5,[r3]
add r3,r5 @ this parameter is used by XcreateGC
str r4,[r3,#60] @ store ident font in offset 60
mov r0,r4
mov r0,r6 @ display address
mov r1,r7 @ window address
mov r2,#GCForeground|GCFont @ @ green color in foreground and font
bl XCreateGC
cmp r0,#0 @ error ?
beq 99f
adr r1,iOfptGC
ldr r5,[r1]
add r1,r5
str r0,[r1] @ store address graphic context
mov r8,r0 @ and in r8
/**********************************/
/* create 2 graphic context */
/**********************************/
mov r0,r6 @ display address
mov r1,r7 @ window address
mov r2,#GCForeground @ red color in Foreground
adr r3,iOfstXGCValues
ldr r5,[r3]
add r3,r5
bl XCreateGC
cmp r0,#0 @ error ?
beq erreurGC
adr r1,iOfptGC1
ldr r5,[r1]
add r1,r5
str r0,[r1] @ store address graphic context
mov r10,r0 @ and in r10
b 100f
99: @ create error
adr r1,iOfszMessErrGc
ldr r5,[r1]
add r1,r5
bl displayError
mov r0,#1
100:
pop {r1-r7,pc} @ restaur registers
iOfszMessErrGc: .int szMessErrGc - .
iOfptGC: .int ptGC - .
iOfptGC1: .int ptGC1 - .
iOfstXGCValues: .int stXGCValues - .
iOfstXGCValues1: .int stXGCValues1 - .
iOfstXGCValues2: .int stXGCValues2 - .
/******************************************************************/
/* animation */
/******************************************************************/
/* r0 contains display */
/* r1 contains window ident */
/* r2 contains context graphic */
/* r3 string address */
animate:
push {r2-r9,lr} @ save registers
mov r5,r3 @ save string address
mov r6,r0 @ save display
mov r7,r1 @ save window
mov r8,r2 @ save GC
@ erase text in the windows
mov r0,r6 @ display address
mov r1,r7 @ window ident
mov r2,r10 @ graphic context
mov r3,#50 @ position x
mov r4,#LGTEXTE1 - 1 @ string lenght
push {r4} @ stack alignement
push {r4} @ to stack parameter
 
push {r5} @ string address
mov r4,#100 @ position y
push {r4}
bl XDrawString
add sp,sp,#16 @ stack alignement (4 push)
 
mov r0,#LGTEXTE1 -2 @ string length
adr r1,iOfiSens @ load direction
ldr r2,[r1]
add r1,r2
ldr r2,[r1]
cmp r2,#0 @ test direction
bne 2f
ldrb r9,[r5,r0] @ last character
sub r1,r0,#1
1: @ loop to move character one position
ldrb r2,[r5,r1]
strb r2,[r5,r0]
sub r0,r0,#1
subs r1,r1,#1
bge 1b
add r1,r1,#1
strb r9,[r5,r1] @ last character -> first character
b 4f
2:
ldrb r9,[r5] @ first character
mov r1,#1
sub r2,r1,#1
3: @ loop to move character
ldrb r3,[r5,r1]
strb r3,[r5,r2]
add r2,r2,#1
add r1,r1,#1
cmp r1,r0
ble 3b
strb r9,[r5,r2] @ first character -> last character
4:
@ write text in the windows
mov r0,r6 @ display address
mov r1,r7 @ window ident
mov r2,r8 @ graphic context
mov r3,#50 @ position x
mov r4,#LGTEXTE1 - 1 @ string lenght
push {r4} @ stack alignement
push {r4} @ to stack parameter
push {r5} @ string address
mov r4,#100 @ position y
push {r4}
bl XDrawString
add sp,sp,#16 @ stack alignement (4 push)
mov r0,#20 @ timeout 5s approx.
bl delay
 
100:
pop {r2-r9,pc} @ restaur registers
/******************************************************************/
/* timeout */
/******************************************************************/
/* r0 contains delay */
 
delay:
push {r1,lr} @ save registers
ldr r1,iCst30000000
mul r0,r1,r0
1:
subs r0,r0,#1
bge 1b
100:
pop {r1,pc} @ restaur registers
iCst30000000: .int 30000000
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">SetTimer, Animate ; Timer runs every 250 ms.
String := "Hello World "
Gui, Add, Text, vS gRev, %String%
Line 240 ⟶ 1,430:
Rev: ; Runs whenever user clicks on the text control
Reverse := !Reverse
return</langsyntaxhighlight>
 
=={{header|BASIC256BASIC}}==
<lang ==={{header|BASIC256>str$}}==="Hello, World! "
<syntaxhighlight lang="basic256">str$="Hello, World! "
direction=0 #value of 0: to the right, 1: to the left.
tlx=10 #Top left x
Line 268 ⟶ 1,459:
end if
clickclear
goto main</langsyntaxhighlight>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> VDU 23,22,212;40;16,32,16,128
txt$ = "Hello World! "
direction% = TRUE
Line 286 ⟶ 1,477:
ENDIF
WAIT 20
UNTIL FALSE</langsyntaxhighlight>
 
=={{header|C}}==
{{libheader|GTK}}
(NB: implicitly, through GTK, it uses also Pango library)
<langsyntaxhighlight lang="c">#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
Line 362 ⟶ 1,553:
gtk_main();
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Windows.Forms;
Line 421 ⟶ 1,612:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{libheader|Qt}}
Contents of animationwidget.cpp:
<langsyntaxhighlight lang="cpp">#include "animationwidget.h"
 
#include <QLabel>
Line 452 ⟶ 1,643:
void AnimationWidget::mousePressEvent(QMouseEvent*) {
right_ = !right_;
}</langsyntaxhighlight>
 
Contents of animationwidget.h:
<langsyntaxhighlight lang="cpp">#ifndef ANIMATIONWIDGET_H
#define ANIMATIONWIDGET_H
 
Line 470 ⟶ 1,661:
};
 
#endif // ANIMATIONWIDGET_H</langsyntaxhighlight>
 
Contents of main.cpp:
<langsyntaxhighlight lang="cpp">#include "animationwidget.h"
 
#include <QApplication>
Line 482 ⟶ 1,673:
w.show();
return a.exec();
}</langsyntaxhighlight>
 
=={{header|Ceylon}}==
module.ceylon
<langsyntaxhighlight lang="ceylon">native("jvm")
module animation "1.0.0" {
import java.desktop "8";
}
</syntaxhighlight>
</lang>
run.ceylon
<langsyntaxhighlight lang="ceylon">import javax.swing {
JFrame,
JLabel,
Line 534 ⟶ 1,725:
frame.pack();
frame.visible = true;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
Clojure is a JVM language so this example uses Swing, and illustrates Clojure's platform integration.
<langsyntaxhighlight lang="clojure">(import '[javax.swing JFrame JLabel])
(import '[java.awt.event MouseAdapter])
 
Line 570 ⟶ 1,761:
(.setVisible true))
(future-call animator) ;simple way to run animator on a separate thread</langsyntaxhighlight>
 
=={{header|Commodore BASIC}}==
There is no window management in the stock version of BASIC V2 on the Commodore 64 or VIC 20. This example below is generic enough to use on all Commodore variants. Note: Asterisks (*) may be replaced with Commodore graphics characters for a more decorative "window".
<langsyntaxhighlight lang="commodorebasicv2">
1 rem rosetta code
2 rem task: animation
Line 597 ⟶ 1,788:
1000 t$=right$(t$,len(t$)-1)+left$(t$,1):return
1010 t$=right$(t$,1)+left$(t$,len(t$)-1):return
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
The ltk package provides a lisp interface to Tk for creating graphical interfaces. Assuming ''ltk'' has been installed somewhere the following will work as per the Tcl example.
{{libheader|Tk}}
<langsyntaxhighlight lang="lisp">(use-package :ltk)
(defparameter *message* "Hello World! ")
Line 634 ⟶ 1,825:
(ltk:mainloop))))
(basic-animation)</langsyntaxhighlight>
 
=={{header|D}}==
Line 641 ⟶ 1,832:
{{libheader|SDL_ttf}}
{{libheader|tools}}
<langsyntaxhighlight lang="d">module test26;
 
import qd, SDL_ttf, tools.time;
Line 664 ⟶ 1,855:
) dir = !dir;
}
}</langsyntaxhighlight>
 
=={{header|Dart}}==
Line 670 ⟶ 1,861:
{{libheader|Flutter}}
view it on dartpad!
<langsyntaxhighlight lang="javascript">import 'package:flutter/material.dart';
import 'dart:async' show Timer;
 
Line 748 ⟶ 1,939:
}
</syntaxhighlight>
</lang>
 
 
===HTML DOM===
{{libheader|Html Dom}}
<langsyntaxhighlight lang="javascript">import 'dart:html';
import 'dart:async';
 
Line 779 ⟶ 1,970:
}
}
</syntaxhighlight>
</lang>
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
Line 788 ⟶ 1,979:
{{libheader| Vcl.StdCtrls}}
{{libheader| Vcl.ExtCtrls}}
<syntaxhighlight lang="delphi">
<lang Delphi>
unit Main;
 
Line 831 ⟶ 2,022:
Caption := Shift(Caption, Reverse);
end;
end.</langsyntaxhighlight>
Form resource:
<syntaxhighlight lang="delphi">
<lang Delphi>
object Form1: TForm1
ClientHeight = 132
Line 849 ⟶ 2,040:
end
end
</syntaxhighlight>
</lang>
=={{header|E}}==
 
{{works with|E-on-Java}} (Java Swing; tested on Mac OS X 10.5.7)
 
<langsyntaxhighlight lang="e"># State
var text := "Hello World! "
var leftward := false
Line 891 ⟶ 2,082:
# Start everything
w.show()
anim.start()</langsyntaxhighlight>
 
Text-only version (no Java dependency; no clicking, use reverse() and stop() to control):
 
<langsyntaxhighlight lang="e">def [reverse, stop] := {
var text := "Hello World! "
var leftward := false
Line 911 ⟶ 2,102:
anim.start()
[def _() { leftward := !leftward; null }, anim.stop]
}</langsyntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang=easylang>
s$ = "Hello world! "
textsize 16
lg = len s$
on timer
color 333
move 10 20
rect 80 20
color 999
move 12 24
text s$
if forw = 0
s$ = substr s$ lg 1 & substr s$ 1 (lg - 1)
else
s$ = substr s$ 2 (lg - 1) & substr s$ 1 1
.
timer 0.2
.
on mouse_down
if mouse_x > 10 and mouse_x < 90
if mouse_y > 20 and mouse_y < 40
forw = 1 - forw
.
.
.
timer 0
</syntaxhighlight>
 
 
=={{header|Elm}}==
<langsyntaxhighlight lang="elm">module Main exposing (..)
 
import Browser
Line 1,026 ⟶ 2,247:
[ text <| rotate message model.time ]
]
</syntaxhighlight>
</lang>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">
(defun animation-start ()
(interactive)
(make-thread
(lambda ()
(let ()
(setq **animation-state** (make-hash-table))
(puthash 'offset 0 **animation-state**)
(puthash 'sleep-cnt 5 **animation-state**)
(puthash 'len 20 **animation-state**)
(puthash 'buffer (make-string (gethash 'len **animation-state**) ? )
**animation-state**)
(puthash 'text "Hello World!" **animation-state**)
(puthash 'forward 't **animation-state**)
(switch-to-buffer-other-window "**animation**")
(erase-buffer)
(insert "\n")
(insert-button
"Revert Direction"
'action (lambda (x)
(let ((forward (gethash 'forward **animation-state**)))
(puthash 'forward (not forward) **animation-state**)))
'follow-link 't)
(while 't
(let ((offset (gethash 'offset **animation-state**))
(len (gethash 'len **animation-state**))
(txt (gethash 'text **animation-state**))
(buff (gethash 'buffer **animation-state**))
(is-forward (gethash 'forward **animation-state**)))
(fillarray buff ? )
(seq-map-indexed (lambda (ch idx)
(aset buff (% (+ offset idx) len) ch))
txt)
(puthash 'buffer buff **animation-state**)
(if is-forward
(puthash 'offset (1+ offset) **animation-state**)
(puthash 'offset (% (+ len (1- offset)) len) **animation-state**))
;;(erase-buffer)
(beginning-of-buffer)
(delete-region (line-beginning-position) (line-end-position))
(insert buff)
;;(message buff)
)
(sleep-for 0 500)
)
)
)
"animation thread")
)
 
(animation-start)
</syntaxhighlight>
 
=={{header|F Sharp|F#}}==
{{libheader|Windows Presentation Foundation}}
<langsyntaxhighlight lang="fsharp">open System.Windows
 
let str = "Hello world! "
Line 1,044 ⟶ 2,323:
button.Content <- str.[i..] + str.[..i-1]
Media.CompositionTarget.Rendering.Add update
(Application()).Run(Window(Content=button)) |> ignore</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight Factorlang="factor">USING: accessors timers calendar kernel models sequences ui
ui.gadgets ui.gadgets.labels ui.gestures ;
FROM: models => change-model ;
Line 1,076 ⟶ 2,355:
[ sentence <model> <animated-label> "Rosetta" open-window ] with-ui ;
MAIN: main</langsyntaxhighlight>
 
=={{header|Fantom}}==
 
<langsyntaxhighlight lang="fantom">
using concurrent
using fwt
Line 1,156 ⟶ 2,435:
}
}
</syntaxhighlight>
</lang>
 
=={{header|FBSL}}==
 
<langsyntaxhighlight lang="qbasic">#INCLUDE <Include\Windows.inc>
 
FBSLSETTEXT(ME, "Hello world! ")
Line 1,189 ⟶ 2,468:
END IF
FBSLSETTEXT(ME, caption)
END SUB</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
Line 1,197 ⟶ 2,476:
To exit, push the window's closing cross. (255 + 107 is the combination that is passed to INKEY$ by that button.)
 
<langsyntaxhighlight lang="freebasic">DIM C AS STRING = "Hello World! ", SIZE AS USHORT = LEN(C)
DIM DIRECTION AS BYTE = 0
DIM AS INTEGER X, Y, BTNS
Line 1,229 ⟶ 2,508:
 
SLEEP 100, 1
LOOP</langsyntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
_window = 1
_label = 1
 
void local fn DoIt
window _window, @"Animation", (0,0,480,270)
subclass textlabel _label, @"Hello World! ", (140,112,210,45)
ControlSetFont( _label, fn FontLabelFontOfSize( 36 ) )
ViewSetProperty( _label, @"MoveRight", @(YES) )
timerbegin , 0.1, YES
CFStringRef string = fn ControlStringValue(_label)
CFStringRef chr
BOOL moveRight = fn NumberBoolValue(fn ViewProperty( _label, @"MoveRight" ))
if ( moveRight )
chr = right( string, 1 )
string = fn StringWithFormat( @"%@%@",chr,left(string,len(string)-1) )
else
chr = left( string, 1 )
string = fn StringWithFormat( @"%@%@",right(string,len(string)-1),chr )
end if
textlabel _label, string
timerend
end fn
 
void local fn DoDialog( ev as long, tag as long )
select ( ev )
case _viewMouseDown
select ( tag )
case _label
BOOL moveRight = fn NumberBoolValue(fn ViewProperty( _label, @"MoveRight" ))
if ( moveRight ) then moveRight == NO else moveRight = YES
ViewSetProperty( _label, @"MoveRight", @(moveRight) )
end select
end select
end fn
 
fn DoIt
 
on dialog fn DoDialog
 
HandleEvents
</syntaxhighlight>
 
=={{header|Gambas}}==
<langsyntaxhighlight lang="gambas">'This code will create the necessary controls on a GUI Form
 
hLabel As Label 'Label needed to display the 'Hello World! " message
Line 1,297 ⟶ 2,624:
hLabel.text = sString 'Display the result
 
End</langsyntaxhighlight>
'''[http://www.cogier.com/gambas/Animation.png Click here for image of running code]'''
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,358 ⟶ 2,685:
}
}
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
Using simple graphics {{libheader|HGL}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
<langsyntaxhighlight lang="haskell">import Graphics.HGL.Units (Time, Point, Size, )
import Graphics.HGL.Draw.Monad (Graphic, )
import Graphics.HGL.Draw.Text
Line 1,387 ⟶ 2,714:
loop t' d
loop "Hello world ! " 1 )</langsyntaxhighlight>
Run within interpreter GHCi:
<syntaxhighlight lang ="haskell">*Main> runAnim</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">CHARACTER string="Hello World! "
 
WINDOW(WINdowhandle=wh, Height=1, X=1, TItle="left/right click to rotate left/right, Y-click-position sets milliseconds period")
Line 1,409 ⟶ 2,736:
SUBROUTINE Mouse_callback()
direction = button_type ! 4 == left button up, 8 == right button up
END </langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
The following code uses features exclusive to Unicon.
 
<langsyntaxhighlight Uniconlang="unicon">import gui
$include "guih.icn"
 
Line 1,458 ⟶ 2,785:
w.show_modal ()
end
</syntaxhighlight>
</lang>
 
The following code uses features exclusive to Icon.
<syntaxhighlight lang="icon">
<lang Icon>
link graphics
 
Line 1,483 ⟶ 2,810:
}
end
</syntaxhighlight>
</lang>
 
=={{header|J}}==
{{works with|J8}}
<langsyntaxhighlight lang="j">coinsert'jgl2' [ require'gl2'
MESSAGE =: 'Hello World! '
Line 1,512 ⟶ 2,839:
)
anim_run ''</langsyntaxhighlight>
 
{{works with|J6}}
<langsyntaxhighlight lang="j">coinsert'jgl2' [ require'gl2'
 
MESSAGE =: 'Hello World! '
Line 1,540 ⟶ 2,867:
)
 
anim_run ''</langsyntaxhighlight>
 
=={{header|Java}}==
{{libheader|Swing}}
<langsyntaxhighlight lang="java">import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
Line 1,604 ⟶ 2,931:
return String.valueOf(rotated);
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}} + {{header|HTML}}==
<langsyntaxhighlight lang="javascript"><html> <head>
<title>RC: Basic Animation</title>
<script type="text/javascript">
Line 1,630 ⟶ 2,957:
</head> <body onload="animate('target')">
<pre id="target">Hello World! </pre>
</body> </html></langsyntaxhighlight>
 
=={{header|JavaScript}} + {{header|SVG}}==
<langsyntaxhighlight lang="javascript"><svg xmlns="http://www.w3.org/2000/svg"
width="100" height="40">
<script type="text/javascript">
Line 1,655 ⟶ 2,982:
<rect width="100" height="40" fill="yellow"/>
<text x="2" y="20" onload="animate(this);">Hello World! </text>
</svg></langsyntaxhighlight>
 
=={{header|Julia}}==
{{libheader|Julia/Tk}}
<syntaxhighlight lang="julia">
<lang Julia>
using Tk
 
Line 1,695 ⟶ 3,022:
 
windowanim(frameinterval)
</syntaxhighlight>
</lang>
{{libheader|Julia/Gtk}}
<langsyntaxhighlight lang="julia">
using Gtk.ShortNames
Line 1,733 ⟶ 3,060:
 
textanimation(frameinterval)
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.Dimension
Line 1,791 ⟶ 3,118:
}
Timer(false).schedule(task, 0, 500)
}</langsyntaxhighlight>
 
=={{header|LabVIEW}}==
Line 1,798 ⟶ 3,125:
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb"> txt$ = "Hello World! "
txtLength = len(txt$)
direction=1
Line 1,831 ⟶ 3,158:
timer 0
close #demo
end</langsyntaxhighlight>
 
=={{header|Logo}}==
{{works with|UCB Logo}}
<langsyntaxhighlight lang="logo">to rotate.left :thing
output lput first :thing butfirst :thing
end
Line 1,854 ⟶ 3,181:
 
hideturtle
until [key?] [step.animation]</langsyntaxhighlight>
 
 
=={{header|Lua}}==
{{works with|LÖVE}}
<syntaxhighlight lang="lua">function love.load()
text = "Hello World! "
length = string.len(text)
update_time = 0.3
timer = 0
right_direction = true
local width, height = love.graphics.getDimensions( )
 
local size = 100
local font = love.graphics.setNewFont( size )
local twidth = font:getWidth( text )
local theight = font:getHeight( )
x = width/2 - twidth/2
y = height/2-theight/2
end
 
function love.update(dt)
timer = timer + dt
if timer > update_time then
timer = timer - update_time
if right_direction then
text = string.sub(text, 2, length) .. string.sub(text, 1, 1)
else
text = string.sub(text, length, length) .. string.sub(text, 1, length-1)
end
end
end
 
 
function love.draw()
love.graphics.print (text, x, y)
end
 
function love.keypressed(key, scancode, isrepeat)
if false then
elseif key == "escape" then
love.event.quit()
end
end
 
function love.mousepressed( x, y, button, istouch, presses )
right_direction = not right_direction
end</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Line 1,860 ⟶ 3,240:
Any Button can use a blink, a timer which return a changed value, true or false, but here we didn't use it (so we didn't Read from event's stack of values. We can place Stack statement to view this stack in console).
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module UseBlink {
Def boolean direction=True
Line 1,888 ⟶ 3,268:
UseBlink
 
</syntaxhighlight>
</lang>
===Using Every Statement===
We can use console as window too. Although we don't have events for this window, we can read mouse button. Also we use split screen so first line (line 0) has the title, and all other lines are cleared before we print on it, every 200ms
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module UseEvery {
Window 16, 6000,4000;
Line 1,909 ⟶ 3,289:
}
UseEvery
</syntaxhighlight>
</lang>
 
===Using Thread===
Line 1,916 ⟶ 3,296:
When a thread created saves the current layer, to use it in each iteration.
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module UseThread {
Def boolean direction=True
Line 1,940 ⟶ 3,320:
}
UseThread
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
First, create a textbox, and by right-clicking it, and selecting component properties, change its name to "Text". Then, create 2 buttons, changing the caption on one to "Reverse", and the other to "Forward". In the edit click action of each respective button, you will put:
<syntaxhighlight lang="maple">
<lang Maple>
ScrollText(GP("Text",value),"Forward",65);
</langsyntaxhighlight>
and:
<syntaxhighlight lang="maple">
<lang Maple>
ScrollText(GP("Text",value),"Reverse",65);
</syntaxhighlight>
</lang>
Then in the startup actions, accessed by clicking the 2 gears, add this:
<syntaxhighlight lang="maple">
<lang Maple>
macro(SP=DocumentTools:-SetProperty, GP=DocumentTools:-GetProperty);
SP("Text",value,"Hello World! ");
Line 1,971 ⟶ 3,351:
end do:
end proc:
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">mystring = "Hello World! ";
Scroll[str_, dir_] := StringJoin @@ RotateLeft[str // Characters, dir];
GiveString[dir_] := (mystring = Scroll[mystring, dir]);
Line 1,983 ⟶ 3,363:
Refresh[GiveString[direction], UpdateInterval -> 1/8]],
TrackedSymbols -> {}], {"MouseClicked" :> (direction *= -1)}]]
}];</langsyntaxhighlight>
 
=={{header|MAXScript}}==
Creates a window with a rotating label and 2 buttons to change the direction.
 
<syntaxhighlight lang="maxscript">
<lang MAXScript>
try destroydialog animGUI catch ()
 
Line 2,036 ⟶ 3,416:
 
createdialog animGUI
</syntaxhighlight>
</lang>
 
=={{header|MiniScript}}==
{{works with|Mini Micro}}
<syntaxhighlight lang="miniscript">clear
<lang MiniScript>clear
text.inverse = true
s = "Hello World! "
toggle = true
while not key.available
while true
text.row = 12
text.column = 15
print " " + s + " "
wait 0.1
if key.available then
s = s[-1] + s[:-1]
toggle = not toggle
key.clear
yield
end if
if toggle then
s = s[-1] + s[:-1]
else
s = s[1:] + s[0]
end if
end while</syntaxhighlight>
 
Alternate version that scrolls pixel by pixel rather than character by character.
<syntaxhighlight lang="miniscript">clear
txt = "Hello World! "
width = txt.len * 20 + 4
gfx.print txt,0,608,color.white, "large"
toggle = false
 
while true
img1 = gfx.getImage(toggle, 608, width - 1, 32)
img2 = gfx.getImage((not toggle) * (width - 1), 608, 1, 32)
gfx.drawImage img1, (not toggle), 608
gfx.drawImage img2, toggle * (width - 1), 608
if key.available then
toggle = not toggle
key.clear
end if
yield
end while
</syntaxhighlight>
text.inverse = false
key.clear</lang>
 
=={{header|Nim}}==
{{libheader|gintro}}
<langsyntaxhighlight Nimlang="nim">import gintro/[glib, gobject, gdk, gtk, gio]
 
type
Line 2,115 ⟶ 3,522:
let app = newApplication(Application, "Rosetta.animation")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">functor
import
Application
Line 2,177 ⟶ 3,584:
{Start}
end</langsyntaxhighlight>
 
=={{header|Pascal}}==
===LCL (Lazarus)===
<langsyntaxhighlight Pascallang="pascal">program HelloWorldAnimatedGUI;
 
uses {$IFDEF UNIX} {$IFDEF UseCThreads}
Line 2,257 ⟶ 3,664:
Application.CreateForm(TFrmHelloWorldAnim, FrmHelloWorldAnim);
Application.Run;
end.</langsyntaxhighlight>
Example can be compiled by FreePascal/Lazarus.
Did all in one file, normally you have the project-file, the form-unit- and the form-resource-file.
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use Tk;
use Time::HiRes qw(sleep);
 
Line 2,288 ⟶ 3,695:
$mw->update();
}
}</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
Clicking on the label changes the animation direction.
<lang Phix>-- demo\rosetta\Animation.exw
<!--<syntaxhighlight lang="phix">(phixonline)-->
include pGUI.e
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Animation.exw</span>
 
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
string hw = "Hello World! "
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
bool direction = true
Ihandle label
<span style="color: #004080;">string</span> <span style="color: #000000;">hw</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Hello World! "</span>
 
<span style="color: #004080;">bool</span> <span style="color: #000000;">direction</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span>
function timer_cb(Ihandle /*ih*/)
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">label</span>
hw = iff(direction?hw[$]&hw[1..-2]:hw[2..$]&hw[1])
IupSetAttribute(label,"TITLE",hw)
<span style="color: #008080;">function</span> <span style="color: #000000;">button_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000080;font-style:italic;">/*button*/</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">pressed</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">/*x*/</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">/*y*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000080;font-style:italic;">/*pStatus*/</span><span style="color: #0000FF;">)</span>
return IUP_IGNORE
<span style="color: #008080;">if</span> <span style="color: #000000;">pressed</span> <span style="color: #008080;">then</span>
end function
<span style="color: #000000;">direction</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">not</span> <span style="color: #000000;">direction</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
function key_cb(Ihandle /*ih*/, atom c)
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CONTINUE</span>
if c=K_ESC then return IUP_CLOSE end if
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
if c=K_UP then direction = not direction end if
return IUP_CONTINUE
<span style="color: #008080;">function</span> <span style="color: #000000;">timer_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #000000;">hw</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">direction</span> <span style="color: #0000FF;">?</span> <span style="color: #000000;">hw</span><span style="color: #0000FF;">[$]</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">hw</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span>
 
<span style="color: #0000FF;">:</span> <span style="color: #000000;">hw</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">hw</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span>
procedure main()
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">label</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hw</span><span style="color: #0000FF;">)</span>
IupOpen()
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_IGNORE</span>
label = IupLabel(hw,"FONT=\"Verdana, 18\"")
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
Ihandle dlg = IupDialog(label,"TITLE=Animation, DIALOGFRAME=YES, CHILDOFFSET=70x40, SIZE=200x80")
IupSetCallback(dlg, "K_ANY", Icallback("key_cb"))
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
IupShow(dlg)
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
Ihandle hTimer = IupTimer(Icallback("timer_cb"), 160)
<span style="color: #000000;">label</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #000000;">hw</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`FONT="Verdana, 18"`</span><span style="color: #0000FF;">)</span>
IupMainLoop()
<span style="color: #7060A8;">IupSetCallback</span><span style="color: #0000FF;">(</span><span style="color: #000000;">label</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"BUTTON_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"button_cb"</span><span style="color: #0000FF;">))</span>
IupClose()
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">label</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE=Animation, DIALOGFRAME=YES, CHILDOFFSET=70x40, SIZE=200x80"</span><span style="color: #0000FF;">)</span>
end procedure
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
 
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">hTimer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupTimer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"timer_cb"</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">160</span><span style="color: #0000FF;">)</span>
main()</lang>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
 
=={{header|PicoLisp}}==
===Plain text===
A plain text version. The following script works in an XTerm window.
<langsyntaxhighlight PicoLisplang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(prin "^[[?9h") # Mouse reporting on
Line 2,340 ⟶ 3,755:
(setq Dir (if (= 1 Dir) 12 1)) )
(key) (key) )
(do (length Text) (prin "^H")) )</langsyntaxhighlight>
===HTML/JavaScript===
The standard PicoLisp GUI is HTTP based. Connect your browser to
Line 2,347 ⟶ 3,762:
The scrolling text is displayed in a button. Clicking on the button
reverses the scroll direction.
<langsyntaxhighlight PicoLisplang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(load "@ext.l" "@lib/http.l" "@lib/xhtml.l" "@lib/form.l")
Line 2,364 ⟶ 3,779:
 
(server 8080 "!start")
(wait)</langsyntaxhighlight>
 
===Java/Swing===
This solution works on ErsatzLisp, the Java version of PicoLisp.
<langsyntaxhighlight PicoLisplang="picolisp">#!ersatz/pil
 
(setq
Line 2,389 ⟶ 3,804:
(loop
(wait 200)
(java Label 'setText (pack (do Dir (rot Text)))) )</langsyntaxhighlight>
 
=={{header|Processing}}==
<langsyntaxhighlight lang="processing">String txt = "Hello, world! ";
boolean dir = true;
 
Line 2,417 ⟶ 3,832:
}
return String.valueOf(rotated);
}</langsyntaxhighlight>
 
==={{header|Processing Python mode}}===
Line 2,423 ⟶ 3,838:
When the user clicks on the (windowed) text, it should reverse its direction.
 
<langsyntaxhighlight lang="python">txt = "Hello, world! "
left = True
 
Line 2,444 ⟶ 3,859:
rotated = text[startIdx:] + text[:startIdx]
return rotated
</syntaxhighlight>
</lang>
 
=={{header|Prolog}}==
SWI-Prolog has a grapghic interface XPCE.
<langsyntaxhighlight Prologlang="prolog">:- use_module(library(pce)).
 
animation :-
Line 2,522 ⟶ 3,937:
get(S, delete_prefix, Str, V),
get(V, append, Str, S1).
</syntaxhighlight>
</lang>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">OpenWindow(0,0,0,500,100,"Hello World!",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
 
text$ = "Hello World! "
Line 2,554 ⟶ 3,969:
tick = ElapsedMilliseconds()
EndIf
ForEver</langsyntaxhighlight>
 
=={{header|Python}}==
===Using PyQt===
{{libheader|PyQt5}}
<langsyntaxhighlight lang="python">#!/usr/bin/env python3
import sys
 
Line 2,602 ⟶ 4,017:
- w.rect().center())
w.show()
sys.exit(app.exec())</langsyntaxhighlight>
===Using pygame===
{{libheader|pygame}}
<langsyntaxhighlight lang="python">import pygame, sys
from pygame.locals import *
pygame.init()
Line 2,659 ⟶ 4,074:
while True:
input(pygame.event.wait())
pygame.display.flip()</langsyntaxhighlight>
===Using Tkinter===
<langsyntaxhighlight lang="python">import Tkinter as tki
 
def scroll_text(s, how_many):
Line 2,684 ⟶ 4,099:
tk.title('Python Animation')
tki.mainloop()
</syntaxhighlight>
</lang>
 
=={{header|Quick BASIC}}==
Line 2,695 ⟶ 4,110:
{{libheader|QB.QLB / QBX.QLB}}
 
<langsyntaxhighlight lang="qbasic">
'here accordingly to the version, QB or QBX
REM $INCLUDE: 'QBX.BI'
Line 2,738 ⟶ 4,153:
IF TIMER < I THEN I = I - 86400 'midnight checking
LOOP
LOOP</langsyntaxhighlight>
 
=={{header|R}}==
Line 2,744 ⟶ 4,159:
 
The basic principle is:create a window with a label in it, then add a handler to the label for rotating the string, and another for changing direction on a click. Use of the tag function allows you to store the text flow direction as an attribute of the label.
<syntaxhighlight lang="r">
<lang r>
rotate_string <- function(x, forwards)
{
Line 2,784 ⟶ 4,199:
handle_rotate_label(lab)
handle_change_direction_on_click(lab)
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">
#lang racket/gui
 
Line 2,829 ⟶ 4,244:
 
(send frame show #t)
</syntaxhighlight>
</lang>
 
 
This is a more functional approach - there is no explicit mutation, everything is handled through event callbacks.
<syntaxhighlight lang="racket">
#lang racket
(require racket/match)
(require 2htdp/image)
(require 2htdp/universe)
 
; program state
; value -> no. of rotations of string
; step -> number (positive for right rotations, else negative)
(struct rotations (value step) #:transparent)
 
(define STR "Hello World! ")
(define LEN (string-length STR))
 
; font
(define COLOR "red")
(define TEXT-SIZE 16) ;; pixels
 
(define (render rots)
(define val (rotations-value rots))
(text (string-append (substring STR val)
(substring STR 0 val))
TEXT-SIZE
COLOR))
 
(define (update rots)
(match rots
[(rotations val dir)
(rotations (modulo (+ val dir) LEN) dir)]))
 
; reverse direction on mouse click
(define (handle-mouse rots x y event)
(case event
; "button-up" indicates mouse click
[("button-up") (rotations (rotations-value rots)
(- (rotations-step rots)))]
[else rots]))
 
; start GUI, with given event handlers
(big-bang (rotations 0 1)
[to-draw render]
[on-tick update]
[on-mouse handle-mouse])
</syntaxhighlight>
 
=={{header|Raku}}==
Line 2,835 ⟶ 4,297:
{{works with|Rakudo|2019.03}}
 
<syntaxhighlight lang="raku" perl6line>use GTK::Simple;
use GTK::Simple::App;
 
Line 2,851 ⟶ 4,313:
$app.set-content($vbox);
 
$app.run;</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Basic Animation"
URL: http://rosettacode.org/wiki/Basic_Animation
Line 2,896 ⟶ 4,358:
]
]
]</langsyntaxhighlight>
=={{header|Red}}==
<langsyntaxhighlight Redlang="red">Red ["Animation"]
 
rev: false
roule: does [e: back tail s: t/text either rev [move e s] [move s e]]
view [t: text "Hello world! " rate 5 [rev: not rev] on-time [roule]]</langsyntaxhighlight>
 
=={{header|REXX}}==
This REXX version <u>only</u> works with REXX/Personal or REXX/PC.
<langsyntaxhighlight lang="rexx">/*REXX prg displays a text string (in one direction), and reverses when a key is pressed*/
parse upper version !ver !vernum .; !pcRexx= 'REXX/PERSONAL'==!ver | 'REXX/PC'==!ver
if \!pcRexx then do
Line 2,927 ⟶ 4,389:
else $= right($, 1)substr($, 1, length($) - 1) /* ··· the other·*/
end /*until*/
halt: /*stick a fork in it, we're all done. */</langsyntaxhighlight><br><br>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Animation
 
Line 2,971 ⟶ 4,433:
next
see nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,010 ⟶ 4,472:
{{trans|Tcl}}
{{libheader|Ruby/Tk}}
<langsyntaxhighlight lang="ruby">require 'tk'
$str = TkVariable.new("Hello World! ")
$dir = :right
Line 3,036 ⟶ 4,498:
animate
Tk.mainloop</langsyntaxhighlight>
 
{{libheader|Shoes}}
<langsyntaxhighlight lang="ruby">Shoes.app do
@direction = 1
@label = para "Hello World! ", :family => 'monospace'
Line 3,049 ⟶ 4,511:
@label.text = @direction > 0 ? t[-1] + t[0..-2] : t[1..-1] + t[0]
end
end</langsyntaxhighlight>
 
=={{header|Rust}}==
==={{libheader|GTK}}===
<langsyntaxhighlight lang="rust">#[cfg(feature = "gtk")]
mod graphical {
extern crate gtk;
Line 3,112 ⟶ 4,574:
 
#[cfg(not(feature = "gtk"))]
fn main() {}</langsyntaxhighlight>
 
=={{header|Scala}}==
{{works with|Scala|2.8}}
<langsyntaxhighlight lang="scala">import scala.actors.Actor.{actor, loop, reactWithin, exit}
import scala.actors.TIMEOUT
import scala.swing.{SimpleSwingApplication, MainFrame, Label}
Line 3,147 ⟶ 4,609:
case _ : MouseClicked => rotator ! Revert
}
}</langsyntaxhighlight>
 
=={{header|Scratch}}==
Line 3,159 ⟶ 4,621:
 
=={{header|smart BASIC}}==
<syntaxhighlight lang smart BASIC="basic">'Animation, by rbytes and Dutchman
word$="Hello World! "
'use button window with text
Line 3,175 ⟶ 4,637:
word$=RIGHT$(word$,LEN(word$)-1)&LEFT$(word$,1)
ENDIF
UNTIL 0</Langsyntaxhighlight>
 
This program can be concatenated onto a single line using ! as the concatenator:
 
<Langsyntaxhighlight smart BASIClang="basic">'by rbytes and Dutchman!word$="Hello World! "!'use button window with text!
SET BUTTONS CUSTOM!SET BUTTONS FONT SIZE 40!DRAW COLOR 0,0,0!DO!'the button is redrawn each loop!BUTTON "anim" TEXT word$ AT 130,100!PAUSE .1!'touching the button reverses the scrolling!IF BUTTON_PRESSED("anim") THEN flag=1-flag!IF flag THEN!'shift right!word$=RIGHT$(word$,1)&LEFT$(word$,LEN(word$)-1)!ELSE!'shift left!word$=RIGHT$(word$,LEN(word$)-1)&LEFT$(word$,1)!ENDIF!UNTIL 0</Langsyntaxhighlight>
 
Mr. Kibernetik, the creator of smart Basic, offered this ultra-compact one-line version:
 
<Langsyntaxhighlight smart BASIClang="basic">w$="Hello World! "!1 BUTTON 0 TEXT w$ AT 0,0!PAUSE .1!IF BUTTON_PRESSED("0") THEN f=1-f!IF f THEN w$=RIGHT$(w$,1)&LEFT$(w$,LEN(w$)-1) ELSE w$=RIGHT$(w$,LEN(w$)-1)&LEFT$(w$,1)!GOTO 1</Langsyntaxhighlight>
 
and smart Basic Forum member sarossell found a way to shorten even that! See if you can spot what is changed.
 
<Langsyntaxhighlight smart BASIClang="basic">w$="Hello World! "!1 BUTTON 0 TEXT w$ AT 0,0!PAUSE .1!IF BUTTON_PRESSED("0") THEN f=1-f!k=LEN(w$)-1!IF f THEN w$=RIGHT$(w$,1)&LEFT$(w$,k) ELSE w$=RIGHT$(w$,k)&LEFT$(w$,1)!GOTO 1</Langsyntaxhighlight>
 
=={{header|Standard ML}}==
Works with PolyML interpreter. Add loop for compilation.
<langsyntaxhighlight Standardlang="standard MLml">open XWindows ;
open Motif ;
Line 3,237 ⟶ 4,699:
)
end;</langsyntaxhighlight>
 
call
Line 3,243 ⟶ 4,705:
 
=={{header|Suneido}}==
<langsyntaxhighlight Suneidolang="suneido">Window(Controller
{
Xmin: 50
Line 3,278 ⟶ 4,740:
super.Destroy()
}
})</langsyntaxhighlight>
 
=={{header|SVG}} (no scripts)==
 
{{works with|Batik|1.7}}
Line 3,286 ⟶ 4,748:
This animation is defined as a smooth movement rather than by moving whole characters, because that is more natural in SVG (without scripting); by characters would require 13 different text elements displayed in sequence.
 
<langsyntaxhighlight lang="xml"><svg xmlns="http://www.w3.org/2000/svg" width="100" height="30">
<g id="all">
<rect width="100%" height="100%" fill="yellow"/>
Line 3,302 ⟶ 4,764:
</g>
</g>
</svg></langsyntaxhighlight>
 
(Does not work in Safari 4.0.2 because it apparently does not implement toggled animations correctly ([http://www.w3.org/TR/2001/REC-smil-animation-20010904/#RestartAttribute see spec]). Dreadful workaround: set the two animations to <code>id="a" begin="0s;all.click" end="all.mousedown"</code> and <code>begin="a.end" end="all.click"</code>, respectively.)
Line 3,308 ⟶ 4,770:
=={{header|Tcl}}==
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tk
set s "Hello World! "
set dir 0
Line 3,327 ⟶ 4,789:
bind .l <Button-1> {set dir [expr {!$dir}]}
# Start the animation
animate</langsyntaxhighlight>
 
=={{header|TI-89 BASIC}}==
Line 3,392 ⟶ 4,854:
=={{header|Vedit macro language}}==
It is not possible to detect mouse clicks while a macro is running. Therefore, the direction is controlled with Caps Lock key.
<langsyntaxhighlight lang="vedit">Buf_Switch(Buf_Free)
Win_Create(Buf_Num, 1, 1, 2, 14)
Ins_Text("Hello World! ")
Line 3,406 ⟶ 4,868:
Update()
Sleep(2)
}</langsyntaxhighlight>
 
=={{header|Visual Basic}}==
Line 3,412 ⟶ 4,874:
This example shows code that is hidden by the IDE. (Form creation is done graphically within the IDE, not at runtime.)
 
<langsyntaxhighlight lang="vb">VERSION 5.00
Begin VB.Form Form1
Begin VB.Timer Timer1
Line 3,442 ⟶ 4,904:
End If
Label1.Caption = x
End Sub</langsyntaxhighlight>
 
=={{header|Wren}}==
{{libheader|DOME}}
<langsyntaxhighlight ecmascriptlang="wren">import "graphics" for Canvas, Color
import "dome" for Window
import "input" for Mouse
Line 3,487 ⟶ 4,949:
}
 
var Game = Animation.new()</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes;
int CpuReg, Dir, I, J;
char Str;
Line 3,512 ⟶ 4,974:
if CpuReg(1) then Dir:= -Dir;
until KeyHit; \any keystroke terminates program
]</langsyntaxhighlight>
 
=={{header|Yabasic}}==
<langsyntaxhighlight Yabasiclang="yabasic">clear screen
open window 400, 150
backcolor 0, 0, 0
Line 3,536 ⟶ 4,998:
texto$ = right$(texto$, 1) + left$(texto$, l-1)
end if
loop</langsyntaxhighlight>
 
=={{header|ZX Spectrum Basic}}==
{{trans|BBC BASIC}}
Replaces the detection of mouse click by pressing a key (Spectrum does not detect this device by default).
<langsyntaxhighlight lang="zxbasic">10 LET t$="Hello world! ": LET lt=LEN t$
20 LET direction=1
30 PRINT AT 0,0;t$
Line 3,547 ⟶ 5,009:
50 LET t$=t$(lt)+t$( TO lt-1)
60 IF INKEY$<>"" THEN LET direction=NOT direction
70 PAUSE 5: GO TO 30</langsyntaxhighlight>
 
 
{{omit from|ACL2}}
Line 3,558 ⟶ 5,021:
{{omit from|PHP}}
{{omit from|SQL PL|It does not handle GUI}}
 
[[Category:Animation]]
9,476

edits