import Graphics.Glossmain ::IO ()
main = animate (InWindow"Expandiendo un circulo" (500,500) (20,20)) green animacion
animacion ::Float->Picture
animacion t = circle (20* t)
Comentarios
La variable t toma como valor el tiempo transcurrido.
import Graphics.Glossmain ::IO ()
main = animate (InWindow"Zen" (800,500) (5,5)) (greyN 0.2) frame
-- Produce one frame of the animation.frame ::Float->Picture
frame timeS =Pictures-- the red rectangles
[ Translate0150 backRec
, Translate00 backRec
, Translate0 (-150) backRec
-- the tree
, Translate0 (-150) $ treeFrac 7 timeS ]
-- One of the red backing rectangles, with a white outline.backRec ::Picture
backRec =Pictures
[ Color red (rectangleSolid 400100)
, Color white (rectangleWire 400100) ]
-- The color for the outline of the tree's branches.treeOutline ::Color
treeOutline = makeColor 0.30.31.01.0-- The color for the shading of the tree's branches.-- The Alpha here is set to 0.5 so the branches are partly transparent.treeColor ::Color
treeColor = makeColor 0.01.00.00.5-- The tree fractal.-- The position of the branches changes depending on the animation time-- as well as the iteration number of the fractal.treeFrac ::Int->Float->Picture
treeFrac 0 timeS =Blank
treeFrac n timeS =Pictures
[ Color treeColor $ rectangleUpperSolid 20300
, Color treeOutline $ rectangleUpperWire 20300
, Translate030$Rotate (200* sin timeS / (fromIntegral n) )
$Scale0.90.9$ treeFrac (n-1) timeS
, Translate070$Rotate (-200* sin timeS / (fromIntegral n))
$Scale0.80.8$ treeFrac (n-1) timeS ]
import Graphics.Gloss
main
= animate (InWindow"Clock" (500, 500) (20, 20))
black frame
-- Build the fractal, scale it so it fits in the window-- and rotate the whole thing as time moves on.frame ::Float->Picture
frame time =Color white
$Scale110110$Rotate (time *2*pi)
$ clockFractal 5 time
-- The basic fractal consists of three circles offset from the origin-- as follows.---- 1-- |-- .-- / \-- 2 3---- The direction of rotation switches as n increases.-- Components at higher iterations also spin faster.--clockFractal ::Int->Float->Picture
clockFractal 0 s =Blank
clockFractal n s =Pictures [circ1, circ2, circ3, lines]
where-- y offset from origin to center of circle 1.
a =1/ sin (2* pi /6)
-- x offset from origin to center of circles 2 and 3.
b = a * cos (2* pi /6)
nf = fromIntegral n
rot =if n `mod`2==0then50* s * (log (1+ nf))
else (-50* s * (log (1+ nf)))
-- each element contains a copy of the (n-1) iteration contained-- within a larger circle, and some text showing the time since -- the animation started.--
circNm1
=Pictures
[ circle 1
, Scale (a/2.5) (a/2.5) $ clockFractal (n-1) s
, if n >2thenColor cyan
$Translate (-0.15) 1$Scale0.0010.001$Text (show s)
elseBlank
]
circ1 =Translate0 a $Rotate rot circNm1
circ2 =Translate1 (-b) $Rotate (-rot) circNm1
circ3 =Translate (-1) (-b) $Rotate rot circNm1
-- join each iteration to the origin with some lines.
lines
=Pictures
[ Line [(0, 0), ( 0, a)]
, Line [(0, 0), ( 1, -b)]
, Line [(0, 0), (-1, -b)] ]