UFA's here! (User-Free Applications)

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

Moderators: Shine, Insert_witty_name

Post Reply
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

UFA's here! (User-Free Applications)

Post by Kameku »

You know you've made them... random text creator, pixel mover... it's just fun! Well, if you're proud of any of your UFA's, go ahead and link us to them, and if you can, provide a screenshot so we're not downloading the same thing we just made! XD

Here's mine -
[Coral Draw - download]
Image
Description -
Draws in random directions from random beginning with only limits to the screen size. Includes timer, and automatically screenshots every minute. Might wanna get a file manager, since after 30 minutes, the pictures take up more than a megabyte. [EDIT] Screenshot was taken when it was in "beta," now has a battery bar, and a display of seconds/minutes/hours passed since the program began.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: UFA's here! (User-Free Applications)

Post by Shine »

You might be interested in my cellular automata: http://www.frank-buss.de/automaton/ especially Arabasek, Game Of Life and the tetracaidecahedron idea. Should be really easy to convert it to Lua.

Another fascinating concept is Langtons Ant: http://www.frank-buss.de/tmp/ameise.html
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

Post by Kameku »

Yes, I have heard of Game of Life from someone in the chat. And as for Langton's Ant, I'll take a look into it.
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

Post by Kameku »

After going through some specifications, I have finally made a good Langton's Ant program! :)

Langton's Ant
[Download Here]
Image
Description - Ant begins at a random place on the screen. If the square it is on is black, it turns right, moves forward, and makes the square he was on white. It is the opposite with a white square. After about 10000 iterations, the ant will begin to make what is called a "highway," which is a pattern in which he makes a path in a up-right, down-right, up-left, or down-left direction. Each segment of the path takes 104 iterations.

Controls:
Triangle - Screenshot
Select - Inverts colors
R + L - Clears screen (only to black)
Start - Exits

Note: I will be taking suggestions, such as incrementing screenshots, etc. Also, if you want to optimize my code, please do, I haven't really had the time.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Kameku wrote:After going through some specifications, I have finally made a good Langton's Ant program! :)

Langton's Ant
Nice. What about more than one ant?

Image

Code: Select all

function even(num)
	return num - math.mod(num, 2)
end

math.randomseed(os.time())

black = Color.new(0,0,0)
white = Color.new(255,255,255)
blue = Color.new(0,0,255)
red = Color.new(255,0,0)
green = Color.new(0,255,0)

ants = {}
colors = { red, green, blue }
for i = 1, 3 do
	ants[i] = {
		x = even((math.random(480) + 240) / 2),
		y = even((math.random(272) + 136)) / 2,
		dir = 0,
		color = colors[i]
	}
end
		
canvas = Image.createEmpty(482, 274)
canvas:clear(black)
iter = 1
screenNumber = 0

function shadow(x, y, text, c1, c2)
	screen:print(x - 1, y, text, c2)
	screen:print(x, y - 1, text, c2)
	screen:print(x + 1, y, text, c2)
	screen:print(x + 1, y + 1, text, c2)
	screen:print(x + 1, y - 1, text, c2)
	screen:print(x + 2, y, text, c2)
	screen:print(x, y + 1, text, c2)
	screen:print(x, y, text, c1)
	screen:print(x + 1, y, text, c1)
end

while true do
	pad = Controls.read()
	if pad:start() then break end
	if pad:triangle() then
		screen:blit(-1, -1, canvas)
		screen.flip()
		screen:save("screenshot.png")
	end
	if pad:r() and pad:l() then
		canvas:clear(black)
		iter = 1
	end
	
	oldpad = pad

	for i = 1, 3 do
		ant = ants[i]	
		if canvas:pixel(ant.x,ant.y) == black then
			ant.dir = ant.dir + 1
			if ant.dir == 4 then ant.dir = 0 end
		else
			ant.dir = ant.dir - 1
			if ant.dir == -1 then ant.dir = 3 end
		end
		
		ant.oldx = ant.x
		ant.oldy = ant.y
		
		if ant.dir == 0 then ant.x = ant.x + 2 end
		if ant.dir == 2 then ant.x = ant.x - 2 end
		if ant.dir == 1 then ant.y = ant.y + 2 end
		if ant.dir == 3 then ant.y = ant.y - 2 end
		
		if ant.x > 480 then ant.x = 0 end
		if ant.x < 0 then ant.x = 480 end
		if ant.y > 272 then ant.y = 0 end
		if ant.y < 0 then ant.y = 272 end
		
		if canvas&#58;pixel&#40;ant.oldx, ant.oldy&#41; == black and
		   canvas&#58;pixel&#40;ant.oldx + 1, ant.oldy&#41; == black and
		   canvas&#58;pixel&#40;ant.oldx, ant.oldy + 1&#41; == black and
		   canvas&#58;pixel&#40;ant.oldx + 1, ant.oldy + 1&#41; == black then
		   	canvas&#58;fillRect&#40;ant.oldx, ant.oldy, 2, 2, ant.color&#41;
		else
			canvas&#58;fillRect&#40;ant.oldx, ant.oldy, 2, 2, black&#41;
		end
	end
	
	screen&#58;clear&#40;&#41;
	screen&#58;blit&#40;-1, -1, canvas&#41;

	for i = 1, 3 do
		ant = ants&#91;i&#93;	
		screen&#58;fillRect&#40;ant.x-1, ant.y-1, 3, 3, white&#41;
	end
	shadow&#40;2, 262, "Step&#58; " .. iter, black, white&#41;
	screen.flip&#40;&#41;
	--screen.waitVblankStart&#40;&#41;
	iter = iter + 1
	
--	if math.mod&#40;iter, 200&#41; == 0 then
--		screen&#58;save&#40;"screenshot" .. screenNumber .. ".png"&#41;
--		screenNumber = screenNumber + 1
--	end
end
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

Post by Kameku »

Dangit, why didn't I have that idea? XD

Guess I'll work on a new cellular automaton, since Game of Life is really flashy. And because I wanna be smart! :D
RanDom_ErrOr
Posts: 13
Joined: Sat Apr 15, 2006 11:19 am

Post by RanDom_ErrOr »

buwahaha my first LUA project... yes i ganked some code for screenshots, iteration count, and that nice little shadow function...

luckily i cleaned it up alot, and reduced the size to nothing, i intend to add functionality to dynamically change the number of "organisms" with up/down arrow functionality... we'll see...

Code: Select all

-- Demonstration No-User-App
-- Author&#58; RanDom_ErrOr
-- Copyright 2006
-- No liscense with this product what so ever. Use at your own risk. I will accept no liability or responsibility if you **** something up.
System.usbDiskModeActivate&#40;&#41;
screenwidth = 480
screenheight = 272
organisms =150 -- set this to what ever value you want... 
letter = "o"
black = Color.new&#40;0,0,0&#41;
screennum = 0
math.random&#40;1,272&#41; &#125;
organism = &#123; &#125;
color = &#123; &#125;
iter = 1
function shadow&#40;x, y, text, c1, c2&#41;
   screen&#58;print&#40;x - 1, y, text, c2&#41;
   screen&#58;print&#40;x, y - 1, text, c2&#41;
   screen&#58;print&#40;x + 1, y, text, c2&#41;
   screen&#58;print&#40;x + 1, y + 1, text, c2&#41;
   screen&#58;print&#40;x + 1, y - 1, text, c2&#41;
   screen&#58;print&#40;x + 2, y, text, c2&#41;
   screen&#58;print&#40;x, y + 1, text, c2&#41;
   screen&#58;print&#40;x, y, text, c1&#41;
   screen&#58;print&#40;x + 1, y, text, c1&#41;
end 
white = Color.new&#40;255,255,255&#41;
math.randomseed&#40;os.time&#40;&#41; &#41;
for i=1,organisms do
	
	color&#91;i&#93; = &#123;color = Color.new&#40;math.random&#40;0,255&#41;, math.random&#40;0,255&#41;, math.random&#40;0,255&#41;&#41; &#125;
	organism&#91;i&#93; = &#123;posx = math.random&#40;1,480&#41;, posy = math.random&#40;1,272&#41; &#125;
end

while true do
pad = Controls.read&#40;&#41;
   if pad&#58;start&#40;&#41; then break end
   if pad&#58;triangle&#40;&#41; then
      screen.flip&#40;&#41;
      screen&#58;save&#40;"screenshot".. screennum..".png"&#41;
screennum = screennum + 1
   end
   if pad&#58;r&#40;&#41; and pad&#58;l&#40;&#41; then
      screen&#58;clear&#40;black&#41;
      iter = 1
   end 
for i=1,organisms do
	x = organism&#91;i&#93;.posx
	y = organism&#91;i&#93;.posy
	screen&#58;print&#40;x,y,letter,color&#91;i&#93;.color&#41;
	organism&#91;i&#93;.posx = organism&#91;i&#93;.posx + math.random&#40;-1,1&#41;
	organism&#91;i&#93;.posy = organism&#91;i&#93;.posy + math.random&#40;-1,1&#41;

	if organism&#91;i&#93;.posx >= screenwidth or organism&#91;i&#93;.posx <= 0 then
			organism&#91;i&#93;.posx = math.random&#40;1,480&#41;
	end
	if organism&#91;i&#93;.posy >= screenheight or organism&#91;i&#93;.posy <= 0 then
			organism&#91;i&#93;.posy = math.random&#40;1,272&#41;
	end
end

shadow&#40;2, 262, "Step&#58; " .. iter, black, white&#41;
	screen.flip&#40;&#41;
iter = iter + 1
end
while true do
screen.waitVblankStart&#40;&#41;
end
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

Post by Kameku »

Pretty interesting. I would suggest printing to an image and then blitting the image. I did, and it really reduced flicker and made it just look better. :)

Personally, I like the "10,000 fists," which is 10,000 organisms, with the lettter being "\m/"
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

RanDom_ErrOr wrote:luckily i cleaned it up alot, and reduced the size to nothing, i intend to add functionality to dynamically change the number of "organisms" with up/down arrow functionality... we'll see...
nice, like an impressionistic oil painting :-)
RanDom_ErrOr
Posts: 13
Joined: Sat Apr 15, 2006 11:19 am

Post by RanDom_ErrOr »

i want to figure out a way to do some blurring after the text has been added... but yet have seen any code or any reference on how to do it... i dont know, i just want to have some fun and use this as a tool on how to learn more of LUA.... With my (very very) limited programming experience (mainly PHP CSS and HTML) its not too hard to figure out things like syntax etc...

my only issues with LUA at this point in time are the things i just dont know... but i'm learning as i go, so it cant be all that bad.... >_>;

btw, im trying to figure out FPS (or iterations persecond...)

and my current code for it is as such

clock = Timer.new(0)
currenttime = clock:time()
fpscurrent = iter (iterations) / currenttime * 100

now im getting ~ 6FPS using waitforVsync within the same loop as screen:flip() but if i remove it, i boost my FPS to about 15FPS... (depending of course on number of organisms...) at 1500 organisms im getting 6.5-6.6~ FPS with the waitforVsync outside the loop... also runs very smooth...

I notice i dont get over ~ 15.5 FPS even with a single organism...

who knows...

btw revised code follows...

Code: Select all

-- Demonstration No-User-App
-- Author&#58; RanDom_ErrOr
-- Copyright 2006
-- No liscense with this product what so ever. Use at your own risk. I will accept no liability or responsibility if you **** something up.
System.usbDiskModeActivate&#40;&#41;
clock = &#123;&#125;
clock = Timer.new&#40;0&#41;
screenwidth = 482
screenheight = 274
organisms =1500
letter = "o"
black = Color.new&#40;0,0,0&#41;
red = Color.new &#40;255,0,0&#41;
white = Color.new&#40;255,255,255&#41;
canvas = Image.createEmpty&#40;480,272&#41;
canvas&#58;clear&#40;black&#41;
screennum = 0
organism = &#123; &#125;
color = &#123; &#125;
iter = 1
fpscurrent = 1
speed = 5
function shadow&#40;x, y, text, c1, c2&#41;
   screen&#58;print&#40;x - 1, y, text, c2&#41;
   screen&#58;print&#40;x, y - 1, text, c2&#41;
   screen&#58;print&#40;x + 1, y, text, c2&#41;
   screen&#58;print&#40;x + 1, y + 1, text, c2&#41;
   screen&#58;print&#40;x + 1, y - 1, text, c2&#41;
   screen&#58;print&#40;x + 2, y, text, c2&#41;
   screen&#58;print&#40;x, y + 1, text, c2&#41;
   screen&#58;print&#40;x, y, text, c1&#41;
   screen&#58;print&#40;x + 1, y, text, c1&#41;
end 
white = Color.new&#40;255,255,255&#41;
math.randomseed&#40;os.time&#40;&#41; &#41;
for i=1,organisms do
	color&#91;i&#93; = &#123;color = Color.new&#40;math.random&#40;0,255&#41;, math.random&#40;0,255&#41;, math.random&#40;0,255&#41;&#41; &#125;
	organism&#91;i&#93; = &#123;posx = math.random&#40;1,480&#41;, posy = math.random&#40;1,272&#41; &#125;
end

while true do
	pad = Controls.read&#40;&#41;
	if pad&#58;up&#40;&#41; then
		speed = speed + 1
		if speed >= 15 then
		speed = 15
		end
	end
	if pad&#58;down&#40;&#41; then
		speed = speed - 1
		if speed <= 1 then
		speed = 1
		end
	end
	if pad&#58;start&#40;&#41; then 
		break 
	end
	if pad&#58;triangle&#40;&#41; then
		screen&#58;blit&#40;-1,-1,canvas&#41;
		screen.flip&#40;&#41;
      		screen&#58;save&#40;"screenshot".. screennum..".png"&#41;
		screennum = screennum + 1
   	end
   	if pad&#58;r&#40;&#41; and pad&#58;l&#40;&#41; then
		canvas&#58;clear&#40;black&#41;
		iter = 1
   	end 
	for i=1,organisms do
		x = organism&#91;i&#93;.posx
		y = organism&#91;i&#93;.posy
		canvas&#58;print&#40;x,y,letter,color&#91;i&#93;.color&#41;
		organism&#91;i&#93;.posx = organism&#91;i&#93;.posx + math.random&#40;-speed,speed&#41;
		organism&#91;i&#93;.posy = organism&#91;i&#93;.posy + math.random&#40;-speed,speed&#41;

		if organism&#91;i&#93;.posx >= screenwidth or organism&#91;i&#93;.posx <= 0 then
			organism&#91;i&#93;.posx = math.random&#40;1,480&#41;
		end
		if organism&#91;i&#93;.posy >= screenheight or organism&#91;i&#93;.posy <= 0 then
			organism&#91;i&#93;.posy = math.random&#40;1,272&#41;
		end
	end
	screen&#58;clear&#40;&#41;
	screen&#58;blit&#40;-1,-1,canvas&#41;
	shadow&#40;2, 262, "Step&#58; " .. iter, black, white&#41;
	currenttime = clock&#58;time&#40;&#41;
	fpscurrent = iter / currenttime * 100
	shadow&#40;2,2,"Frames Per Second&#58; " .. fpscurrent,red,  white&#41;
	shadow&#40;2,11, "Speed&#58; " .. speed, red, white&#41;
	shadow&#40;2,20, "Organisms&#58; " .. organisms, red,white&#41;
	screen.flip&#40;&#41;
	iter = iter + 1
	end
while true do
	screen.waitVblankStart&#40;&#41;
end
too bad this method is flawed... /cry anyone have a slightly more accurate way of counting iterations per second in real time? w/o having slight clock inaccuracies...? (i.e if you reset the display with L and R it displays crazy numbers... /cry)

oh an interesting use for this application... stuck pixel unsticker... theoretically it should work >>; anyone want to give it a whirl and see if it works? hehe, at very least, its more pleasing on the eyes than a RGB flasher is... :x
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

Post by Kameku »

Just put in "clock:reset()" in your clear.
RanDom_ErrOr
Posts: 13
Joined: Sat Apr 15, 2006 11:19 am

Post by RanDom_ErrOr »

i tried that, but both iteration and timer are the same so it just does 1/1*100 and it just keeps going more and more... im just going to ignore it, and say FSCK it... i was just curious how many loops per second it was doing...

considering 6~7 * 1500 = 9000-11500 characters displayed per second... thats not too bad... (well, its not great, but still, not too bad for how this has been coded...)
Post Reply