|
#41
|
|||
|
|||
|
Created a tiny library, and a test app of some buttons.
I place this file, LIB.LUA in the /applications/ folder Code:
-- set some color vars function setColors() clrBlack = color.new(0,0,0); clrWhite = color.new(255,255,255); clrRed = color.new(255,0,0); clrBlue = color.new(0,0,255); clrYellow = color.new(255,255,0); clrGreen = color.new(0,255,0); clrOrange = color.new(255,128,0); clrGray = color.new(128,128,128); clrViolet = color.new(128,0,255); clrCyan = color.new(0,128,255); clrBrown = color.new(128,80,64); end; -- screen reset function resetScreen(color, update) screen.clear(); screen.fillrect(0,0,400,240, color); if update==1 then screen.update(); end; end; -- consolidated text operations function textWrite(x,y,color,size,string) text.color(color); text.size(size); text.draw(x,y,string); end; -- check home button function btnHome() --if (control.read() == 1) and (control.isButton() == 1) and (button.home() == 1) and (button.up() == 1) then if (control.read() == 1) and (control.isButton() == 1) and (button.home() == 1) and (button.click() == 1) then return true; else return false; end; end; --create button function makeButton(x,y,width,height,bordercolor,bgcolor,textsize,textcolor, string) screen.fillrect(x,y,width,height,bgcolor); screen.drawrect(x,y,x+width,y+height,bordercolor); text.color(textcolor); text.size(textsize); text.draw(x,y,string); end; -- check screen click function scrnClick() if (control.read() == 1) and (control.isTouch() == 1) and ((touch.click() == 1) or (touch.up() == 1)) then x,y = touch.pos(); return true; else return false; end; end; -- check button function btnClick(tx,ty,twidth,theight) if ((x>tx) and (x<(tx+twidth)) and (y>ty) and (y<(ty+theight))) then return true; else return flase; end; end; Code:
dofile("../LIB.LUA");
setColors();
a=0;
function refresh()
resetScreen(clrGray, 0);
textWrite(10,10,clrBlack,20,"a = "..a);
makeButton(350,0,50,50,clrWhite,clrViolet,20,clrWhite,"Up");
makeButton(350,140,50,50,clrWhite,clrViolet,20,clrWhite,"Dn");
makeButton(350,190,50,50,clrWhite,clrViolet,20,clrWhite,"Cls");
screen.update();
end;
refresh();
while true do
if btnHome() then break end;
if scrnClick() then
-- up button
if btnClick(350,0,50,50) then
a = a+1;
refresh();
end;
--down button
if btnClick(350,140,50,50) then
a = a-1;
refresh();
end;
--close button
if btnClick(350,190,50,50) then
break;
end;
end;
os.sleep(3);
end;
|
|
|
|||
|
|
|
#42
|
|||
|
|||
|
May I recommend some changes?
Code:
function textWrite(x,y,color,size,string) text.color(color); text.size(size); text.draw(x,y,string); end; Code:
function textWrite(x,y,color,size,string) text.color(color); local osize = text.size(size); text.draw(x,y,string); text.size(osize) end; Code:
function scrnClick() if (control.read() == 1) and (control.isTouch() == 1) and ((touch.click() == 1) or (touch.up() == 1)) then x,y = touch.pos(); return true; else return false; end; end; Code:
function scrnClick() if (control.read() == 1) and (control.isTouch() == 1) and ((touch.click() == 1) or (touch.up() == 1)) then --Not even sure if we have to call the below to remove it from the queue local x,y = touch.pos(); return true; else return false; end; end; Code:
function setColors() clrBlack = color.new(0,0,0); clrWhite = color.new(255,255,255); clrRed = color.new(255,0,0); clrBlue = color.new(0,0,255); clrYellow = color.new(255,255,0); clrGreen = color.new(0,255,0); clrOrange = color.new(255,128,0); clrGray = color.new(128,128,128); clrViolet = color.new(128,0,255); clrCyan = color.new(0,128,255); clrBrown = color.new(128,80,64); end; Code:
clrBlack = color.new(0,0,0); clrWhite = color.new(255,255,255); clrRed = color.new(255,0,0); clrBlue = color.new(0,0,255); clrYellow = color.new(255,255,0); clrGreen = color.new(0,255,0); clrOrange = color.new(255,128,0); clrGray = color.new(128,128,128); clrViolet = color.new(128,0,255); clrCyan = color.new(0,128,255); clrBrown = color.new(128,80,64); |
|
#43
|
|||
|
|||
|
Quote:
And thanks for the help on var scope stuff, I need to play wth that some more. |
|
#44
|
|||
|
|||
|
Yeh I was trying to push the zen to it's limits and noticed that local scope is MUCH faster in terms of execution speed. Mostly because local variables are kept on a "stack" in the VM.
|
|
#45
|
||||
|
||||
|
"and (touch.up() == 1 or touch.click == 1)"
Hi, It works great to avoid double clicks, but it makes clicking slow, and unresponsive. Regarding the function 'textwrite', what about using the alignment commands, the center command makes it easy to place text, uneffected of text size and number of char's. Code:
color_black = color.new(0,0,0); color_white = color.new(255,255,255); color_text = color.new(255,255,200); screen.fillrect(0,0,400,240,color_black); text.color(color_white); text1="Anything But "; text2="Ipod"; text.size(16); text.draw(0,10, text1 .. text2, "left", 400); text.draw(0,30, text1 .. text2, "center",400); text.draw(0,50, text1 .. text2, "right", 400); text.size(40); text.color(color_text); text.draw(0,100, "CREATIVE X-Fi2", "center", 400); screen.update(); Quote:
|
|
#46
|
|||
|
|||
|
Code:
if control.read() == 1 and control.isTouch() == 1 and (touch.up() == 1 or touch.click() == 1) then
x, y = touch.pos()
|
|
#47
|
|||
|
|||
|
Nice topic !!
I always like programming on devices other dan a pc Quote:
indeed a lot of random numbers, but there is a change when you move the device. i've added some sound with the changing var's Code:
color_black = color.new(0,0,0);
color_white = color.new(255,255,255);
color_blue = color.new(0,0,255);
color_red = color.new(255,0,0);
color_green = color.new(0,255,0);
screen.clear();
text.size(20);
text.color(color_white);
while true do
x = accelerometer.getdata();
y = accelerometer.get_senddatatype();
z = accelerometer.get_samplerate();
screen.fillrect(0,0,400,240,color_black);
text.draw(10,10,"Accelerometer Test");
text.draw(10,30,x);
text.draw(10,50,y);
text.draw(10,70,z);
audio.beep(z+500,20);
screen.update();
if (control.read() == 1) and (button.home() == 1) then
break;
end;
os.sleep(4);
end;
it does not only "feels" the angle but also raising up and down, you can hear the sound changing. I think that the different data are different types of data. One range is the angle, 1 range is raise up and down. it's just a tought. sorry for my bad english, we call it Nederspeak :P (spenglish for dutch people) |
|
#48
|
||||
|
||||
|
X-Clock
![]() A clock in size 140 fonts, using the "center" alignment. Amazing what you can do with few lines, this clock on the O2 would have been 1000's of lines and bitmap font loading and so on. :-) Here we have fully anti aliasing scalable fonts in three lines. Code:
-- X-Fi Clock
color_black = color.new(0,0,0);
color_date = color.new(120,200,255);
color_time = color.new(0,144,255);
while true do
text.color(color_date);
text.size(20);
text.draw(0,10, os.date(), "center", 400);
text.color(color_time);
text.size(140);
text.draw(0,40, string.sub (os.date(),12,16), "center", 400);
screen.update();
screen.fillrect(0,0,400,240,color_black);
if (control.read() == 1) and (control.isButton() == 1) and (button.home() == 1) and (button.click() == 1) then
break;
end;
os.sleep(10);
end;
text.size(140); text.draw(0,40, string.sub (os.date(),12,16), "center", 400); to this text.size(100); text.draw(0,60, string.sub (os.date(),12,19), "center", 400); Last edited by Jan_DK; 12-08-2009 at 09:50 AM. Reason: add seconds |
|
#49
|
|||
|
|||
|
Absolutely wonderful idea on the accelerometer with the beeps. Still trying to find out to make it practical.
|
|
#50
|
|||
|
|||
|
Hi guys. I just bought my fi2 and am waiting for it.
Glad to see it can be programmed!
|
|
#51
|
|||
|
|||
|
Yup for sure its nice to see this player can be programmed. If this thing gets more popular we might get some homebrew scene going if we're in luck!
|
|
#52
|
|||
|
|||
|
It's still seriously limited in my view. In terms of the API we are given in terms of images, screen, and drawing are all very set. Nor can we counteract by redrawing a lot because the thing just isn't very powerful especially when reduced to a scripting language.
The touch screen isn't responsive enough for things passed tic-tac-toe(I would loved to be proved wrong here) and the accelerometer can only detect the orientation you are holding the player. Homebrew are going to have to be either simplistic or creative to be actually usable. Edit: Was messing around with image.create() today. Was hoping it created a copy of the screen at selected coordinates, because we have no way of getting data from the screen. Well, course it didn't to what I wanted. It basically created a new image with non-initialized memory. Completely useless if you ask me. I don't see how I can draw to the image, nor can we save it. Last edited by ThievingSix; 12-09-2009 at 04:22 PM. |
|
#53
|
||||
|
||||
|
The only LUA/X-Fi2 thing I've fund out today is to play audio wave files
The wave file was a 44100hz stereo 1.2Mb the range in the volume I'm not sure of? Code:
audio.volume(25);
background_sound = wav.load("sound1.wav");
wav.play(background_sound);
I'm looking for a way to take a screen shot and save to disk. Jan. |
|
#54
|
|||
|
|||
|
lol Jan, read my last post, it's what I've been trying to screw around with as well.
And I want to correct my last post. I can write to newly created images with image.fill(color), but not entirely useful. |
|
#55
|
|||
|
|||
|
Quote:
maybe itīs possible to make something like Axe for the Nintendo DS . But in that app, the sound is generated. Should also be possible i think. |
|
#56
|
|||
|
|||
|
Not possible. We don't have sufficient access to the hardware directly for an application like that.
|
|
#57
|
|||
|
|||
|
nice job all.
i have one question that there seems to be some ambiguity on... can i save straight text with a .lua extension, or do i need a program to change it to that bytecode? if so, which program should i use? also, if anyone is looking to build a game for this, might i suggest atari games? the old atari had crap resolution for its controllers and crap resolution for its screen, yet the games were badass...not to mention the code for them in various languages is available as public domain. asteroids would be nice...joust, missile command maybe? |
|
#58
|
||||
|
||||
|
You can use notepad in windows,
no converting or compiling is necessary. 1. make a folder in the application folder on the X-fi2. 2. save the text file as MAIN.LUA |
|
#59
|
|||
|
|||
|
You can do either, compile or no compile. One would have less load time.
|
|
#60
|
|||
|
|||
|
thanks.
what about reading the soduku.lua...what program would i use? i'd like to use lua to change a few little things -thicker volume control always showing -turn off screen while docked -move scroller position to touch point without having to drag the little button |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 02:55 AM.













Linear Mode
