
Animation is integral to many parts of GUIs, including both the fancy effects when things change used in window managers, and of course games.   The core of any animation system is a scheme for periodically changing the display while still remaining responsive to the user.   This task demonstrates this.



Task

Create a window containing the string "Hello World! " (the trailing space is significant).

Make the text appear to be rotating right by periodically removing one letter from the end of the string and attaching it to the front.

When the user clicks on the (windowed) text, it should reverse its direction.




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