fillTriangle function

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
flattspott
Posts: 22
Joined: Mon Aug 22, 2005 4:06 am

fillTriangle function

Post by flattspott »

Code: Select all

function fillTriangle(size,color,direction)
	direction = direction or 1
	local shape = Image.createEmpty(size, size)
	distance = (size/2)
	if direction == 1 then
		for i = 0,distance do shape:drawLine(distance-i, i, distance+i, i, color) end -- up
	elseif direction == 2 then
		for i = 0,distance do shape:drawLine(i, i, size-i, i, color) end -- down
	elseif direction == 3 then
		for i = 0,distance do shape:drawLine(size-i, i, size-i, size-i, color) end -- left
	elseif direction == 4 then
		for i = 0,distance do shape:drawLine(i, size-i, i, i, color) end -- right
	end
  	return shape
end

--EXAMPLE USAGE
while not Controls.read():start() do
	screen:blit(110, 50, fillTriangle(128,Color.new(25, 100, 220),1))
	screen.waitVblankStart()
	screen.flip()
end
Image

Another offering from me.[/img]
Zenurb
Posts: 106
Joined: Fri Sep 30, 2005 8:33 am
Location: United Kingdom
Contact:

Post by Zenurb »

probably a bit slow? I don't see this working at 60fps.
Proud Dvorak User
US 1.5 PSP (Original)
Post Reply