Animation: Difference between revisions
Content added Content deleted
m (→{{header|Processing Python mode}}: make subhead of Processing) |
(→{{header|Suneido}}: + Standard ML) |
||
Line 2,762: | Line 2,762: | ||
<Lang smart 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</Lang> |
<Lang smart 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</Lang> |
||
=={{header|Standard ML}}== |
|||
Works with PolyML. |
|||
<lang Standard ML>open XWindows ; |
|||
open Motif ; |
|||
structure TTd = Thread.Thread ; |
|||
structure TTm = Thread.Mutex ; |
|||
val bannerWindow = fn () => |
|||
let |
|||
datatype thron = nothr | thr of TTd.thread ; |
|||
val toThr = fn thr x=> x; |
|||
val on = ref nothr ; |
|||
val mx = TTm.mutex (); |
|||
val dim = {tw=77,th=14} ; |
|||
val shell = XtAppInitialise "" "click text to start or redirect" "top" [] [ XmNwidth 320, XmNheight 60 ] ; |
|||
val main = XmCreateMainWindow shell "main" [ XmNmappedWhenManaged true ] ; |
|||
val canvas = XmCreateDrawingArea main "drawarea" [ XmNwidth (#tw dim), XmNheight (#th dim)] ; |
|||
val usegc = DefaultGC (XtDisplay canvas) ; |
|||
val buf = XCreatePixmap (RootWindow (XtDisplay shell)) (Area{x=0,y=0,w = #tw dim, h= (#th dim) }) 24 ; |
|||
val _ = (XSetBackground usegc 0xfffffff ; |
|||
XDrawImageString buf usegc (XPoint {x=0,y= (#th dim)-1 } ) "Hello World! ") ; |
|||
val drawparts = fn pos => ( |
|||
XCopyArea buf (XtWindow canvas) usegc ( XPoint {x=pos,y=0} ) (Area{x=0,y=0,w = (#tw dim) - pos , h= #th dim }) ; |
|||
XCopyArea buf (XtWindow canvas) usegc ( XPoint {x=00,y=0} ) (Area{x= (#tw dim) - pos ,y=0,w = pos, h= #th dim }) ; |
|||
XFlush (XtDisplay canvas) ) ; |
|||
val direct = ref (1,1) (* couple needed due to makeshift use of inputCallback *) |
|||
fun shift s = (drawparts ( s mod (#tw dim)); |
|||
Posix.Process.sleep (Time.fromReal 0.1) ; |
|||
shift ( s + 1 * (#1 (!direct))) ) ; |
|||
val swdir = fn (w,s,t) => |
|||
(TTd.fork( fn () => |
|||
(TTm.lock mx; |
|||
direct := (if (#2 (!direct))* (#1 (!direct)) > 0 |
|||
then ( ~1 * (#1 (!direct)),#2 (!direct)) |
|||
else (#1 (!direct),~1 * (#2 (!direct))) ); |
|||
TTm.unlock mx; |
|||
TTd.exit ()), [] ) ; |
|||
t ) |
|||
val finish = fn (w,s,t) => |
|||
( if !on <> nothr then if TTd.isActive (toThr (!on)) then TTd.kill (toThr (!on)) else () else () ; |
|||
on := nothr ; |
|||
t) ; |
|||
val movimg = fn (w,s,t) => |
|||
( finish (w,s,t) ; swdir (w,s,t) ; |
|||
on := thr (TTd.fork (fn () => shift 0,[]) ) ; t ) ; |
|||
val setimg = fn (w,s,t) => |
|||
( finish (w,s,t); drawparts 0 ; t ) |
|||
in |
|||
( |
|||
XtSetCallbacks canvas [ (XmNexposeCallback , setimg) ,(XmNinputCallback , movimg) , (XmNdestroyCallback, finish) ] XmNarmCallback ; |
|||
XtManageChild canvas ; |
|||
XtManageChild main ; |
|||
XtRealizeWidget shell |
|||
) |
|||
end;</lang> |
|||
call |
|||
bannerWindow () ; |
|||
=={{header|Suneido}}== |
=={{header|Suneido}}== |
||
<lang Suneido>Window(Controller |
<lang Suneido>Window(Controller |