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:
[[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">
/* 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>
=={{header|Action!}}==
<
BYTE i
Line 633 ⟶ 634:
CRSINH=0 ;show cursor
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Animation.png Screenshot from Atari 8-bit computer]
=={{header|ActionScript}}==
<
var textBox:TextField = new TextField();
addChild(textBox);
Line 659 ⟶ 660:
//event handler to register clicks
textBox.addEventListener(MouseEvent.MOUSE_DOWN, function(){goingRight = !goingRight;});
</syntaxhighlight>
=={{header|Ada}}==
Line 666 ⟶ 667:
animation.adb:
<
with Gtk.Handlers;
with Gtk.Label;
Line 757 ⟶ 758:
Gtk.Window.Show_All (Widget => Main_Window);
Gtk.Main.Main;
end Animation;</
=={{header|Applesoft BASIC}}==
<
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)</
=={{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 */
Line 1,413 ⟶ 1,414:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
=={{header|AutoHotkey}}==
<
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</
=={{header|
<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</
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<
txt$ = "Hello World! "
direction% = TRUE
Line 1,475 ⟶ 1,477:
ENDIF
WAIT 20
UNTIL FALSE</
=={{header|C}}==
{{libheader|GTK}}
(NB: implicitly, through GTK, it uses also Pango library)
<
#include <string.h>
#include <gtk/gtk.h>
Line 1,551 ⟶ 1,553:
gtk_main();
return 0;
}</
=={{header|C sharp|C#}}==
<
using System.Drawing;
using System.Windows.Forms;
Line 1,610 ⟶ 1,612:
}
}
}</
=={{header|C++}}==
{{libheader|Qt}}
Contents of animationwidget.cpp:
<
#include <QLabel>
Line 1,641 ⟶ 1,643:
void AnimationWidget::mousePressEvent(QMouseEvent*) {
right_ = !right_;
}</
Contents of animationwidget.h:
<
#define ANIMATIONWIDGET_H
Line 1,659 ⟶ 1,661:
};
#endif // ANIMATIONWIDGET_H</
Contents of main.cpp:
<
#include <QApplication>
Line 1,671 ⟶ 1,673:
w.show();
return a.exec();
}</
=={{header|Ceylon}}==
module.ceylon
<
module animation "1.0.0" {
import java.desktop "8";
}
</syntaxhighlight>
run.ceylon
<
JFrame,
JLabel,
Line 1,723 ⟶ 1,725:
frame.pack();
frame.visible = true;
}</
=={{header|Clojure}}==
Clojure is a JVM language so this example uses Swing, and illustrates Clojure's platform integration.
<
(import '[java.awt.event MouseAdapter])
Line 1,759 ⟶ 1,761:
(.setVisible true))
(future-call animator) ;simple way to run animator on a separate thread</
=={{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".
<
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>
=={{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}}
<
(defparameter *message* "Hello World! ")
Line 1,823 ⟶ 1,825:
(ltk:mainloop))))
(basic-animation)</
=={{header|D}}==
Line 1,830 ⟶ 1,832:
{{libheader|SDL_ttf}}
{{libheader|tools}}
<
import qd, SDL_ttf, tools.time;
Line 1,853 ⟶ 1,855:
) dir = !dir;
}
}</
=={{header|Dart}}==
Line 1,859 ⟶ 1,861:
{{libheader|Flutter}}
view it on dartpad!
<
import 'dart:async' show Timer;
Line 1,937 ⟶ 1,939:
}
</syntaxhighlight>
===HTML DOM===
{{libheader|Html Dom}}
<
import 'dart:async';
Line 1,968 ⟶ 1,970:
}
}
</syntaxhighlight>
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
Line 1,977 ⟶ 1,979:
{{libheader| Vcl.StdCtrls}}
{{libheader| Vcl.ExtCtrls}}
<syntaxhighlight lang="delphi">
unit Main;
Line 2,020 ⟶ 2,022:
Caption := Shift(Caption, Reverse);
end;
end.</
Form resource:
<syntaxhighlight lang="delphi">
object Form1: TForm1
ClientHeight = 132
Line 2,038 ⟶ 2,040:
end
end
</syntaxhighlight>
=={{header|E}}==
{{works with|E-on-Java}} (Java Swing; tested on Mac OS X 10.5.7)
<
var text := "Hello World! "
var leftward := false
Line 2,080 ⟶ 2,082:
# Start everything
w.show()
anim.start()</
Text-only version (no Java dependency; no clicking, use reverse() and stop() to control):
<
var text := "Hello World! "
var leftward := false
Line 2,100 ⟶ 2,102:
anim.start()
[def _() { leftward := !leftward; null }, anim.stop]
}</
=={{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}}==
<
import Browser
Line 2,215 ⟶ 2,247:
[ text <| rotate message model.time ]
]
</syntaxhighlight>
=={{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}}
<
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</
=={{header|Factor}}==
<
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</
=={{header|Fantom}}==
<
using concurrent
using fwt
Line 2,345 ⟶ 2,435:
}
}
</syntaxhighlight>
=={{header|FBSL}}==
<
FBSLSETTEXT(ME, "Hello world! ")
Line 2,378 ⟶ 2,468:
END IF
FBSLSETTEXT(ME, caption)
END SUB</
=={{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.)
<
DIM DIRECTION AS BYTE = 0
DIM AS INTEGER X, Y, BTNS
Line 2,418 ⟶ 2,508:
SLEEP 100, 1
LOOP</
=={{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}}==
<
hLabel As Label 'Label needed to display the 'Hello World! " message
Line 2,486 ⟶ 2,624:
hLabel.text = sString 'Display the result
End</
'''[http://www.cogier.com/gambas/Animation.png Click here for image of running code]'''
=={{header|Go}}==
<
import (
Line 2,547 ⟶ 2,685:
}
}
}</
=={{header|Haskell}}==
Using simple graphics {{libheader|HGL}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
<
import Graphics.HGL.Draw.Monad (Graphic, )
import Graphics.HGL.Draw.Text
Line 2,576 ⟶ 2,714:
loop t' d
loop "Hello world ! " 1 )</
Run within interpreter GHCi:
<syntaxhighlight lang
=={{header|HicEst}}==
<
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 </
=={{header|Icon}} and {{header|Unicon}}==
The following code uses features exclusive to Unicon.
<
$include "guih.icn"
Line 2,647 ⟶ 2,785:
w.show_modal ()
end
</syntaxhighlight>
The following code uses features exclusive to Icon.
<syntaxhighlight lang="icon">
link graphics
Line 2,672 ⟶ 2,810:
}
end
</syntaxhighlight>
=={{header|J}}==
{{works with|J8}}
<
MESSAGE =: 'Hello World! '
Line 2,701 ⟶ 2,839:
)
anim_run ''</
{{works with|J6}}
<
MESSAGE =: 'Hello World! '
Line 2,729 ⟶ 2,867:
)
anim_run ''</
=={{header|Java}}==
{{libheader|Swing}}
<
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
Line 2,793 ⟶ 2,931:
return String.valueOf(rotated);
}
}</
=={{header|JavaScript}} + {{header|HTML}}==
<
<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></
=={{header|JavaScript}} + {{header|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></
=={{header|Julia}}==
{{libheader|Julia/Tk}}
<syntaxhighlight lang="julia">
using Tk
Line 2,884 ⟶ 3,022:
windowanim(frameinterval)
</syntaxhighlight>
{{libheader|Julia/Gtk}}
<
using Gtk.ShortNames
Line 2,922 ⟶ 3,060:
textanimation(frameinterval)
</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|Java}}
<
import java.awt.Dimension
Line 2,980 ⟶ 3,118:
}
Timer(false).schedule(task, 0, 500)
}</
=={{header|LabVIEW}}==
Line 2,987 ⟶ 3,125:
=={{header|Liberty BASIC}}==
<
txtLength = len(txt$)
direction=1
Line 3,020 ⟶ 3,158:
timer 0
close #demo
end</
=={{header|Logo}}==
{{works with|UCB Logo}}
<
output lput first :thing butfirst :thing
end
Line 3,043 ⟶ 3,181:
hideturtle
until [key?] [step.animation]</
=={{header|Lua}}==
{{works with|LÖVE}}
<
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</
=={{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">
Module UseBlink {
Def boolean direction=True
Line 3,130 ⟶ 3,268:
UseBlink
</syntaxhighlight>
===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">
Module UseEvery {
Window 16, 6000,4000;
Line 3,151 ⟶ 3,289:
}
UseEvery
</syntaxhighlight>
===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">
Module UseThread {
Def boolean direction=True
Line 3,182 ⟶ 3,320:
}
UseThread
</syntaxhighlight>
=={{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">
ScrollText(GP("Text",value),"Forward",65);
</
and:
<syntaxhighlight lang="maple">
ScrollText(GP("Text",value),"Reverse",65);
</syntaxhighlight>
Then in the startup actions, accessed by clicking the 2 gears, add this:
<syntaxhighlight lang="maple">
macro(SP=DocumentTools:-SetProperty, GP=DocumentTools:-GetProperty);
SP("Text",value,"Hello World! ");
Line 3,213 ⟶ 3,351:
end do:
end proc:
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
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)}]]
}];</
=={{header|MAXScript}}==
Creates a window with a rotating label and 2 buttons to change the direction.
<syntaxhighlight lang="maxscript">
try destroydialog animGUI catch ()
Line 3,278 ⟶ 3,416:
createdialog animGUI
</syntaxhighlight>
=={{header|MiniScript}}==
{{works with|Mini Micro}}
<syntaxhighlight lang="miniscript">clear
s = "Hello World! "
toggle = true
while true
text.row = 12
text.column = 15
print " " + s + " "
wait 0.1
if key.available then
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>
=={{header|Nim}}==
{{libheader|gintro}}
<
type
Line 3,357 ⟶ 3,522:
let app = newApplication(Application, "Rosetta.animation")
discard app.connect("activate", activate)
discard app.run()</
=={{header|Oz}}==
<
import
Application
Line 3,419 ⟶ 3,584:
{Start}
end</
=={{header|Pascal}}==
===LCL (Lazarus)===
<
uses {$IFDEF UNIX} {$IFDEF UseCThreads}
Line 3,499 ⟶ 3,664:
Application.CreateForm(TFrmHelloWorldAnim, FrmHelloWorldAnim);
Application.Run;
end.</
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}}==
<
use Time::HiRes qw(sleep);
Line 3,530 ⟶ 3,695:
$mw->update();
}
}</
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
Clicking on the label changes the animation direction.
<!--<
<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>
<!--</
=={{header|PicoLisp}}==
===Plain text===
A plain text version. The following script works in an XTerm window.
<
(prin "^[[?9h") # Mouse reporting on
Line 3,590 ⟶ 3,755:
(setq Dir (if (= 1 Dir) 12 1)) )
(key) (key) )
(do (length Text) (prin "^H")) )</
===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.
<
(load "@ext.l" "@lib/http.l" "@lib/xhtml.l" "@lib/form.l")
Line 3,614 ⟶ 3,779:
(server 8080 "!start")
(wait)</
===Java/Swing===
This solution works on ErsatzLisp, the Java version of PicoLisp.
<
(setq
Line 3,639 ⟶ 3,804:
(loop
(wait 200)
(java Label 'setText (pack (do Dir (rot Text)))) )</
=={{header|Processing}}==
<
boolean dir = true;
Line 3,667 ⟶ 3,832:
}
return String.valueOf(rotated);
}</
==={{header|Processing Python mode}}===
Line 3,673 ⟶ 3,838:
When the user clicks on the (windowed) text, it should reverse its direction.
<
left = True
Line 3,694 ⟶ 3,859:
rotated = text[startIdx:] + text[:startIdx]
return rotated
</syntaxhighlight>
=={{header|Prolog}}==
SWI-Prolog has a grapghic interface XPCE.
<
animation :-
Line 3,772 ⟶ 3,937:
get(S, delete_prefix, Str, V),
get(V, append, Str, S1).
</syntaxhighlight>
=={{header|PureBasic}}==
<
text$ = "Hello World! "
Line 3,804 ⟶ 3,969:
tick = ElapsedMilliseconds()
EndIf
ForEver</
=={{header|Python}}==
===Using PyQt===
{{libheader|PyQt5}}
<
import sys
Line 3,852 ⟶ 4,017:
- w.rect().center())
w.show()
sys.exit(app.exec())</
===Using pygame===
{{libheader|pygame}}
<
from pygame.locals import *
pygame.init()
Line 3,909 ⟶ 4,074:
while True:
input(pygame.event.wait())
pygame.display.flip()</
===Using Tkinter===
<
def scroll_text(s, how_many):
Line 3,934 ⟶ 4,099:
tk.title('Python Animation')
tki.mainloop()
</syntaxhighlight>
=={{header|Quick BASIC}}==
Line 3,945 ⟶ 4,110:
{{libheader|QB.QLB / QBX.QLB}}
<
'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</
=={{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">
rotate_string <- function(x, forwards)
{
Line 4,034 ⟶ 4,199:
handle_rotate_label(lab)
handle_change_direction_on_click(lab)
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket/gui
Line 4,079 ⟶ 4,244:
(send frame show #t)
</syntaxhighlight>
This is a more functional approach - there is no explicit mutation, everything is handled through event callbacks.
<
#lang racket
(require racket/match)
Line 4,126 ⟶ 4,291:
[on-tick update]
[on-mouse handle-mouse])
</syntaxhighlight>
=={{header|Raku}}==
Line 4,132 ⟶ 4,297:
{{works with|Rakudo|2019.03}}
<syntaxhighlight lang="raku"
use GTK::Simple::App;
Line 4,148 ⟶ 4,313:
$app.set-content($vbox);
$app.run;</
=={{header|REBOL}}==
<
Title: "Basic Animation"
URL: http://rosettacode.org/wiki/Basic_Animation
Line 4,193 ⟶ 4,358:
]
]
]</
=={{header|Red}}==
<
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]]</
=={{header|REXX}}==
This REXX version <u>only</u> works with REXX/Personal or REXX/PC.
<
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. */</
=={{header|Ring}}==
<
# Project : Animation
Line 4,268 ⟶ 4,433:
next
see nl
</syntaxhighlight>
Output:
<pre>
Line 4,307 ⟶ 4,472:
{{trans|Tcl}}
{{libheader|Ruby/Tk}}
<
$str = TkVariable.new("Hello World! ")
$dir = :right
Line 4,333 ⟶ 4,498:
animate
Tk.mainloop</
{{libheader|Shoes}}
<
@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</
=={{header|Rust}}==
==={{libheader|GTK}}===
<
mod graphical {
extern crate gtk;
Line 4,409 ⟶ 4,574:
#[cfg(not(feature = "gtk"))]
fn main() {}</
=={{header|Scala}}==
{{works with|Scala|2.8}}
<
import scala.actors.TIMEOUT
import scala.swing.{SimpleSwingApplication, MainFrame, Label}
Line 4,444 ⟶ 4,609:
case _ : MouseClicked => rotator ! Revert
}
}</
=={{header|Scratch}}==
Line 4,456 ⟶ 4,621:
=={{header|smart BASIC}}==
<syntaxhighlight lang
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</
This program can be concatenated onto a single line using ! as the concatenator:
<
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</
Mr. Kibernetik, the creator of smart Basic, offered this ultra-compact one-line version:
<
and smart Basic Forum member sarossell found a way to shorten even that! See if you can spot what is changed.
<
=={{header|Standard ML}}==
Works with PolyML interpreter. Add loop for compilation.
<
open Motif ;
Line 4,534 ⟶ 4,699:
)
end;</
call
Line 4,540 ⟶ 4,705:
=={{header|Suneido}}==
<
{
Xmin: 50
Line 4,575 ⟶ 4,740:
super.Destroy()
}
})</
=={{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.
<
<g id="all">
<rect width="100%" height="100%" fill="yellow"/>
Line 4,599 ⟶ 4,764:
</g>
</g>
</svg></
(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}}
<
set s "Hello World! "
set dir 0
Line 4,624 ⟶ 4,789:
bind .l <Button-1> {set dir [expr {!$dir}]}
# Start the animation
animate</
=={{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.
<
Win_Create(Buf_Num, 1, 1, 2, 14)
Ins_Text("Hello World! ")
Line 4,703 ⟶ 4,868:
Update()
Sleep(2)
}</
=={{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.)
<
Begin VB.Form Form1
Begin VB.Timer Timer1
Line 4,739 ⟶ 4,904:
End If
Label1.Caption = x
End Sub</
=={{header|Wren}}==
{{libheader|DOME}}
<
import "dome" for Window
import "input" for Mouse
Line 4,784 ⟶ 4,949:
}
var Game = Animation.new()</
=={{header|XPL0}}==
<
int CpuReg, Dir, I, J;
char Str;
Line 4,809 ⟶ 4,974:
if CpuReg(1) then Dir:= -Dir;
until KeyHit; \any keystroke terminates program
]</
=={{header|Yabasic}}==
<
open window 400, 150
backcolor 0, 0, 0
Line 4,833 ⟶ 4,998:
texto$ = right$(texto$, 1) + left$(texto$, l-1)
end if
loop</
=={{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).
<
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</
{{omit from|ACL2}}
Line 4,855 ⟶ 5,021:
{{omit from|PHP}}
{{omit from|SQL PL|It does not handle GUI}}
|