| FBA The Creator http://www.fbacreator.com/fbaforum/ |
|
| New small functions http://www.fbacreator.com/fbaforum/viewtopic.php?f=3&t=221 |
Page 1 of 1 |
| Author: | Root [ Tue Sep 29, 2009 4:23 pm ] |
| Post subject: | New small functions |
I want to quickly get image point color in RGB format. I've made function for that: red,green,blue = givecolor(fba) -- fba is color in 65536 mode (two bytes or 16bit) function givecolor(fba) return math.floor(fba/2048)*8,math.floor((fba-math.floor(fba/2048)*2048)/32)*4,((fba-math.floor(fba/2048)*2048)-math.floor((fba-math.floor(fba/2048)*2048)/32)*32)*8 end it's like getcolor but vice versa (as you can see) but the problem is that it takes too much time to implement something like that: R,G,B = givecolor( imagecolor(h, x, y) ) small but too long if you want to scan image with screen size 240X320. so I would like to apply for other, faster function like imagecolor() but specified only on the shortest geting color data, I mean without choosing "post color" if "imagecolor(h, x, y, R, G, B)" or "get it" if "imagecolor(h, x, y)" and all other stuff. And if you don't mind add my function givecolor(fba) for example to your getcolor() for crossconverting e.g. FBA = getcolor(R, G, B) R, G, B = getcolor(FBA) or as a separate function. Some people may need that... |
|
| Author: | Root [ Tue Sep 29, 2009 4:27 pm ] |
| Post subject: | Re: New small functions |
And I got another interesting func. xShift,yShift = rotate(angle) function rotate(a) return math.cos(a / 180 * math.pi), - math.sin(a / 180 * math.pi) end minus flippin' Y axis (because on screen we have it increasing in down direction) can be used for determination of coordinates after turning on some angle. Try this to understand what I mean: Code: -----"main.fba"----- allso x and y can be added. ARC function Based on rotate() please add it to Fba! arc(xc, yc, r, sa, ea, R,G,B) xc, yc - center sa, ea - starting angle, ending angle Code: -----"main.fba"----- in this way can be implemented sector() cluster() chord() with help of poly() and filled versions of them like in fillpoly(). |
|
| Author: | Root [ Tue Sep 29, 2009 4:58 pm ] |
| Post subject: | Re: New small functions |
byte (256) encoding used in many files to store numerical info e.g. imageheight in images or bitrate in sound files and so on. encoded = b256(number[, limit]) number - number to encode limit - defines how many characters should have encoded string function f256(n,limit) local str="" local por=(limit or string.len(n))-1 for x=0,por do local dig=math.floor(n/256^(por-x)) n=n-dig*256^(por-x) str=string.char(dig)..str end return str end decoding function looks like that: decoded = unb256(str, limit) function unb256(str, limit) local n=0 local por=(limit or string.len(str)) for x=1,por do n=n+string.byte(str,x)*256^(x-1) end return n end This one can be used for decoding header of files. This simplifying loading EXTERNAL images of many formats. You can even load video files .avi for example. and play it as an array of images.(unfortunaly without sound |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Limited https://www.phpbb.com/ |
|