Lua: finished inputbox with negative and decimal inputs. Added to the repository more than 20(!) new scripts by DawnBringer

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1357 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2010-02-21 17:58:20 +00:00
parent b393482c58
commit 8c2655f88a
42 changed files with 1301 additions and 97 deletions

View File

@ -42,3 +42,13 @@ void Error_function(int error_code, const char *filename, int line_number, const
/// - If the error code is 0, just do a red screen flash and resume. /// - If the error code is 0, just do a red screen flash and resume.
/// - If the error code is non-zero, abort the program. /// - If the error code is non-zero, abort the program.
#define Error(n) Error_function(n, __FILE__,__LINE__,__func__) #define Error(n) Error_function(n, __FILE__,__LINE__,__func__)
/// Helper function used by the macro ::Warning
void Warning_function(const char *message, const char *filename, int line_number, const char *function_name);
///
/// Report a run-time abnormal condition : It will print to standard output
/// some information about the calling function, and then resume silently.
/// This is most useful in debugger so you can put a breakpoint on
/// ::Warning_function and examine the stack trace.
#define Warning(msg) Warning_function(msg, __FILE__,__LINE__,__func__)

View File

@ -488,9 +488,6 @@ int L_GetTransColor(lua_State* L)
return 1; return 1;
} }
int L_InputBox(lua_State* L) int L_InputBox(lua_State* L)
{ {
const int max_settings = 9; const int max_settings = 9;
@ -574,7 +571,6 @@ int L_InputBox(lua_State* L)
if (max_label_length>25) if (max_label_length>25)
max_label_length=25; max_label_length=25;
Hide_cursor();
Open_window(115+max_label_length*8,44+nb_settings*17,window_caption); Open_window(115+max_label_length*8,44+nb_settings*17,window_caption);
// OK // OK
@ -603,7 +599,7 @@ int L_InputBox(lua_State* L)
// Numeric input field // Numeric input field
Window_set_input_button(12+max_label_length*8+21, 20+setting*17,7); Window_set_input_button(12+max_label_length*8+21, 20+setting*17,7);
// Print editable value // Print editable value
Dec2str(current_value[setting],str,decimal_places[setting]); Sprint_double(str,current_value[setting],decimal_places[setting],7);
Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light); Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light);
// //
control[Window_nb_buttons] = CONTROL_INPUT | setting; control[Window_nb_buttons] = CONTROL_INPUT | setting;
@ -636,7 +632,8 @@ int L_InputBox(lua_State* L)
break; break;
case CONTROL_INPUT: case CONTROL_INPUT:
Dec2str(current_value[setting],str,decimal_places[setting]);
Sprint_double(str,current_value[setting],decimal_places[setting],0);
Readline_ex(12+max_label_length*8+23, 22+setting*17,str,7,40,3,decimal_places[setting]); Readline_ex(12+max_label_length*8+23, 22+setting*17,str,7,40,3,decimal_places[setting]);
current_value[setting]=atof(str); current_value[setting]=atof(str);
@ -644,9 +641,8 @@ int L_InputBox(lua_State* L)
current_value[setting] = min_value[setting]; current_value[setting] = min_value[setting];
else if (current_value[setting] > max_value[setting]) else if (current_value[setting] > max_value[setting])
current_value[setting] = max_value[setting]; current_value[setting] = max_value[setting];
Hide_cursor();
// Print editable value // Print editable value
Dec2str(current_value[setting],str,decimal_places[setting]); Sprint_double(str,current_value[setting],decimal_places[setting],7);
Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light); Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light);
// //
Display_cursor(); Display_cursor();
@ -662,7 +658,7 @@ int L_InputBox(lua_State* L)
Hide_cursor(); Hide_cursor();
// Print editable value // Print editable value
Dec2str(current_value[setting],str,decimal_places[setting]); Sprint_double(str,current_value[setting],decimal_places[setting],7);
Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light); Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light);
// //
Display_cursor(); Display_cursor();
@ -678,7 +674,7 @@ int L_InputBox(lua_State* L)
Hide_cursor(); Hide_cursor();
// Print editable value // Print editable value
Dec2str(current_value[setting],str,decimal_places[setting]); Sprint_double(str,current_value[setting],decimal_places[setting],7);
Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light); Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light);
// //
Display_cursor(); Display_cursor();
@ -695,7 +691,6 @@ int L_InputBox(lua_State* L)
} }
} }
Hide_cursor();
Close_window(); Close_window();
Cursor_shape=CURSOR_SHAPE_HOURGLASS; Cursor_shape=CURSOR_SHAPE_HOURGLASS;
Display_cursor(); Display_cursor();

6
main.c
View File

@ -110,6 +110,12 @@ void Display_syntax(void)
} }
} }
// ---------------------------- Sortie impromptue ----------------------------
void Warning_function(const char *message, const char *filename, int line_number, const char *function_name)
{
printf("Warning in file %s, line %d, function %s : %s\n", filename, line_number, function_name, message);
}
// ---------------------------- Sortie impromptue ---------------------------- // ---------------------------- Sortie impromptue ----------------------------
void Error_function(int error_code, const char *filename, int line_number, const char *function_name) void Error_function(int error_code, const char *filename, int line_number, const char *function_name)

View File

@ -152,7 +152,10 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
else if (input_type==1) else if (input_type==1)
snprintf(str,10,"%d",atoi(str)); // On tasse la chaine à gauche snprintf(str,10,"%d",atoi(str)); // On tasse la chaine à gauche
else if (input_type==3) else if (input_type==3)
sprintf(str,"%.*f",decimal_places, atof(str)); // On tasse la chaine à gauche {
// Nothing. The caller should have used Sprint_double, with min_positions
// at zero, so there's no spaces on the left and no useless 0s on the right.
}
Wait_end_of_click(); Wait_end_of_click();
Keyboard_click_allowed = 0; Keyboard_click_allowed = 0;
@ -169,7 +172,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
size=strlen(str); size=strlen(str);
position=(size<max_size)? size:size-1; position=(size<max_size)? size:size-1;
if (position-offset>visible_size) if (position-offset>=visible_size)
offset=position-visible_size+1; offset=position-visible_size+1;
// Formatage d'une partie de la chaine (si trop longue pour tenir) // Formatage d'une partie de la chaine (si trop longue pour tenir)
strncpy(display_string, str + offset, visible_size); strncpy(display_string, str + offset, visible_size);
@ -247,7 +250,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
if ((position<size) && (position<max_size-1)) if ((position<size) && (position<max_size-1))
{ {
position=(size<max_size)?size:size-1; position=(size<max_size)?size:size-1;
if (position-offset>visible_size) if (position-offset>=visible_size)
offset=position-visible_size+1; offset=position-visible_size+1;
goto affichage; goto affichage;
} }
@ -359,35 +362,9 @@ affichage:
else if (input_type==3) else if (input_type==3)
{ {
double value; double value;
int i; // Discard extra digits
unsigned int str_length; value = Fround(atof(str), decimal_places);
Sprint_double(str,value,decimal_places,visible_size);
value = atof(str);
// Remove extraneous decimal places:
// From number
value = Fround(value, decimal_places);
// From display
sprintf(str,"%.*f",decimal_places, atof(str));
// Remove extraneous zeroes
/*
for (i=0; i<size; i++)
{
if (str[i]=='.')
{
int j;
for (j=0; i+j<size && j<decimal_places && str[i+j]!='.'; j++)
{
// advance
}
str[i+j]='\0';
size = i+j;
break; // end of process
}
}
*/
// Recompute updated size // Recompute updated size
size = strlen(str); size = strlen(str);
@ -405,3 +382,53 @@ affichage:
return (input_key==SDLK_RETURN || Mouse_K != 0); return (input_key==SDLK_RETURN || Mouse_K != 0);
} }
void Sprint_double(char *str, double value, byte decimal_places, byte min_positions)
{
int i;
int length;
sprintf(str,"%.*f",decimal_places, value);
length=strlen(str);
for (i=0; i<length; i++)
{
if (str[i]=='.')
{
// Remove extraneous zeroes
char * decimals = str+i+1;
int j;
for (j=strlen(decimals)-1; j >= 0 && decimals[j]=='0'; j--)
{
decimals[j] = '\0';
}
// If all decimals were removed, remove the dot too
if (str[i+1]=='\0')
str[i]='\0';
// Update string length
length=strlen(str);
// Ends the parent loop
break;
}
}
// Now try add spaces at beginning
if (length<min_positions)
{
int offset = min_positions - length;
// Move the string to the right
for (i=0; i<=length; i++)
{
str[length+offset-i] = str[length-i];
}
// Replace the N first characters by spaces
for (i=0; i<offset; i++)
{
str[i] = ' ';
}
}
}

View File

@ -45,3 +45,11 @@ byte Readline(word x_pos,word y_pos,char * str,byte visible_size,byte input_type
/// @param decimal_places Number of decimal places (used only with decimal type) /// @param decimal_places Number of decimal places (used only with decimal type)
/// @return 0 if user cancelled (esc), 1 if accepted (return) /// @return 0 if user cancelled (esc), 1 if accepted (return)
byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_size, byte input_type, byte decimal_places); byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_size, byte input_type, byte decimal_places);
///
/// Converts a double to string.
/// @param str Target string, should be pre-allocated and at least 40 characters, to be safe.
/// @param value The number to convert
/// @param decimal_places Number of decimal places to keep. 15 seems the maximum.
/// @param min_positions Minimum number of characters: Will pad spaces on the left to meet this minimum.
void Sprint_double(char *str, double value, byte decimal_places, byte min_positions);

View File

@ -13,8 +13,8 @@ messagebox(
ok, w, h = inputbox("Modify brush", ok, w, h = inputbox("Modify brush",
"Width", w, -100.0,100.0, 0, "Width", w, -900.0,900.0, 3,
"Height", h, -200.0,100.0, 0, "Height", h, -900.0,900.0, 4,
"X Flip", 0, 0, 1, 0, "X Flip", 0, 0, 1, 0,
"Y Flip", 0, 0, 1, 0 "Y Flip", 0, 0, 1, 0
); );

View File

@ -1,35 +1,13 @@
-- Picture scene: Amigaball --BRUSH Scene: Amigaball 1.0
-- by Richard Fhager, code adopted --by Richard Fhager
-- from Evalion --http://hem.fyristorg.com/dawnbringer/
w = 256 -- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
h = 256 --http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
setpicturesize(w,h)
-- Set Amiga Palette
colors = {} w, h = getbrushsize()
for c = 0, 63, 1 do
colors[c+1] = {c*4,0,0}
end
for c = 0, 63, 1 do
colors[c+65] = {255,c*4,c*4}
end
for c = 0, 63, 1 do
colors[c+129] = {255-c*4,255-c*4,255-c*4}
end
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end
-- Make Amiga ball
for y = 0, h - 1, 1 do for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do for x = 0, w - 1, 1 do
@ -58,9 +36,7 @@ for y = 0, h - 1, 1 do
g = V + SPEC1 + SPEC2 g = V + SPEC1 + SPEC2
b = V + SPEC1 + SPEC2 b = V + SPEC1 + SPEC2
c = matchcolor(r,g,b) putbrushpixel(x, y, matchcolor(r,g,b));
putpicturepixel(x, y, c);
end end
end end

View File

@ -0,0 +1,31 @@
--BRUSH Scene: Sphere of pencolor v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
--http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
w, h = getbrushsize()
rp,gp,bp = getcolor(getforecolor())
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
-- Fractionalize image dimensions
ox = x / w;
oy = y / h;
-- Sphere
X = 0.5; Y = 0.5; Rd = 0.5
a = math.sqrt(math.max(0,Rd*Rd - ((X-ox)*(X-ox)+(Y-oy)*(Y-oy)))) * 1/Rd
r = rp * a
g = gp * a
b = bp * a
putbrushpixel(x, y, matchcolor(r,g,b));
end
end

94
scripts/bru_db_FindAA.lua Normal file
View File

@ -0,0 +1,94 @@
--BRUSH: Find AA-colors from pencolors
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
cellw = 8
cellh = 4
colors = 256
setbrushsize(cellw * 3, cellh * 3)
--
function makePalList(cols)
pal = {}
for n = 0, cols-1, 1 do
r,g,b = getcolor(n)
pal[n+1] = {r,g,b}
end
return pal
end
--
--
function getBestPalMatchHYBRID(rgb,pal,briweight)
local diff,diffC,diffB,best,bestcol,cols,n,c,r,g,b,p,obri,pbri
cols = #pal
bestcol = 0
best = 9e99
r = rgb[1]
g = rgb[2]
b = rgb[3]
obri = math.pow(r*9,2)+math.pow(g*16,2)+math.pow(b*8,2)
for n=0, cols-1, 1 do
p = pal[n+1]
pbri = math.pow(p[1]*9,2)+math.pow(p[2]*16,2)+math.pow(p[3]*8,2)
diffB = math.abs(obri - pbri)
diffC = (math.pow(r-p[1],2)+math.pow(g-p[2],2)+math.pow(b-p[3],2)) * 400
--diff = diffB + diffC
diff = briweight * (diffB - diffC) + diffC
if diff <= best then bestcol = n; best = diff; end
end
return bestcol
end
--
--
function drawRectangle(x1,y1,w,h,c)
for y = y1, y1+h, 1 do
for x = x1, x1+w, 1 do
putbrushpixel(x,y,c);
end
end
end
--
palList = makePalList(colors)
cf = getforecolor()
cb = getbackcolor()
rf,gf,bf = getcolor(cf)
rb,gb,bb = getcolor(cb)
ra = (rf + rb) / 2
ga = (gf + gb) / 2
ba = (bf + bb) / 2
rgb1 = {ra,ga,ba}
c1 = getBestPalMatchHYBRID(rgb1,palList,0.0)
c2 = getBestPalMatchHYBRID(rgb1,palList,0.75)
c3 = getBestPalMatchHYBRID(rgb1,palList,0.99)
q = {{cf,c1,cb},
{cf,c2,cb},
{cf,c3,cb}}
for y = 0, #q-1, 1 do
for x = 0, #q[1]-1, 1 do
drawRectangle(x*cellw,y*cellh,cellw,cellh,q[y+1][x+1])
end
end

View File

@ -0,0 +1,24 @@
--BRUSH Distortion: FishEye
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
--http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
w, h = getbrushsize()
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
ox = x / w;
oy = y / h;
v = (math.cos((ox-0.5)*math.pi)*math.cos((oy-0.5)*math.pi))*0.85;
ox = (1 + ox - (ox-0.5)*v) % 1;
oy = (1 + oy - (oy-0.5)*v) % 1;
c = getbrushbackuppixel(math.floor(ox*w),math.floor(oy*h));
putbrushpixel(x, y, c);
end
end

View File

@ -0,0 +1,18 @@
--BRUSH Remap: Grayscale (average)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
w, h = getbrushsize()
for x = 0, w - 1, 1 do
for y = 0, h - 1, 1 do
r, g, b = getcolor(getbrushpixel(x,y))
a = (r+g+b)/3
putbrushpixel(x, y, matchcolor(a,a,a));
end
end

View File

@ -0,0 +1,29 @@
--BRUSH Remap: Grayscale (desaturate)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
--http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
percent = 100
--
function desaturate(percent,r,g,b) -- V1.0 by Richard Fhager
p = percent / 100
a = (math.min(math.max(r,g,b),255) + math.max(math.min(r,g,b),0)) * 0.5 * p
r = math.min(math.max(r + (a-r*p),0),255) -- Capping may not be needed if mathcolor/setcolor is updated
g = math.min(math.max(g + (a-g*p),0),255)
b = math.min(math.max(b + (a-b*p),0),255)
return r,g,b
end
--
w, h = getbrushsize()
for x = 0, w - 1, 1 do
for y = 0, h - 1, 1 do
putbrushpixel(x, y, matchcolor(desaturate(percent,getcolor(getbrushpixel(x,y)))));
end
end

View File

@ -0,0 +1,28 @@
--BRUSH: Halfsize with smoothscaling
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
w, h = getbrushsize()
setbrushsize(math.floor(w/2),math.floor(h/2))
for x = 0, w - 1, 2 do
for y = 0, h - 1, 2 do
r1,g1,b1 = getcolor(getbrushbackuppixel(x,y));
r2,g2,b2 = getcolor(getbrushbackuppixel(x+1,y));
r3,g3,b3 = getcolor(getbrushbackuppixel(x,y+1));
r4,g4,b4 = getcolor(getbrushbackuppixel(x+1,y+1));
r = (r1 + r2 + r3 + r4 ) / 4;
g = (g1 + g2 + g3 + g4 ) / 4;
b = (b1 + b2 + b3 + b4 ) / 4;
c = matchcolor(r,g,b);
putbrushpixel(x/2, y/2, c);
end
end

View File

@ -0,0 +1,54 @@
--BRUSH Scene: Mandelbrot fractal v0.5
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
--http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
colors = 64
x0 = -1.7
x1 = 0.7
ym = 0
iter = 64
ok, x0, x1, ym, iter = inputbox("Fractal data",
"X0", x0, -2, 2,4,
"X1", x1, -2, 2,4,
"midY", ym, -2, 2,4,
"Iter", iter, 1, 2048,0
);
-- -0.831116819,-0.831116815,0.2292112435,192
function mandel(x,y,l,r,o,i) -- pos. as fraction of 1, left coord, right coord, y coord, iterations
local w,s,a,p,q,n,v,w
s=math.abs(r-l);
a = l + s*x;
p = a;
b = o - s*(y-0.5);
q = b;
n = 1;
v = 0;
w = 0;
while (v+w<4 and n<i) do n=n+1; v=p*p; w=q*q; q=2*p*q+b; p=v-w+a; end;
return n
end
w, h = getbrushsize()
for x = 0, w - 1, 1 do
for y = 0, h - 1, 1 do
q = mandel(x/w,y/h,x0,x1,ym,iter) % colors;
putbrushpixel(x, y, q);
end
end

35
scripts/bru_db_Waves.lua Normal file
View File

@ -0,0 +1,35 @@
--BRUSH Distortion: Waves v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
--frq = 2
--amp = 0.3
-- Adjust power of frequency & amplitude
frq_adj = 2
amp_adj = 0.02
ok,frq,amp = inputbox("Settings",
"Frequency 1-10", 3, 1,10,0,
"Amplitude 1-10", 3, 1,10,0
);
w, h = getbrushsize()
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
ox = x / w;
oy = y / h;
ox = (1 + ox + math.sin(oy*math.pi*frq*frq_adj)*amp*amp_adj) % 1;
c = getbrushbackuppixel(math.floor(ox*w),y);
putbrushpixel(x, y, c);
end
end

View File

@ -1,21 +0,0 @@
-- Picture distortion: Sine
w, h = getpicturesize()
frq = 2
amp = 0.3
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
ox = x / w;
oy = y / h;
ox = (1 + ox + math.sin(oy*math.pi*frq)*amp) % 1;
c = getbackuppixel(math.floor(ox*w),y);
--c = y % 16
putpicturepixel(x, y, c);
end
end

View File

@ -0,0 +1,33 @@
--PALETTE Adjust: Desaturate v1.1
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
-- Note: Negative values will work as INCREASED saturation, but I'm not sure if this function is 100% correct
--percent = 25
OK,percent = inputbox("Desaturate Palette","Percent %", 25, 0,100,0);
--
function desaturate(percent,r,g,b) -- V1.0 by Richard Fhager
p = percent / 100
a = (math.min(math.max(r,g,b),255) + math.max(math.min(r,g,b),0)) * 0.5 * p
r = r + (a-r*p)
g = g + (a-g*p)
b = b + (a-b*p)
return r,g,b
end
--
if OK == true then
for c = 0, 255, 1 do
setcolor(c, desaturate(percent,getcolor(c)))
end
end

View File

@ -0,0 +1,164 @@
--PALETTE: Expand Colors v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
--
-- Continously fill the greatest void in the area of the color-cube enclosed by (or along ramps of) initial colors
-- This algorithm will create lines of allowed colors (all ranges) in 3d colorspace and the pick
-- new colors from the most void areas (on any line). Almost like a Median-cut in reverse.
--
-- Rather than filling the colorcube symmetrically it adds intermediate colors to the existing ones.
--
-- Running this script on the C64 16-color palette might be educational
--
--
-- Source cols#, Expand to #,
-- Ex: 15-31 means that palette colors 0-15 is expanded to 16 new colors placed at slots 16-31
--
-- Spread mode: OFF - New colors will conform to the contrast & saturation of original colors
-- (new colors will stay on the ramps possible from the original colors)
--
-- ON - New colors will expand their variance by each new addition (mostly notable when adding many new colors)
-- Will add range lines/ramps to all new colors from old ones, but keep within max/min values of the
-- original colors. 15-bit mode will dampen the spread towards extreme colors (if starting with low contrast)
--
-- 15-bit colors: Higher color-resolution, 32768 possible colors rather than the 4096 of 12bit. Slower but perhaps better.
--
SHADES = 16 -- Going 24bit will probably be too slow and steal too much memory, so start with 12bit (4096 colors) for now
ini = 0
exp = 255
OK,ini,exp,linemode,fbit = inputbox("Expand Colors (0-255):",
"Source Cols #: 1-254", 15, 1,254,0,
"Expand to #: 2-255", 31, 2,255,0,
"Spread mode", 0, 0,1,0,
"15-bit colors (slow)", 0, 0,1,0
);
if (fbit == 1) then SHADES = 32; end
function initColorCube(sha)
ary = {}
for z = 0, sha-1, 1 do
ary[z+1] = {}
for y = 0, sha-1, 1 do
ary[z+1][y+1] = {}
for x = 0, sha-1, 1 do
ary[z+1][y+1][x+1] = {false,0}
end
end
end
return ary
end
-- Gravity model (think of colors as stars of equal mass/brightness in a 3d space)
function addColor2Cube(cube,sha,r,g,b)
star = 1000000
fade = 1000
cube[r+1][g+1][b+1] = {false,star}
for z = 0, sha-1, 1 do
for y = 0, sha-1, 1 do
for x = 0, sha-1, 1 do
d = fade / ( (x-b)^2 + (y-g)^2 + (z-r)^2 )
cube[z+1][y+1][x+1][2] = cube[z+1][y+1][x+1][2] + d
end;end;end
end
-- Create new allowed colorlines in colorspace (ramps from which colors can be picked)
function enableRangeColorsInCube(cube,sha,r1,g1,b1,r2,g2,b2)
local div,r,g,b
div = 256 / sha
rs = (r2 - r1) / sha / div
gs = (g2 - g1) / sha / div
bs = (b2 - b1) / sha / div
for n = 0, sha-1, 1 do
r = math.floor(r1/div + rs * n)
g = math.floor(g1/div + gs * n)
b = math.floor(b1/div + bs * n)
cube[r+1][g+1][b+1][1] = true
end
end
function findVoid(cube,sha)
weakest = 999999999999
weak_i = {-1,-1,-1}
for z = 0, sha-1, 1 do
for y = 0, sha-1, 1 do
for x = 0, sha-1, 1 do
c = cube[z+1][y+1][x+1]
if c[1] == true then
w = c[2]
if w <= weakest then weakest = w; weak_i = {z,y,x}; end
end
end;end;end
return weak_i[1],weak_i[2],weak_i[3]
end
--
if OK == true then
cube = initColorCube(SHADES)
-- Define allowed colorspace
for y = 0, ini-1, 1 do
r1,g1,b1 = getcolor(y)
for x = y+1, ini, 1 do
r2,g2,b2 = getcolor(x)
enableRangeColorsInCube(cube,SHADES,r1,g1,b1,r2,g2,b2)
end
end
div = 256 / SHADES
-- Fill cube with initial colors
for n = 0, ini, 1 do
r,g,b = getcolor(n)
addColor2Cube(cube,SHADES,math.floor(r/div),math.floor(g/div),math.floor(b/div))
end
for n = ini+1, exp, 1 do
r,g,b = findVoid(cube,SHADES)
if (r == -1) then messagebox("Report:","No more colors can be found, exit at "..n); break; end
mult = 255 / (SHADES - 1)
setcolor(n, r*mult,g*mult,b*mult)
if linemode == 1 then
-- Add lines from new color to all old
for x = 0, n-1, 1 do
r2,g2,b2 = getcolor(x)
enableRangeColorsInCube(cube,SHADES,r*mult,g*mult,b*mult,r2,g2,b2) -- uses 24bit values rgb
end
end
addColor2Cube(cube,SHADES,r,g,b) -- rgb is in 'shade' format here
end
end

View File

@ -0,0 +1,98 @@
--PALETTE: Fill ColorCube voids v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
--
-- Create a palette by continously filling the greatest void in the RGB color-cube
--
SHADES = 16 -- Going 24bit will probably be too slow and steal too much memory, so we're 12bit (4096 colors) for now
ini = 0
exp = 255
OK,ini,exp = inputbox("Fill Palette Color voids",
"From/Keep #: 0-254", 0, 0,254,0,
"Replace to #: 1-255", 31, 1,255,0
);
function initColorCube(sha)
ary = {}
for z = 0, sha-1, 1 do
ary[z+1] = {}
for y = 0, sha-1, 1 do
ary[z+1][y+1] = {}
end
end
return ary
end
function addColor2Cube(cube,sha,r,g,b) -- Gravity model
star = 1000000
fade = 1000
cube[r+1][g+1][b+1] = star
for z = 0, sha-1, 1 do
for y = 0, sha-1, 1 do
for x = 0, sha-1, 1 do
d = fade / ( (x-b)^2 + (y-g)^2 + (z-r)^2 )
if cube[z+1][y+1][x+1] ~= nil then
cube[z+1][y+1][x+1] = cube[z+1][y+1][x+1] + d
else
cube[z+1][y+1][x+1] = d
end
end;end;end
end
function findVoid(cube,sha)
weakest = 999999999999
weak_i = {-1,-1,-1}
for z = 0, sha-1, 1 do
for y = 0, sha-1, 1 do
for x = 0, sha-1, 1 do
w = cube[z+1][y+1][x+1]
if w <= weakest then weakest = w; weak_i = {z,y,x}; end
end;end;end
return weak_i[1],weak_i[2],weak_i[3]
end
--
if OK == true then
cube = initColorCube(SHADES)
-- Fill cube with initial colors
for n = 0, ini-1, 1 do
r,g,b = getcolor(n)
div = SHADES
addColor2Cube(cube,SHADES,math.floor(r/div),math.floor(g/div),math.floor(b/div))
end
if ini == 0 then -- With no inital color, some inital data must be added to the colorcube.
addColor2Cube(cube,SHADES,0,0,0)
setcolor(0, 0,0,0)
ini = ini + 1
end
for n = ini, exp, 1 do
r,g,b = findVoid(cube,SHADES)
mult = 255 / (SHADES - 1)
setcolor(n, r*mult,g*mult,b*mult)
addColor2Cube(cube,SHADES,r,g,b)
end
end

View File

@ -0,0 +1,20 @@
--PALETTE Modify: Inverted RGB
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
for c = 0, 255, 1 do
r,g,b = getcolor(c)
r2 = (g+b)/2
g2 = (r+b)/2
b2 = (r+g)/2
setcolor(c, r2,g2,b2)
end

View File

@ -0,0 +1,32 @@
--PALETTE Set: 3 Bit (8 Primaries)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Generate palette of all colors possible with a given number of shades for each channel
-- 2 shades = 1 bit / channel = 3 bit palette = 2^3 colors = 8 colors
-- 4 shades = 2 bit / channel = 6 bit palette = 2^6 colors = 64 colors
-- Channel shades (shades = 2 ^ bit-depth)
shades = 2
mult = 255 / (shades-1)
colors = {}
col = 0
for r = 0, shades-1, 1 do
for g = 0, shades-1, 1 do
for b = 0, shades-1, 1 do
col = col + 1
colors[col] = { r*mult, g*mult, b*mult }
end
end
end
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end

View File

@ -0,0 +1,32 @@
--PALETTE Set: Full 6 Bit (64 colors)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Generate palette of all colors possible with a given number of shades for each channel
-- 2 shades = 1 bit / channel = 3 bit palette = 2^3 colors = 8 colors
-- 4 shades = 2 bit / channel = 6 bit palette = 2^6 colors = 64 colors
-- Channel shades (shades = 2 ^ bit-depth)
shades = 4
mult = 255 / (shades-1)
colors = {}
col = 0
for r = 0, shades-1, 1 do
for g = 0, shades-1, 1 do
for b = 0, shades-1, 1 do
col = col + 1
colors[col] = { r*mult, g*mult, b*mult }
end
end
end
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end

View File

@ -0,0 +1,43 @@
--PALETTE Set: C64 Palette (16 colors)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
OK,clean = inputbox("C64 Palette:", "Remove old palette", 0, 0,1,0
);
colors = {{0, 0, 0}, -- 0 Black
{62, 49,162}, -- 1 D.Blue
{87, 66, 0}, -- 2 Brown
{140, 62, 52}, -- 3 D.Red
{84, 84, 84}, -- 4 D.Grey
{141, 72,179}, -- 5 Purple
{144, 95, 37}, -- 6 Orange
{124,112,218}, -- 7 B.Blue
{128,128,128}, -- 8 Grey
{104,169, 65}, -- 9 Green
{187,119,109}, -- 10 B.Red
{122,191,199}, -- 11 Cyan
{171,171,171}, -- 12 B.Grey
{208,220,113}, -- 13 Yellow
{172,234,136}, -- 14 B.Green
{255,255,255} -- 15 White
}
if OK == true then
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end
if clean == 1 then
for c = #colors+1, 255, 1 do
setcolor(c-1,0,0,0)
end
end
end

View File

@ -0,0 +1,55 @@
--PALETTE Adjust: Shift Hue v0.9
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
--Shift_degrees = 45
--ok, w, h, xflip, yflip = inputbox("Modify brush",
-- "Width", w, 1,100,0,
-- "Height", h, 1,100,0,
-- "X-Flip", 0, 0, 1,0,
-- "Y-Flip", 0, 0, 1,0
--);
OK,Shift_degrees = inputbox("Shift Hue v0.9","Degrees", 45, 0,360,3);
--
function shiftHUE(r,g,b,deg) -- V1.3 R.Fhager 2007, adopted from Evalion
local c,h,mi,mx,d,s,p,i,f,q,t
c = {g,b,r}
mi = math.min(r,g,b)
mx = math.max(r,g,b); v = mx;
d = mx - mi;
s = 0; if mx ~= 0 then s = d/mx; end
p = 1; if g ~= mx then p = 2; if b ~= mx then p = 0; end; end
if s~=0 then
h=(deg/60+(6+p*2+(c[1+p]-c[1+(p+1)%3])/d))%6;
i=math.floor(h);
f=h-i;
p=v*(1-s);
q=v*(1-s*f);
t=v*(1-s*(1-f));
c={v,q,p,p,t,v}
r = c[1+i]
g = c[1+(i+4)%6]
b = c[1+(i+2)%6]
end
return r,g,b
end
--
if OK == true then
for c = 0, 255, 1 do
r,g,b = getcolor(c)
setcolor(c, shiftHUE(r,g,b,Shift_degrees))
end
end

View File

@ -0,0 +1,79 @@
--PICTURE (part of): 2 Isometric v0.1b
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- Color 0 is assumed to be the background
--
iso = {{0, 0, 1, 1, 1, 1, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1},
{2, 2, 1, 1, 1, 1, 3, 3},
{2, 2, 2, 2, 3, 3, 3, 3},
{2, 2, 2, 2, 3, 3, 3, 3},
{2, 2, 2, 2, 3, 3, 3, 3},
{0, 0, 2, 2, 3, 3, 0, 0}}
isowidth = 8
isoheight = 7
xoff = 0.5
yoff = 0
xstep = 4
ystep = 2
zstep = 4
-- Part of screen from top-left (4 = 1/4)
xsize = 5
ysize = 4
w, h = getpicturesize()
xo = math.floor(w * xoff)
-- just don't render more than can be fittted right now
w = math.floor(w / xsize)
h = math.floor(h / ysize)
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
isox = x * xstep - y * xstep
isoy = y * ystep + x * ystep
cb = getbackuppixel(x,y)
--
if cb ~= 0 then
r,g,b = getbackupcolor(cb);
c1 = matchcolor(r,g,b);
c2 = matchcolor(r+64, g+64, b+64);
c3 = matchcolor(r-64, g-64, b-64);
cols = {0,c1,c2,c3}
for iy = 1, isoheight, 1 do
for ix = 1, isowidth, 1 do
i = iso[iy][ix]
c = cols[i+1]
if i ~= 0 then putpicturepixel(xo + isox+ix-1, isoy+iy-1, c); end
end
end
end
--
end
end

View File

@ -0,0 +1,61 @@
--PICTURE: Rainbow - Dark to Bright
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
--
--
function shiftHUE(r,g,b,deg) -- V1.3 R.Fhager 2007, adopted from Evalion
local c,h,mi,mx,d,s,p,i,f,q,t
c = {g,b,r}
mi = math.min(r,g,b)
mx = math.max(r,g,b); v = mx;
d = mx - mi;
s = 0; if mx ~= 0 then s = d/mx; end
p = 1; if g ~= mx then p = 2; if b ~= mx then p = 0; end; end
if s~=0 then
h=(deg/60+(6+p*2+(c[1+p]-c[1+(p+1)%3])/d))%6;
i=math.floor(h);
f=h-i;
p=v*(1-s);
q=v*(1-s*f);
t=v*(1-s*(1-f));
c={v,q,p,p,t,v}
r = c[1+i]
g = c[1+(i+4)%6]
b = c[1+(i+2)%6]
end
return r,g,b
end
--
w, h = getpicturesize()
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
-- Fractionalize image dimensions
ox = x / w;
oy = y / h;
r = 255 * math.sin(oy * 2)
g = (oy-0.5)*512 * oy
b = (oy-0.5)*512 * oy
r, g, b = shiftHUE(r,g,b,ox * 360);
c = matchcolor(math.max(0,math.min(255,r)),math.max(0,math.min(255,g)),math.max(0,math.min(255,b)))
putpicturepixel(x, y, c);
end
end

View File

@ -0,0 +1,48 @@
--PICTURE: Pattern - Sierpinsky carpet v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
--
frac = {{1,1,1},{1,0,1},{1,1,1}}
iter = 6
--
function pattern(x,y,p,n,i) -- Fractal Pattern V1.0 by Richard Fhager (mod allows for wrapping)
py = #p
px = #p[1]
while ((p[1+math.abs(math.floor(y*py))%py][1+math.abs(math.floor(x*px))%px]) == 1 and n<i) do
x=x*px-math.floor(x*px);
y=y*py-math.floor(y*py);
n = n+1
end
return 1 - n/i;
end
--
w, h = getpicturesize()
rp,gp,bp = getcolor(getforecolor())
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
ox = x / w;
oy = y / h;
f = pattern(ox,oy,frac,0,iter);
c = matchcolor(rp*f,gp*f,bp*f)
putpicturepixel(x, y, c);
end
end

View File

@ -0,0 +1,46 @@
--PICTURE: Pattern - Sierpinsky triangle v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
--
frac = {{1,1},{1,0}}
iter = 15
--
function pattern(x,y,p,n,i) -- Fractal Pattern V1.0 by Richard Fhager (mod allows for wrapping)
py = #p
px = #p[1]
while ((p[1+math.abs(math.floor(y*py))%py][1+math.abs(math.floor(x*px))%px]) == 1 and n<i) do
x=x*px-math.floor(x*px);
y=y*py-math.floor(y*py);
n = n+1
end
return 1 - n/i;
end
--
w, h = getpicturesize()
rp,gp,bp = getcolor(getforecolor())
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
ox = x / w;
oy = y / h;
f = pattern(ox,oy,frac,0,iter);
c = matchcolor(rp*f,gp*f,bp*f)
putpicturepixel(x, y, c);
end
end

View File

@ -0,0 +1,45 @@
--SCENE: Remap pic to RGB, diag.dith
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Set Palette (to a predefined one)
colors = {{ 0, 0, 0},
{255, 0, 0},
{ 0,255, 0},
{ 0, 0,255}
}
chm = {1,0,0}
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end
for c = #colors, 255, 1 do
setcolor(c,0,0,0)
end
w, h = getpicturesize()
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
r,g,b = getbackupcolor(getbackuppixel(x,y));
rn = r * chm[1+(y+0+x)%3]
gn = g * chm[1+(y+1+x)%3]
bn = b * chm[1+(y+2+x)%3]
n = matchcolor(rn,gn,bn);
putpicturepixel(x, y, n);
end
end

View File

@ -0,0 +1,62 @@
--SCENE: Remap pic 2 RGB, 1lineED-dith. (Same line simple error-diffusion dither)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
power = 0.615
c1 = 0.8 -- Error weight (white is green)
c2 = 0.2 -- RGB weight (white is r+g+b)
-- Set Palette (to a predefined one)
colors = {{ 0, 0, 0},
{255, 0, 0},
{ 0,255, 0},
{ 0, 0,255}
}
chm = {1,0,0}
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end
for c = #colors, 255, 1 do
setcolor(c,0,0,0)
end
w, h = getpicturesize()
for y = 0, h - 1, 1 do
re = 0
ge = 0
be = 0
for x = (y%2), w - 1, 1 do
r,g,b = getbackupcolor(getbackuppixel(x,y));
rn = re * c1 + r * chm[1+(y+0+x)%3] * c2
gn = ge * c1 + g * chm[1+(y+1+x)%3] * c2
bn = be * c1 + b * chm[1+(y+2+x)%3] * c2
n = matchcolor(rn,gn,bn);
putpicturepixel(x, y, n);
rn,gn,bn = getcolor(getpicturepixel(x,y));
re = (re + (r - rn)) * power
ge = (ge + (g - gn)) * power
be = (be + (b - bn)) * power
end
end

View File

@ -0,0 +1,72 @@
--SCENE: Remap pic to 3bit, LineEDdith. (Same line simple error-diffusion dither)
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
--
-- Just a demonstration.
--
power = 0.6
-- Channel shades (shades = 2 ^ bit-depth)
shades = 2
mult = 255 / (shades-1)
colors = {}
col = 0
for r = 0, shades-1, 1 do
for g = 0, shades-1, 1 do
for b = 0, shades-1, 1 do
col = col + 1
colors[col] = { r*mult, g*mult, b*mult }
end
end
end
for c = 1, #colors, 1 do
setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
end
for c = #colors, 255, 1 do
setcolor(c,0,0,0)
end
w, h = getpicturesize()
for y = 0, h - 1, 1 do
re = 0
ge = 0
be = 0
for x = (y%2), w - 1, 1 do
r,g,b = getbackupcolor(getbackuppixel(x,y));
rn = re + r
gn = ge + g
bn = be + b
n = matchcolor(rn,gn,bn);
putpicturepixel(x, y, n);
rn,gn,bn = getcolor(getpicturepixel(x,y));
re = (re + (r - rn)) * power
ge = (ge + (g - gn)) * power
be = (be + (b - bn)) * power
end
end