* Add scripts from dawnbringer : 3D palette viewer and applycolor (with tint and colorize effects)
* Add the dawnbringer lib Some changes were made * Remove line and filled circle functions from dawnbringer lib * Add C replacement (slightly faster, and useful enough to be part of core) git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1730 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
c80ec5edbf
commit
f6da992038
431
share/grafx2/scripts/ani_db_3DPalette.lua
Normal file
431
share/grafx2/scripts/ani_db_3DPalette.lua
Normal file
@ -0,0 +1,431 @@
|
|||||||
|
--3D-Palette viwer V0.7 (HSL-models added, 3D-World added, Pen-color only cycles thru unique colors, InputBox)
|
||||||
|
--by Richard 'Dawnbringer' Fhager
|
||||||
|
|
||||||
|
-- Mouse: Rotate Cube (Stops animation)
|
||||||
|
-- Arrow-keys: Move Cube (in 3D world)
|
||||||
|
-- F1: Start/Stop animation
|
||||||
|
-- F2: Reset
|
||||||
|
-- F3: Increase Color-Size
|
||||||
|
-- F4: Decrease Color-Size
|
||||||
|
-- F5: (Wip) Cycle thru selected PenColor (Note that only unique colors are displayed)
|
||||||
|
-- F9: RGB-space model
|
||||||
|
--F10: HSL-space model
|
||||||
|
--F11: HSLcubic-space model
|
||||||
|
-- "+" (Num): Zoom In
|
||||||
|
-- "-" (Num): Zoom Out
|
||||||
|
-- Esc: Exit script
|
||||||
|
|
||||||
|
require("dawnbringer_lib")
|
||||||
|
|
||||||
|
|
||||||
|
BRIDIAG_SHOW = 1 -- Show brightness/Grayscale diagonal (1 = on, 0 = off)
|
||||||
|
ANIM = 1 -- Animation (1 = on, 0 = off)
|
||||||
|
BOX_DRK = 8 -- Darkest color used for box (0-255)
|
||||||
|
BOX_BRI = 112 -- Brightest color used for box (0-255)
|
||||||
|
COLSIZE_BASE = 26 -- Colors base size (value to adjusted by palette-size, with 2 cols maxsize is v / 1.23)
|
||||||
|
|
||||||
|
--
|
||||||
|
OK,RGB,HSL,HSLC,BOX_BRI,COLSIZE_BASE,SET800x600 = inputbox("3D-Palette Viever Settings",
|
||||||
|
|
||||||
|
"1. RGB space [F9]", 1, 0,1,-1,
|
||||||
|
"2. HSL space [F10]", 0, 0,1,-1,
|
||||||
|
"3. HSL-cubic space [F11]",0, 0,1,-1,
|
||||||
|
"Box Brightness (16-255)", BOX_BRI, 16,255,0,
|
||||||
|
"Col Size (1-100) [F3/F4]", COLSIZE_BASE, 1,100,0,
|
||||||
|
"Set Screen to 800x600", 1,0,1,0
|
||||||
|
|
||||||
|
);
|
||||||
|
--
|
||||||
|
|
||||||
|
if OK then
|
||||||
|
|
||||||
|
if SET800x600 == 1 then setpicturesize(800,600); end
|
||||||
|
|
||||||
|
SPACE = "rgb"
|
||||||
|
FORM = "cube"
|
||||||
|
if HSL == 1 then
|
||||||
|
SPACE = "hsl"
|
||||||
|
FORM = "cylinder"
|
||||||
|
end
|
||||||
|
if HSLC == 1 then
|
||||||
|
SPACE = "hsl_cubic"
|
||||||
|
FORM = "cube"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
pal = db.fixPalette(db.makePalList(256))
|
||||||
|
|
||||||
|
FG = getforecolor()
|
||||||
|
BG = getbackcolor()
|
||||||
|
|
||||||
|
palcol = FG
|
||||||
|
|
||||||
|
--
|
||||||
|
function initColors(space)
|
||||||
|
for n = 1, #pal, 1 do
|
||||||
|
c = pal[n];
|
||||||
|
if space == "rgb" then
|
||||||
|
cols[n] = {c[1]/128-1,c[2]/128-1,c[3]/128-1,c[4]};
|
||||||
|
end
|
||||||
|
if space == "hsl_cubic" then
|
||||||
|
cols[n] = {}
|
||||||
|
cols[n][1] = (db.getHUE(c[1],c[2],c[3],0) / 6.0 * 255) / 128 - 1
|
||||||
|
cols[n][2] = (db.getSaturation(c[1],c[2],c[3])) / 128 - 1
|
||||||
|
cols[n][3] = (db.getLightness(c[1],c[2],c[3])) / 128 - 1
|
||||||
|
cols[n][4] = c[4]
|
||||||
|
end
|
||||||
|
if space == "hsl" then
|
||||||
|
cols[n] = {}
|
||||||
|
hue = db.getHUE(c[1],c[2],c[3],0) / 6.0 * math.pi*2
|
||||||
|
rad = db.getSaturation(c[1],c[2],c[3]) / 256
|
||||||
|
cols[n][1] = math.cos(hue) * rad
|
||||||
|
cols[n][2] = math.sin(hue) * rad
|
||||||
|
cols[n][3] = (db.getLightness(c[1],c[2],c[3])) / 128 - 1
|
||||||
|
cols[n][4] = c[4]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--
|
||||||
|
|
||||||
|
cols = {} -- Make points of palette colors
|
||||||
|
colz = {} -- To hold calculated points
|
||||||
|
initColors(SPACE)
|
||||||
|
|
||||||
|
|
||||||
|
function initPointsAndLines(form,bridiag)
|
||||||
|
if form == "cube" then
|
||||||
|
pts = {{-1,1,-1},{1,1,-1},{1,-1,-1},{-1,-1,-1}, -- The box
|
||||||
|
{-1,1, 1},{1,1, 1},{1,-1, 1},{-1,-1, 1}}
|
||||||
|
lin = {{1,2},{2,3},{3,4},{4,1},{5,6},{6,7},{7,8},{8,5},{1,5},{2,6},{3,7},{4,8}} -- Box Lines
|
||||||
|
if bridiag == 1 then lin[13] = {4,6}; end
|
||||||
|
end
|
||||||
|
if form == "cylinder" then
|
||||||
|
p = 28
|
||||||
|
pts = {}
|
||||||
|
lin = {}
|
||||||
|
for n = 1, p, 1 do
|
||||||
|
x = math.cos(math.pi*2 / p * (n-1))
|
||||||
|
y = math.sin(math.pi*2 / p * (n-1))
|
||||||
|
pts[n] = {x,y,-1}
|
||||||
|
lin[n] = {n,1 + (n%p)}
|
||||||
|
pts[n + p] = {x,y,1}
|
||||||
|
lin[n + p] = {n+p,p + 1 + (n%p)}
|
||||||
|
end
|
||||||
|
lin[p*2+1] = {1,p+1} -- Red (0 degrees)
|
||||||
|
lin[p*2+2] = {p+1,p+1+math.ceil(p/2)} -- Lightness end (needs an even # of points to work)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
boxp = {} -- To hold the calculated points
|
||||||
|
initPointsAndLines(FORM,BRIDIAG_SHOW)
|
||||||
|
|
||||||
|
w,h = getpicturesize()
|
||||||
|
CX,CY = w/2, h/2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function initAndReset()
|
||||||
|
XANG, YANG, ZANG, ZOOM, COLSIZE_ADJ, XD, YD, WORLD_X, WORLD_Y = 0,0,0,0,0,0,0,0,0
|
||||||
|
end
|
||||||
|
|
||||||
|
initAndReset()
|
||||||
|
|
||||||
|
SIZE = math.min(w,h)/4
|
||||||
|
DIST = 5 -- Distance perspective modifier, ~5 is nominal, more means "less 3D"
|
||||||
|
|
||||||
|
CMAXSIZE = math.floor(COLSIZE_BASE / ((#pal)^0.3))
|
||||||
|
--CMAXSIZE = 8
|
||||||
|
CMINSIZE = 1 -- Negative values are ok. Color are never smaller than 1 pix
|
||||||
|
|
||||||
|
BOX_LINE_DIV = 20 -- Number of colors/segments that a box-line can be divided into (depth)
|
||||||
|
BOX_DIV_MULT = BOX_LINE_DIV / (math.sqrt(3)*2)
|
||||||
|
|
||||||
|
-- Box depth colors
|
||||||
|
box_div = {}
|
||||||
|
for n = 0, BOX_LINE_DIV-1, 1 do
|
||||||
|
c = BOX_DRK + (BOX_BRI / (BOX_LINE_DIV - 1)) * n
|
||||||
|
--box_div[BOX_LINE_DIV - n] = matchcolor(c,c,c)
|
||||||
|
box_div[BOX_LINE_DIV - n] = db.getBestPalMatchHYBRID({c,c,c},pal,0.5,true)
|
||||||
|
end
|
||||||
|
|
||||||
|
--BOX_COL = matchcolor(80,80,80)
|
||||||
|
BKG_COL = matchcolor(0,0,0)
|
||||||
|
--CUR_COL = matchcolor(112,112,112)
|
||||||
|
|
||||||
|
|
||||||
|
function rotate3D(x,y,z,Xsin,Ysin,Zsin,Xcos,Ycos,Zcos) -- PrecCalced cos&sin for speed
|
||||||
|
|
||||||
|
local x1,x2,x3,y1,y2,y3,f,xp,yp
|
||||||
|
|
||||||
|
x1 = x
|
||||||
|
y1 = y * Xcos + z * Xsin
|
||||||
|
z1 = z * Xcos - y * Xsin
|
||||||
|
|
||||||
|
x2 = x1 * Ycos - z1 * Ysin
|
||||||
|
y2 = y1
|
||||||
|
z2 = x1 * Ysin + z1 * Ycos
|
||||||
|
|
||||||
|
x3 = x2 * Zcos - y2 * Zsin
|
||||||
|
y3 = x2 * Zsin + y2 * Zcos
|
||||||
|
z3 = z2
|
||||||
|
|
||||||
|
return x3,y3,z3
|
||||||
|
end
|
||||||
|
|
||||||
|
function do3D(x,y,z,zoom,dist,Xsin,Ysin,Zsin,Xcos,Ycos,Zcos) -- PrecCalced cos&sin for speed
|
||||||
|
|
||||||
|
local x1,x2,x3,y1,y2,y3,f,xp,yp
|
||||||
|
|
||||||
|
x1 = x
|
||||||
|
y1 = y * Xcos + z * Xsin
|
||||||
|
z1 = z * Xcos - y * Xsin
|
||||||
|
|
||||||
|
x2 = x1 * Ycos - z1 * Ysin
|
||||||
|
y2 = y1
|
||||||
|
z2 = x1 * Ysin + z1 * Ycos
|
||||||
|
|
||||||
|
x3 = x2 * Zcos - y2 * Zsin
|
||||||
|
y3 = x2 * Zsin + y2 * Zcos
|
||||||
|
z3 = z2
|
||||||
|
|
||||||
|
f = dist/(z3 + dist + zoom)
|
||||||
|
xp = x3 * f
|
||||||
|
yp = y3 * f
|
||||||
|
|
||||||
|
return xp,yp,z3
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function draw3Dline(x1,y1,z1,x2,y2,z2,div,mult,depthlist)
|
||||||
|
local s,xt,yt,xd,yd,zd,xf,yf
|
||||||
|
xd = (x2 - x1) / div
|
||||||
|
yd = (y2 - y1) / div
|
||||||
|
zd = (z2 - z1) / div
|
||||||
|
xf,yf = x1,y1
|
||||||
|
|
||||||
|
for s = 1, div, 1 do
|
||||||
|
-- Depth assumes a 1-Box (z ranges from -sq(3) to sq(3))
|
||||||
|
depth = math.floor(1 + (z1+zd*s + 1.732) * mult)
|
||||||
|
xt = x1 + xd*s -- + math.random()*8
|
||||||
|
yt = y1 + yd*s -- + math.random()*8
|
||||||
|
c = depthlist[depth]
|
||||||
|
if c == null then c = 1; end -- Something isn't perfect, error is super rare but this controls it
|
||||||
|
drawline(xf,yf,xt,yt,c)
|
||||||
|
xf = xt
|
||||||
|
yf = yt
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function killinertia()
|
||||||
|
XD = 0
|
||||||
|
YD = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
-- If using 1-box, z is -sq(3) to sq(3)
|
||||||
|
minz = math.sqrt(3)
|
||||||
|
totz = minz * 2
|
||||||
|
maxrad = CMAXSIZE - CMINSIZE
|
||||||
|
|
||||||
|
q = 0
|
||||||
|
delay = 4
|
||||||
|
move = 0.03
|
||||||
|
|
||||||
|
while 1 < 2 do
|
||||||
|
|
||||||
|
-- Time-for-space-wiggle...or somekindof attempt
|
||||||
|
--WORLD_X = -move
|
||||||
|
--q = (q + 1) % delay
|
||||||
|
--if q < delay/2 then WORLD_X = move; end
|
||||||
|
|
||||||
|
clearpicture(BKG_COL)
|
||||||
|
|
||||||
|
Xsin = math.sin(XANG); Xcos = math.cos(XANG)
|
||||||
|
Ysin = math.sin(YANG); Ycos = math.cos(YANG)
|
||||||
|
Zsin = math.sin(ZANG); Zcos = math.cos(ZANG)
|
||||||
|
|
||||||
|
-- Rotate Box points
|
||||||
|
for n = 1, #pts, 1 do
|
||||||
|
p = pts[n]
|
||||||
|
x,y,z = p[1],p[2],p[3]
|
||||||
|
XP,YP,zp = rotate3D(x,y,z,Xsin,Ysin,Zsin,Xcos,Ycos,Zcos)
|
||||||
|
boxp[n] = {XP,YP,zp}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Rotate Colors in palette
|
||||||
|
for n = 1, #cols, 1 do
|
||||||
|
p = cols[n]
|
||||||
|
x,y,z,c = p[1],p[2],p[3],p[4]
|
||||||
|
XP,YP,zp = rotate3D(x,y,z,Xsin,Ysin,Zsin,Xcos,Ycos,Zcos)
|
||||||
|
colz[n] = {XP,YP,zp,c}
|
||||||
|
end
|
||||||
|
|
||||||
|
------------------------------------
|
||||||
|
-- Control world
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
-- Calculate points anew
|
||||||
|
|
||||||
|
-- Worldize Box points
|
||||||
|
for n = 1, #boxp, 1 do
|
||||||
|
s = SIZE
|
||||||
|
v = boxp[n]
|
||||||
|
x = v[1] + WORLD_X
|
||||||
|
y = v[2] + WORLD_Y
|
||||||
|
z = v[3]
|
||||||
|
f = DIST/(z + DIST + ZOOM)
|
||||||
|
XP = CX + x * f * s
|
||||||
|
YP = CY + y * f * s
|
||||||
|
boxp[n] = {XP,YP,z}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Worldize Colors in palette
|
||||||
|
for n = 1, #colz, 1 do
|
||||||
|
s = SIZE
|
||||||
|
v = colz[n]
|
||||||
|
x = v[1] + WORLD_X
|
||||||
|
y = v[2] + WORLD_Y
|
||||||
|
z = v[3]
|
||||||
|
c = v[4]
|
||||||
|
f = DIST/(z + DIST + ZOOM)
|
||||||
|
XP = CX + x * f * s
|
||||||
|
YP = CY + y * f * s
|
||||||
|
colz[n] = {XP,YP,z,c}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
-- Brightness Diagonal
|
||||||
|
--if BRIDIAG_SHOW == 1 then
|
||||||
|
-- p1 = boxp[4]
|
||||||
|
-- p2 = boxp[6]
|
||||||
|
-- x1,y1,z1 = p1[1],p1[2],p1[3]
|
||||||
|
-- x2,y2,z2 = p2[1],p2[2],p2[3]
|
||||||
|
-- draw3Dline(x1,y1,z1,x2,y2,z2,BOX_LINE_DIV,BOX_DIV_MULT,box_div)
|
||||||
|
--end
|
||||||
|
|
||||||
|
-- sort on z
|
||||||
|
db.sorti(colz,3)
|
||||||
|
|
||||||
|
-- Draw colors
|
||||||
|
for n = #colz, 1, -1 do
|
||||||
|
p = colz[n]
|
||||||
|
XP,YP,zp,c = p[1],p[2],p[3],p[4]
|
||||||
|
|
||||||
|
radius = CMINSIZE + maxrad - (zp+minz) / totz * maxrad
|
||||||
|
dorad = math.floor(radius - ZOOM*2 + COLSIZE_ADJ)
|
||||||
|
|
||||||
|
if dorad >= 1 then
|
||||||
|
drawdisk(XP,YP,dorad,c)
|
||||||
|
--db.drawRectangle(XP,YP,dorad,dorad,c)
|
||||||
|
else putpicturepixel(XP,YP,c)
|
||||||
|
end
|
||||||
|
|
||||||
|
if c == FG or c == BG then
|
||||||
|
sz = math.max(3,dorad + 3)
|
||||||
|
if c == BKG_COL then v = (c+128) % 255; c = matchcolor(v,v,v); end
|
||||||
|
db.drawRectangleLine(XP-sz,YP-sz,sz*2,sz*2,c)
|
||||||
|
end
|
||||||
|
|
||||||
|
end -- colz
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Draw box
|
||||||
|
for n = 1, #lin, 1 do
|
||||||
|
|
||||||
|
l = lin[n]
|
||||||
|
p1 = boxp[l[1]]
|
||||||
|
p2 = boxp[l[2]]
|
||||||
|
x1,y1,z1 = p1[1],p1[2],p1[3]
|
||||||
|
x2,y2,z2 = p2[1],p2[2],p2[3]
|
||||||
|
draw3Dline(x1,y1,z1,x2,y2,z2,BOX_LINE_DIV,BOX_DIV_MULT,box_div)
|
||||||
|
|
||||||
|
end -- eof box
|
||||||
|
|
||||||
|
--updatescreen(); if (waitbreak(0.00)==1) then return; end
|
||||||
|
|
||||||
|
repeat
|
||||||
|
|
||||||
|
old_key = key;
|
||||||
|
old_mouse_x = mouse_x;
|
||||||
|
old_mouse_y = mouse_y;
|
||||||
|
old_mouse_b = mouse_b;
|
||||||
|
|
||||||
|
updatescreen()
|
||||||
|
moved, key, mouse_x, mouse_y, mouse_b = waitinput(0)
|
||||||
|
|
||||||
|
if mouse_b == 1 then ANIM = 0; end
|
||||||
|
|
||||||
|
if (key==27) then
|
||||||
|
return;
|
||||||
|
end
|
||||||
|
|
||||||
|
if (key==282) then ANIM = (ANIM+1) % 2; end -- F1: Stop/Start Animation
|
||||||
|
if (key==283) then initAndReset(); end -- F2: Reset all values
|
||||||
|
if (key==284) then COLSIZE_ADJ = COLSIZE_ADJ + 0.5; end -- F3
|
||||||
|
if (key==285) then COLSIZE_ADJ = COLSIZE_ADJ - 0.5; end -- F4
|
||||||
|
|
||||||
|
if (key==286) then
|
||||||
|
--FG = (FG + 1) % 255;
|
||||||
|
palcol = (palcol + 1) % #pal
|
||||||
|
FG = pal[palcol+1][4]
|
||||||
|
setforecolor(FG);
|
||||||
|
setcolor(0,getcolor(0)) -- Force update of palette until setforecolor() is fixed
|
||||||
|
end -- F5
|
||||||
|
|
||||||
|
if (key==290) then -- F9
|
||||||
|
initColors("rgb")
|
||||||
|
initPointsAndLines("cube",BRIDIAG_SHOW)
|
||||||
|
end
|
||||||
|
if (key==291) then -- F10
|
||||||
|
initColors("hsl")
|
||||||
|
initPointsAndLines("cylinder", 0) -- Bridiag won't show even if turned on, it's only for cube
|
||||||
|
end
|
||||||
|
if (key==292) then -- F11
|
||||||
|
initColors("hsl_cubic")
|
||||||
|
initPointsAndLines("cube",BRIDIAG_SHOW)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (key==269) then ZOOM = ZOOM + 0.1; end
|
||||||
|
if (key==270) then ZOOM = ZOOM - 0.1; end
|
||||||
|
SPEED = math.pi / 100
|
||||||
|
|
||||||
|
|
||||||
|
if (key==273) then WORLD_Y = WORLD_Y - 0.05; killinertia(); end
|
||||||
|
if (key==274) then WORLD_Y = WORLD_Y + 0.05; killinertia(); end
|
||||||
|
|
||||||
|
if (key==276) then WORLD_X = WORLD_X - 0.05; killinertia(); end
|
||||||
|
if (key==275) then WORLD_X = WORLD_X + 0.05; killinertia(); end
|
||||||
|
|
||||||
|
until ((mouse_b == 1 and (old_mouse_x~=mouse_x or old_mouse_y~=mouse_y)) or key~=0 or ANIM==1 or math.abs(XD)>0.01 or math.abs(YD)>0.01);
|
||||||
|
|
||||||
|
if ANIM == 0 then
|
||||||
|
if (mouse_b==1 and (old_mouse_x~=mouse_x or old_mouse_y~=mouse_y)) then -- Inertia
|
||||||
|
XD = (mouse_y - old_mouse_y)*0.005
|
||||||
|
YD = (mouse_x - old_mouse_x)*0.005
|
||||||
|
else
|
||||||
|
XD = XD*0.92
|
||||||
|
YD = YD*0.92
|
||||||
|
end
|
||||||
|
XANG = ((XANG - XD) % (math.pi*2));
|
||||||
|
YANG = ((YANG + YD) % (math.pi*2));
|
||||||
|
ZANG = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if ANIM == 1 then
|
||||||
|
XANG = (XANG + math.pi/300) % (math.pi*2)
|
||||||
|
YANG = (YANG + math.pi/500) % (math.pi*2)
|
||||||
|
ZANG = (ZANG + math.pi/1000) % (math.pi*2)
|
||||||
|
end
|
||||||
|
|
||||||
|
--XANG = ((CY-mouse_y) / 200 % (math.pi*2));
|
||||||
|
--YANG = ((mouse_x - CX) / 200 % (math.pi*2));
|
||||||
|
--ZANG = 0
|
||||||
|
|
||||||
|
|
||||||
|
statusmessage("X: "..math.floor(XANG*57.3).."°, Y: "..math.floor(YANG*57.3).."°, Z: "..math.floor(ZANG*57.3).."°, Zoom: "..math.floor(-ZOOM*10).." ")
|
||||||
|
end
|
||||||
|
|
||||||
|
end -- OK
|
||||||
125
share/grafx2/scripts/bru_db_ApplyColor.lua
Normal file
125
share/grafx2/scripts/bru_db_ApplyColor.lua
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
--BRUSH Remap: Apply PenColor
|
||||||
|
--by Richard Fhager
|
||||||
|
--http://hem.fyristorg.com/dawnbringer/
|
||||||
|
|
||||||
|
-- Copyright 2010 Richard Fhager
|
||||||
|
--
|
||||||
|
-- This program is free software; you can redistribute it and/or
|
||||||
|
-- modify it under the terms of the GNU General Public License
|
||||||
|
-- as published by the Free Software Foundation; version 2
|
||||||
|
-- of the License. See <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
|
--dofile("dawnbringer_lib.lua")
|
||||||
|
require("dawnbringer_lib")
|
||||||
|
|
||||||
|
OK,tin,clz,fade,amt,brikeep,falloff,nobg,briweight = inputbox("Apply PenColor 2 Brush",
|
||||||
|
|
||||||
|
"1. Tint", 1, 0,1,-1,
|
||||||
|
"2. Colorize", 0, 0,1,-1,
|
||||||
|
"BG->FG color Fade", 0, 0,1,0,
|
||||||
|
"AMOUNT % (0-100)", 100, 0,100,0,
|
||||||
|
"Preserve Brightness", 1, 0,1,0,
|
||||||
|
"Bri/Dark FallOff", 1, 0,1,0,
|
||||||
|
"Exclude Background", 1,0,1,0,
|
||||||
|
"ColMatch Bri-Weight %", 25, 0,100,0
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if OK == true then
|
||||||
|
|
||||||
|
function cap(v) return math.min(255,math.max(v,0)); end
|
||||||
|
|
||||||
|
w, h = getbrushsize()
|
||||||
|
|
||||||
|
|
||||||
|
fg = getforecolor()
|
||||||
|
bg = getbackcolor()
|
||||||
|
fR,fG,fB = getcolor(fg)
|
||||||
|
bR,bG,bB = getcolor(bg)
|
||||||
|
|
||||||
|
pal = db.fixPalette(db.makePalList(256))
|
||||||
|
if nobg == 1 then
|
||||||
|
pal = db.stripIndexFromPalList(pal,bg) -- Remove background color from pallist
|
||||||
|
end
|
||||||
|
|
||||||
|
amtA = amt / 100
|
||||||
|
amtR = 1 - amtA
|
||||||
|
|
||||||
|
-- Normalize Pen Color
|
||||||
|
lev = (fR+fG+fB)/3
|
||||||
|
fR = fR - lev
|
||||||
|
fG = fG - lev
|
||||||
|
fB = fB - lev
|
||||||
|
|
||||||
|
---------------------------------------------------
|
||||||
|
-- Colorize (Colourant) (just apply colorbalance)
|
||||||
|
-- Tint (make grayscale and apply colorbalance)
|
||||||
|
--
|
||||||
|
-- I think it should be the other way around since colorize is the process of adding color to B&W film...
|
||||||
|
-- But this is the what Brilliance and others call it
|
||||||
|
--
|
||||||
|
if clz == 1 or tin == 1 then
|
||||||
|
cols = {}
|
||||||
|
for n = 0, 255, 1 do
|
||||||
|
|
||||||
|
r,g,b = getcolor(n)
|
||||||
|
a = db.getBrightness(r,g,b)
|
||||||
|
|
||||||
|
|
||||||
|
mR,mG,mB = fR,fG,fB
|
||||||
|
|
||||||
|
-- Fade between bg & fg pencolor across dark-bright
|
||||||
|
if fade == 1 then
|
||||||
|
lf = a / 255
|
||||||
|
lr = 1 - lf
|
||||||
|
mR = bR*lr + fR*lf
|
||||||
|
mG = bG*lr + fG*lf
|
||||||
|
mB = bB*lr + fB*lf
|
||||||
|
lev = (mR+mG+mB)/3
|
||||||
|
mR = mR - lev
|
||||||
|
mG = mG - lev
|
||||||
|
mB = mB - lev
|
||||||
|
end
|
||||||
|
|
||||||
|
fr,fg,fb = mR,mG,mB
|
||||||
|
|
||||||
|
|
||||||
|
if brikeep == 1 then
|
||||||
|
-- Loose Brightness preservation (ex: applying full red to dark colors)
|
||||||
|
brin = db.getBrightness(cap(r+mR),cap(g+mG),cap(b+mB))
|
||||||
|
itot = brin - a
|
||||||
|
fr = mR - itot
|
||||||
|
fg = mG - itot
|
||||||
|
fb = mB - itot
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Falloff (Effect weakens at dark and bright colors)
|
||||||
|
if falloff == 1 then
|
||||||
|
fo = 1 - math.abs((a - 127.5)/127.5)^2
|
||||||
|
fr = fr * fo
|
||||||
|
fg = fg * fo
|
||||||
|
fb = fb * fo
|
||||||
|
end
|
||||||
|
|
||||||
|
if tin == 1 then
|
||||||
|
--cols[n+1] = matchcolor((a+fr)*amtA + r*amtR, (a+fg)*amtA + g*amtR, (a+fb)*amtA + b*amtR)
|
||||||
|
cols[n+1] = db.getBestPalMatchHYBRID({(a+fr)*amtA+r*amtR, (a+fg)*amtA + g*amtR, (a+fb)*amtA + b*amtR},pal,briweight / 100,true)
|
||||||
|
end
|
||||||
|
if clz == 1 then
|
||||||
|
--cols[n+1] = matchcolor((r+fr)*amtA + r*amtR, (g+fg)*amtA + g*amtR, (b+fb)*amtA + b*amtR)
|
||||||
|
cols[n+1] = db.getBestPalMatchHYBRID({(r+fr)*amtA+r*amtR, (g+fg)*amtA + g*amtR, (b+fb)*amtA + b*amtR},pal,briweight / 100,true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if nobg == 1 then cols[getbackcolor()+1] = getbackcolor(); end
|
||||||
|
|
||||||
|
for x = 0, w - 1, 1 do
|
||||||
|
for y = 0, h - 1, 1 do
|
||||||
|
putbrushpixel(x, y, cols[getbrushpixel(x,y) + 1]);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
-- eof Colorize & Tint
|
||||||
|
--------------------------------------------------------
|
||||||
|
|
||||||
|
end -- OK
|
||||||
2471
share/grafx2/scripts/libs/dawnbringer_lib.lua
Normal file
2471
share/grafx2/scripts/libs/dawnbringer_lib.lua
Normal file
File diff suppressed because it is too large
Load Diff
121
src/factory.c
121
src/factory.c
@ -348,6 +348,85 @@ int L_PutPicturePixel(lua_State* L)
|
|||||||
return 0; // no values returned for lua
|
return 0; // no values returned for lua
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int L_DrawLine(lua_State* L)
|
||||||
|
{
|
||||||
|
int x1, y1, x2, y2, c;
|
||||||
|
|
||||||
|
int nb_args = lua_gettop(L);
|
||||||
|
|
||||||
|
LUA_ARG_LIMIT(5, "drawline");
|
||||||
|
LUA_ARG_NUMBER(1, "drawline", x1, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(2, "drawline", y1, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(3, "drawline", x2, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(4, "drawline", y2, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(5, "drawline", c, INT_MIN, INT_MAX);
|
||||||
|
|
||||||
|
Pixel_figure = Display_pixel;
|
||||||
|
Draw_line_general(x1, y1, x2, y2, c);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int L_DrawFilledRect(lua_State* L)
|
||||||
|
{
|
||||||
|
int x1, y1, x2, y2, c;
|
||||||
|
|
||||||
|
int nb_args = lua_gettop(L);
|
||||||
|
|
||||||
|
LUA_ARG_LIMIT(5, "drawfilledrect");
|
||||||
|
LUA_ARG_NUMBER(1, "drawfilledrect", x1, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(2, "drawfilledrect", y1, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(3, "drawfilledrect", x2, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(4, "drawfilledrect", y2, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(5, "drawfilledrect", c, INT_MIN, INT_MAX);
|
||||||
|
|
||||||
|
Draw_filled_rectangle(x1, y1, x2, y2, c);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int L_DrawCircle(lua_State* L)
|
||||||
|
{
|
||||||
|
int x1, y1, r, c;
|
||||||
|
|
||||||
|
int nb_args = lua_gettop(L);
|
||||||
|
|
||||||
|
LUA_ARG_LIMIT(4, "drawcircle");
|
||||||
|
LUA_ARG_NUMBER(1, "drawcircle", x1, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(2, "drawcircle", y1, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(3, "drawcircle", r, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(4, "drawcircle", c, INT_MIN, INT_MAX);
|
||||||
|
|
||||||
|
Pixel_figure = Display_pixel;
|
||||||
|
Circle_limit = r*r;
|
||||||
|
Draw_empty_circle_general(x1, y1, r, c);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int L_DrawDisk(lua_State* L)
|
||||||
|
{
|
||||||
|
int x1, y1, r, c;
|
||||||
|
|
||||||
|
int nb_args = lua_gettop(L);
|
||||||
|
|
||||||
|
LUA_ARG_LIMIT(4, "drawdisk");
|
||||||
|
LUA_ARG_NUMBER(1, "drawdisk", x1, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(2, "drawdisk", y1, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(3, "drawdisk", r, INT_MIN, INT_MAX);
|
||||||
|
LUA_ARG_NUMBER(4, "drawdisk", c, INT_MIN, INT_MAX);
|
||||||
|
|
||||||
|
Circle_limit = r*r;
|
||||||
|
Draw_filled_circle(x1, y1, r, c);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int L_GetPicturePixel(lua_State* L)
|
int L_GetPicturePixel(lua_State* L)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
@ -1308,36 +1387,54 @@ void Run_script(const char *script_subdirectory, const char *script_filename)
|
|||||||
L = lua_open();
|
L = lua_open();
|
||||||
putenv("LUA_PATH=libs\\?.lua");
|
putenv("LUA_PATH=libs\\?.lua");
|
||||||
|
|
||||||
|
// writing and reading pixels
|
||||||
lua_register(L,"putbrushpixel",L_PutBrushPixel);
|
lua_register(L,"putbrushpixel",L_PutBrushPixel);
|
||||||
|
lua_register(L,"putpicturepixel",L_PutPicturePixel);
|
||||||
|
lua_register(L, "drawline",L_DrawLine);
|
||||||
|
lua_register(L, "drawfilledrect",L_DrawFilledRect);
|
||||||
|
lua_register(L, "drawcircle",L_DrawCircle);
|
||||||
|
lua_register(L, "drawdisk",L_DrawDisk);
|
||||||
|
|
||||||
lua_register(L,"getbrushpixel",L_GetBrushPixel);
|
lua_register(L,"getbrushpixel",L_GetBrushPixel);
|
||||||
lua_register(L,"getbrushbackuppixel",L_GetBrushBackupPixel);
|
lua_register(L,"getbrushbackuppixel",L_GetBrushBackupPixel);
|
||||||
lua_register(L,"putpicturepixel",L_PutPicturePixel);
|
|
||||||
lua_register(L,"getpicturepixel",L_GetPicturePixel);
|
lua_register(L,"getpicturepixel",L_GetPicturePixel);
|
||||||
lua_register(L,"getlayerpixel",L_GetLayerPixel);
|
lua_register(L,"getlayerpixel",L_GetLayerPixel);
|
||||||
lua_register(L,"getbackuppixel",L_GetBackupPixel);
|
lua_register(L,"getbackuppixel",L_GetBackupPixel);
|
||||||
|
lua_register(L,"getsparelayerpixel",L_GetSpareLayerPixel);
|
||||||
|
lua_register(L,"getsparepicturepixel",L_GetSparePicturePixel);
|
||||||
|
|
||||||
|
|
||||||
|
// resizing stuff
|
||||||
lua_register(L,"setbrushsize",L_SetBrushSize);
|
lua_register(L,"setbrushsize",L_SetBrushSize);
|
||||||
lua_register(L,"setpicturesize",L_SetPictureSize);
|
lua_register(L,"setpicturesize",L_SetPictureSize);
|
||||||
|
|
||||||
lua_register(L,"getbrushsize",L_GetBrushSize);
|
lua_register(L,"getbrushsize",L_GetBrushSize);
|
||||||
lua_register(L,"getpicturesize",L_GetPictureSize);
|
lua_register(L,"getpicturesize",L_GetPictureSize);
|
||||||
|
lua_register(L,"getsparepicturesize",L_GetSparePictureSize);
|
||||||
|
|
||||||
|
// color and palette
|
||||||
lua_register(L,"setcolor",L_SetColor);
|
lua_register(L,"setcolor",L_SetColor);
|
||||||
|
lua_register(L,"setforecolor",L_SetForeColor);
|
||||||
|
lua_register(L,"setbackcolor",L_SetBackColor);
|
||||||
|
|
||||||
lua_register(L,"getcolor",L_GetColor);
|
lua_register(L,"getcolor",L_GetColor);
|
||||||
lua_register(L,"getbackupcolor",L_GetBackupColor);
|
lua_register(L,"getbackupcolor",L_GetBackupColor);
|
||||||
lua_register(L,"matchcolor",L_MatchColor);
|
|
||||||
lua_register(L,"getbrushtransparentcolor",L_GetBrushTransparentColor);
|
lua_register(L,"getbrushtransparentcolor",L_GetBrushTransparentColor);
|
||||||
|
lua_register(L,"getsparecolor",L_GetSpareColor);
|
||||||
|
lua_register(L,"getsparetranscolor",L_GetSpareTransColor);
|
||||||
|
lua_register(L,"getforecolor",L_GetForeColor);
|
||||||
|
lua_register(L,"getbackcolor",L_GetBackColor);
|
||||||
|
lua_register(L,"gettranscolor",L_GetTransColor);
|
||||||
|
|
||||||
|
lua_register(L,"matchcolor",L_MatchColor);
|
||||||
|
|
||||||
|
// ui
|
||||||
lua_register(L,"inputbox",L_InputBox);
|
lua_register(L,"inputbox",L_InputBox);
|
||||||
lua_register(L,"messagebox",L_MessageBox);
|
lua_register(L,"messagebox",L_MessageBox);
|
||||||
lua_register(L,"statusmessage",L_StatusMessage);
|
lua_register(L,"statusmessage",L_StatusMessage);
|
||||||
lua_register(L,"selectbox",L_SelectBox);
|
lua_register(L,"selectbox",L_SelectBox);
|
||||||
lua_register(L,"getforecolor",L_GetForeColor);
|
|
||||||
lua_register(L,"getbackcolor",L_GetBackColor);
|
// misc. stuff
|
||||||
lua_register(L,"setforecolor",L_SetForeColor);
|
|
||||||
lua_register(L,"setbackcolor",L_SetBackColor);
|
|
||||||
lua_register(L,"gettranscolor",L_GetTransColor);
|
|
||||||
lua_register(L,"getsparepicturesize",L_GetSparePictureSize);
|
|
||||||
lua_register(L,"getsparelayerpixel",L_GetSpareLayerPixel);
|
|
||||||
lua_register(L,"getsparepicturepixel",L_GetSparePicturePixel);
|
|
||||||
lua_register(L,"getsparecolor",L_GetSpareColor);
|
|
||||||
lua_register(L,"getsparetranscolor",L_GetSpareTransColor);
|
|
||||||
lua_register(L,"clearpicture",L_ClearPicture);
|
lua_register(L,"clearpicture",L_ClearPicture);
|
||||||
lua_register(L,"wait",L_Wait);
|
lua_register(L,"wait",L_Wait);
|
||||||
lua_register(L,"waitbreak",L_WaitBreak);
|
lua_register(L,"waitbreak",L_WaitBreak);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user