Log In  


Hello,

Is there a way to rotate text, or write text at an angle?

Thanks !



Rotating the pixels of the letters would have a poor result at this resolution. You could print the letters one at a time along a line with something like this:

function print_angle(s, x, y, c, a)
 for i=1,#s do
  print(sub(s,i,i), x, y, c)
  x += cos(a) * 4
  y += sin(a) * 6
 end
end

function _init()
 angle = 0
end
function _update()
 angle += 0.01
 if (angle > 1) angle = 0
end
function _draw()
 cls()
 print_angle('rotate', 62, 61, 7, angle)
end

Here's a forum discussion on sprite rotation that illustrates the limitations of rotating a small image. https://www.lexaloffle.com/bbs/?tid=2189 I tried printing a string to the screen then using memcpy to transfer it to the spritesheet for use with these rotation routines, but I couldn't get it working before I lost interest. I don't see why it wouldn't work in theory, other than being illegible. :)


I wrote the following functions for a game I'm making. It allows you to copy any portion of the screen and flip it horizontally or vertically, but not rotate. It works on anything on the screen, including text.

Example:

cpy = copy_screen(x+3,y+3,3,25)
paste_screen(cpy, x+18,y+4, false, true)

--or

paste_screen(copy_screen(x+3,y+3,3,25), x+18,y+4, false, true)
function paste_screen(screen,x,y,flip_x,flip_y)
	if flip_x then
		ax = #screen
	else
		ax = 1
	end

	for sx = 1, #screen do
		if flip_y then
			ay = #screen[1]
		else
			ay = 1
		end
		for sy = 1, #screen[sx] do
			rect(x+sx-1,y+sy-1,x+sx-1,y+sy-1,screen[ax][ay])
			if flip_y then
				ay -= 1
			else
				ay += 1
			end
		end
		if flip_x then
			ax -= 1
		else
			ax += 1
		end
	end
end

function copy_screen(x,y,width,height)
	local screen = {}

	for sx = x,x+width-1 do
		screen[sx-x+1] = {}
		for sy = y,y+height-1 do
			screen[sx-x+1][sy-y+1] = pget(sx,sy)
		end
	end
	return screen
end

Thanks a lot !

Indeed the rotating of text would destroy the text, but rotating zoomed text might be OK.

Anyways, it is very interesting code to get me started.

thanks !!



[Please log in to post a comment]