Animation: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(add task to aarch64 assembly raspberry pi)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(9 intermediate revisions by 6 users not shown)
Line 1:
{{task|Temporal media}}
[[Category:GUI]]
[[Category:Animation]]
{{task|Temporal media}}
{{requires|Graphics}}
 
Line 15 ⟶ 16:
=={{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">
<lang AArch64 Assembly>
/* Programme assembleur ARM Raspberry ou Android */
/* programme animletter64.s */
Line 546 ⟶ 547:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC DrawWindow(BYTE x,y,len)
BYTE i
 
Line 633 ⟶ 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 659 ⟶ 660:
//event handler to register clicks
textBox.addEventListener(MouseEvent.MOUSE_DOWN, function(){goingRight = !goingRight;});
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
Line 666 ⟶ 667:
 
animation.adb:
<langsyntaxhighlight Adalang="ada">with Gtk.Main;
with Gtk.Handlers;
with Gtk.Label;
Line 757 ⟶ 758:
Gtk.Window.Show_All (Widget => Main_Window);
Gtk.Main.Main;
end Animation;</langsyntaxhighlight>
 
=={{header|Applesoft BASIC}}==
<langsyntaxhighlight 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);
Line 766 ⟶ 767:
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)</langsyntaxhighlight>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI or android 32 bits with termux application */
/* program animLetter.s */
Line 1,413 ⟶ 1,414:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
</lang>
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">SetTimer, Animate ; Timer runs every 250 ms.
String := "Hello World "
Gui, Add, Text, vS gRev, %String%
Line 1,429 ⟶ 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 1,457 ⟶ 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 1,475 ⟶ 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 1,551 ⟶ 1,553:
gtk_main();
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Windows.Forms;
Line 1,610 ⟶ 1,612:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{libheader|Qt}}
Contents of animationwidget.cpp:
<langsyntaxhighlight lang="cpp">#include "animationwidget.h"
 
#include <QLabel>
Line 1,641 ⟶ 1,643:
void AnimationWidget::mousePressEvent(QMouseEvent*) {
right_ = !right_;
}</langsyntaxhighlight>
 
Contents of animationwidget.h:
<langsyntaxhighlight lang="cpp">#ifndef ANIMATIONWIDGET_H
#define ANIMATIONWIDGET_H
 
Line 1,659 ⟶ 1,661:
};
 
#endif // ANIMATIONWIDGET_H</langsyntaxhighlight>
 
Contents of main.cpp:
<langsyntaxhighlight lang="cpp">#include "animationwidget.h"
 
#include <QApplication>
Line 1,671 ⟶ 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 1,723 ⟶ 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 1,759 ⟶ 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 1,786 ⟶ 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 1,823 ⟶ 1,825:
(ltk:mainloop))))
(basic-animation)</langsyntaxhighlight>
 
=={{header|D}}==
Line 1,830 ⟶ 1,832:
{{libheader|SDL_ttf}}
{{libheader|tools}}
<langsyntaxhighlight lang="d">module test26;
 
import qd, SDL_ttf, tools.time;
Line 1,853 ⟶ 1,855:
) dir = !dir;
}
}</langsyntaxhighlight>
 
=={{header|Dart}}==
Line 1,859 ⟶ 1,861:
{{libheader|Flutter}}
view it on dartpad!
<langsyntaxhighlight lang="javascript">import 'package:flutter/material.dart';
import 'dart:async' show Timer;
 
Line 1,937 ⟶ 1,939:
}
</syntaxhighlight>
</lang>
 
 
===HTML DOM===
{{libheader|Html Dom}}
<langsyntaxhighlight lang="javascript">import 'dart:html';
import 'dart:async';
 
Line 1,968 ⟶ 1,970:
}
}
</syntaxhighlight>
</lang>
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
Line 1,977 ⟶ 1,979:
{{libheader| Vcl.StdCtrls}}
{{libheader| Vcl.ExtCtrls}}
<syntaxhighlight lang="delphi">
<lang Delphi>
unit Main;
 
Line 2,020 ⟶ 2,022:
Caption := Shift(Caption, Reverse);
end;
end.</langsyntaxhighlight>
Form resource:
<syntaxhighlight lang="delphi">
<lang Delphi>
object Form1: TForm1
ClientHeight = 132
Line 2,038 ⟶ 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 2,080 ⟶ 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 2,100 ⟶ 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 2,215 ⟶ 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 2,233 ⟶ 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 2,265 ⟶ 2,355:
[ sentence <model> <animated-label> "Rosetta" open-window ] with-ui ;
MAIN: main</langsyntaxhighlight>
 
=={{header|Fantom}}==
 
<langsyntaxhighlight lang="fantom">
using concurrent
using fwt
Line 2,345 ⟶ 2,435:
}
}
</syntaxhighlight>
</lang>
 
=={{header|FBSL}}==
 
<langsyntaxhighlight lang="qbasic">#INCLUDE <Include\Windows.inc>
 
FBSLSETTEXT(ME, "Hello world! ")
Line 2,378 ⟶ 2,468:
END IF
FBSLSETTEXT(ME, caption)
END SUB</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
Line 2,386 ⟶ 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 2,418 ⟶ 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 2,486 ⟶ 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 2,547 ⟶ 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 2,576 ⟶ 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 2,598 ⟶ 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 2,647 ⟶ 2,785:
w.show_modal ()
end
</syntaxhighlight>
</lang>
 
The following code uses features exclusive to Icon.
<syntaxhighlight lang="icon">
<lang Icon>
link graphics
 
Line 2,672 ⟶ 2,810:
}
end
</syntaxhighlight>
</lang>
 
=={{header|J}}==
{{works with|J8}}
<langsyntaxhighlight lang="j">coinsert'jgl2' [ require'gl2'
MESSAGE =: 'Hello World! '
Line 2,701 ⟶ 2,839:
)
anim_run ''</langsyntaxhighlight>
 
{{works with|J6}}
<langsyntaxhighlight lang="j">coinsert'jgl2' [ require'gl2'
 
MESSAGE =: 'Hello World! '
Line 2,729 ⟶ 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 2,793 ⟶ 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 2,819 ⟶ 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 2,844 ⟶ 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 2,884 ⟶ 3,022:
 
windowanim(frameinterval)
</syntaxhighlight>
</lang>
{{libheader|Julia/Gtk}}
<langsyntaxhighlight lang="julia">
using Gtk.ShortNames
Line 2,922 ⟶ 3,060:
 
textanimation(frameinterval)
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.0
 
import java.awt.Dimension
Line 2,980 ⟶ 3,118:
}
Timer(false).schedule(task, 0, 500)
}</langsyntaxhighlight>
 
=={{header|LabVIEW}}==
Line 2,987 ⟶ 3,125:
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb"> txt$ = "Hello World! "
txtLength = len(txt$)
direction=1
Line 3,020 ⟶ 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 3,043 ⟶ 3,181:
 
hideturtle
until [key?] [step.animation]</langsyntaxhighlight>
 
 
=={{header|Lua}}==
{{works with|LÖVE}}
<langsyntaxhighlight Lualang="lua">function love.load()
text = "Hello World! "
length = string.len(text)
Line 3,096 ⟶ 3,234:
function love.mousepressed( x, y, button, istouch, presses )
right_direction = not right_direction
end</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Line 3,102 ⟶ 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 3,130 ⟶ 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 3,151 ⟶ 3,289:
}
UseEvery
</syntaxhighlight>
</lang>
 
===Using Thread===
Line 3,158 ⟶ 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 3,182 ⟶ 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 3,213 ⟶ 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 3,225 ⟶ 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 3,278 ⟶ 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 3,357 ⟶ 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 3,419 ⟶ 3,584:
{Start}
end</langsyntaxhighlight>
 
=={{header|Pascal}}==
===LCL (Lazarus)===
<langsyntaxhighlight Pascallang="pascal">program HelloWorldAnimatedGUI;
 
uses {$IFDEF UNIX} {$IFDEF UseCThreads}
Line 3,499 ⟶ 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 3,530 ⟶ 3,695:
$mw->update();
}
}</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
Clicking on the label changes the animation direction.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
Line 3,572 ⟶ 3,737:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{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 3,590 ⟶ 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 3,597 ⟶ 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 3,614 ⟶ 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 3,639 ⟶ 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 3,667 ⟶ 3,832:
}
return String.valueOf(rotated);
}</langsyntaxhighlight>
 
==={{header|Processing Python mode}}===
Line 3,673 ⟶ 3,838:
When the user clicks on the (windowed) text, it should reverse its direction.
 
<langsyntaxhighlight lang="python">txt = "Hello, world! "
left = True
 
Line 3,694 ⟶ 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 3,772 ⟶ 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 3,804 ⟶ 3,969:
tick = ElapsedMilliseconds()
EndIf
ForEver</langsyntaxhighlight>
 
=={{header|Python}}==
===Using PyQt===
{{libheader|PyQt5}}
<langsyntaxhighlight lang="python">#!/usr/bin/env python3
import sys
 
Line 3,852 ⟶ 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 3,909 ⟶ 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 3,934 ⟶ 4,099:
tk.title('Python Animation')
tki.mainloop()
</syntaxhighlight>
</lang>
 
=={{header|Quick BASIC}}==
Line 3,945 ⟶ 4,110:
{{libheader|QB.QLB / QBX.QLB}}
 
<langsyntaxhighlight lang="qbasic">
'here accordingly to the version, QB or QBX
REM $INCLUDE: 'QBX.BI'
Line 3,988 ⟶ 4,153:
IF TIMER < I THEN I = I - 86400 'midnight checking
LOOP
LOOP</langsyntaxhighlight>
 
=={{header|R}}==
Line 3,994 ⟶ 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 4,034 ⟶ 4,199:
handle_rotate_label(lab)
handle_change_direction_on_click(lab)
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">
#lang racket/gui
 
Line 4,079 ⟶ 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.
<langsyntaxhighlight lang="racket">
#lang racket
(require racket/match)
Line 4,126 ⟶ 4,291:
[on-tick update]
[on-mouse handle-mouse])
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 4,132 ⟶ 4,297:
{{works with|Rakudo|2019.03}}
 
<syntaxhighlight lang="raku" perl6line>use GTK::Simple;
use GTK::Simple::App;
 
Line 4,148 ⟶ 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 4,193 ⟶ 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 4,224 ⟶ 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 4,268 ⟶ 4,433:
next
see nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,307 ⟶ 4,472:
{{trans|Tcl}}
{{libheader|Ruby/Tk}}
<langsyntaxhighlight lang="ruby">require 'tk'
$str = TkVariable.new("Hello World! ")
$dir = :right
Line 4,333 ⟶ 4,498:
animate
Tk.mainloop</langsyntaxhighlight>
 
{{libheader|Shoes}}
<langsyntaxhighlight lang="ruby">Shoes.app do
@direction = 1
@label = para "Hello World! ", :family => 'monospace'
Line 4,346 ⟶ 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 4,409 ⟶ 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 4,444 ⟶ 4,609:
case _ : MouseClicked => rotator ! Revert
}
}</langsyntaxhighlight>
 
=={{header|Scratch}}==
Line 4,456 ⟶ 4,621:
 
=={{header|smart BASIC}}==
<syntaxhighlight lang smart BASIC="basic">'Animation, by rbytes and Dutchman
word$="Hello World! "
'use button window with text
Line 4,472 ⟶ 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 4,534 ⟶ 4,699:
)
end;</langsyntaxhighlight>
 
call
Line 4,540 ⟶ 4,705:
 
=={{header|Suneido}}==
<langsyntaxhighlight Suneidolang="suneido">Window(Controller
{
Xmin: 50
Line 4,575 ⟶ 4,740:
super.Destroy()
}
})</langsyntaxhighlight>
 
=={{header|SVG}}==
Line 4,583 ⟶ 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 4,599 ⟶ 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 4,605 ⟶ 4,770:
=={{header|Tcl}}==
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tk
set s "Hello World! "
set dir 0
Line 4,624 ⟶ 4,789:
bind .l <Button-1> {set dir [expr {!$dir}]}
# Start the animation
animate</langsyntaxhighlight>
 
=={{header|TI-89 BASIC}}==
Line 4,689 ⟶ 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 4,703 ⟶ 4,868:
Update()
Sleep(2)
}</langsyntaxhighlight>
 
=={{header|Visual Basic}}==
Line 4,709 ⟶ 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 4,739 ⟶ 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 4,784 ⟶ 4,949:
}
 
var Game = Animation.new()</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes;
int CpuReg, Dir, I, J;
char Str;
Line 4,809 ⟶ 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 4,833 ⟶ 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 4,844 ⟶ 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 4,855 ⟶ 5,021:
{{omit from|PHP}}
{{omit from|SQL PL|It does not handle GUI}}
 
[[Category:Animation]]
9,479

edits