Reorganized scripts, fixed 'memory' not working with subdirectories

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1765 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud
2011-04-03 16:45:10 +00:00
parent 0129bb3590
commit 27e8d15971
38 changed files with 28 additions and 24 deletions

View File

@@ -0,0 +1,124 @@
--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("../libs/dawnbringer_lib.lua")
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

View File

@@ -0,0 +1,31 @@
--BRUSH Distortion: FishEye
--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/>
-- 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,24 @@
--BRUSH Remap: Grayscale (average)
--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/>
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,36 @@
--BRUSH Remap: Grayscale (desaturate)
--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/>
-- 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 = r + (a-r*p)
g = g + (a-g*p)
b = b + (a-b*p)
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,34 @@
--BRUSH: Halfsize with smoothscaling
--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/>
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,42 @@
--BRUSH Distortion: Waves v1.0
--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/>
-- 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

@@ -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
dofile("../libs/dawnbringer_lib.lua")
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

View File

@@ -0,0 +1,68 @@
--PICTURE scene: Ellipse update-demo (anim)
--Demonstrates 'interactive' features.
--by Richard Fhager
-- Copyright 2011 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/>
--
-- rot: Rotation in degrees
-- stp: Step is # of line segments (more is "better")
-- a & b are axis-radius
function ellipse2(x,y,a,b,stp,rot,col)
local n,m=math,rad,al,sa,ca,sb,cb,ox,oy,x1,y1,ast
m = math; rad = m.pi/180; ast = rad * 360/stp;
sb = m.sin(-rot * rad); cb = m.cos(-rot * rad)
for n = 0, stp, 1 do
ox = x1; oy = y1;
sa = m.sin(ast*n) * b; ca = m.cos(ast*n) * a
x1 = x + ca * cb - sa * sb
y1 = y + ca * sb + sa * cb
if (n > 0) then drawline(ox,oy,x1,y1,col); end
end
end
--
setpicturesize(300,300)
setcolor(0,96,96,96)
setcolor(1,255,255,128)
r1 = 100
r2 = 50
rt = 0
frames = 100
while (1 < 2) do
r1t = 10 + math.random() * 140
r2t = 10 + math.random() * 140
rtt = math.random() * 360
for n = 0, frames-1, 1 do
clearpicture(0)
f2 = n / frames
f1 = 1 - f2
r1a = r1*f1 + r1t*f2
r2a = r2*f1 + r2t*f2
rta = rt*f1 + rtt*f2
-- x, y, r1, r2, stp, rot, col
ellipse2(150, 150, r1a, r2a, 50, rta, 1)
statusmessage('press ESC to stop')
updatescreen();if (waitbreak(0)==1) then return end
end
r1,r2,rt = r1a,r2a,rta
end

View File

@@ -0,0 +1,17 @@
-- flip picture - Copyright 2010 Paulo Silva
-- 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/>
w,h=getpicturesize();
ok,flipx,flipy=inputbox("flip picture","flip x",1,0,1,-1,"flip y",0,0,1,-1);
if ok==true then
if flipx==1 then
for y=0,h-1,1 do
for x=0,w/2,1 do
c1=getpicturepixel(x,y);c2=getpicturepixel(w-x-1,y)
putpicturepixel(x,y,c2);putpicturepixel(w-x-1,y,c1)
end;end
else
for y=0,h/2,1 do
for x=0,w-1,1 do
c1=getpicturepixel(x,y);c2=getpicturepixel(x,h-y-1)
putpicturepixel(x,y,c2);putpicturepixel(x,h-y-1,c1)
end;end;end;end

View File

@@ -0,0 +1,59 @@
--PICTURE: Pattern - Sierpinsky carpet v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- 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/>
-- 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
updatescreen()
if (waitbreak(0)==1) then
return
end
end

View File

@@ -0,0 +1,57 @@
--PICTURE: Pattern - Sierpinsky triangle v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- 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/>
-- 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
updatescreen()
if (waitbreak(0)==1) then
return
end
end

View File

@@ -0,0 +1,46 @@
--ANIM: Sprite Animator v0.1
--Spare page holds data - Plays on current
--by Richard Fhager
dofile("../libs/memory.lua")
arg=memory.load({XS=16,YS=16,SPACE=1,FRAMES=8,XOFF=0,YOFF=0,FPS=10})
OK, XS, YS, SPACE, FRAMES, XOFF, YOFF, FPS = inputbox("Sprite-Sheet Animator",
"Sprite X-size", arg.XS, 1, 256,0,
"Sprite Y-size", arg.YS, 1, 256,0,
"Spacing", arg.SPACE, 0, 32,0,
"# of Frames", arg.FRAMES,2, 100,0,
"X-offset", arg.XOFF, 0, 256,0,
"Y-offset", arg.YOFF, 0, 256,0,
"Play Speed (FPS)",arg.FPS, 1, 60,0
);
if OK == true then
memory.save({XS=XS,YS=YS,SPACE=SPACE,FRAMES=FRAMES,XOFF=XOFF,YOFF=YOFF,FPS=FPS})
MAXPLAYS = 25
w,h = getpicturesize()
OX = w / 2 - XS/2
OY = h / 2 - YS/2
for play = 1, MAXPLAYS, 1 do
for f = 0, FRAMES-1, 1 do
for y = 0, YS-1, 1 do
for x = 0, XS-1, 1 do
sx = x + XOFF + f * (XS + SPACE)
sy = y + YOFF
putpicturepixel(OX+x, OY+y, getsparepicturepixel(sx, sy))
end
end
updatescreen(); if (waitbreak(1/FPS)==1) then return; end
end
end -- plays
end --OK

View File

@@ -0,0 +1,57 @@
--BRUSH Scene: Amigaball 1.0
--
--Draws the famous 'Amiga ball' in the brush.
--
--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/>
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
--http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
w, h = getbrushsize()
if (w<64 or h<64) then
setbrushsize(64,64)
w=64
h=64
end
for y = 0, h - 1, 1 do
for x = 0, w - 1, 1 do
-- Fractionalize image dimensions
ox = x / w;
oy = y / h;
-- Ball
Xr = ox-0.5; Yr = oy-0.5;
W = (1 - 2*math.sqrt(Xr*Xr + Yr*Yr));
-- 'FishEye' distortion / Fake 3D
F = (math.cos((ox-0.5)*math.pi)*math.cos((oy-0.5)*math.pi))*0.65;
ox = ox - (ox-0.5)*F;
oy = oy - (oy-0.5)*F;
-- Checkers
V = ((math.floor(0.25+ox*10)+math.floor(1+oy*10)) % 2) * 255 * W;
-- Specularities
SPEC1 = math.max(0,(1-5*math.sqrt((ox-0.45)*(ox-0.45)+(oy-0.45)*(oy-0.45)))*112);
SPEC2 = math.max(0,(1-15*math.sqrt((ox-0.49)*(ox-0.49)+(oy-0.48)*(oy-0.48)))*255);
r = W * 255 + SPEC1 + SPEC2
g = V + SPEC1 + SPEC2
b = V + SPEC1 + SPEC2
putbrushpixel(x, y, matchcolor(r,g,b));
end
end

View File

@@ -0,0 +1,38 @@
--BRUSH Scene: Sphere of pencolor v1.0
--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/>
-- 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

View File

@@ -0,0 +1,100 @@
--BRUSH: Find AA-colors from pencolors
--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/>
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,64 @@
--BRUSH Scene: Mandelbrot fractal v0.5
--
--Draws a Mandelbrot fractal in the current brush.
--
--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/>
-- 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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,138 @@
-- Persistence library:
-- Memorize data for current function
-- memory.save(tab) and tab=memory.load()
--
-- The data will be stored in file called
-- <calling_function_name>.dat
-- in the lua directory
--
-- Example 1:
--
-- -- Load initial values or set defaults
-- arg = memory.load({picX=320,picY=200,scale=0})
-- -- Run an inputbox
-- OK,arg.picX,arg.picY,arg.scale = inputbox("Image Size")",
-- "Width", arg.picX, 1,2048,0,
-- "Height", arg.picY, 1,2048,0,
-- "Scale", arg.scale, 0,1,0);
-- if OK == true then
-- -- Save the selected values
-- memory.save(arg)
-- end
-- Example 2:
--
-- -- Load initial values or set defaults
-- arg = memory.load({x=320,y=200,scale=0})
-- picX=arg.x
-- picY=arg.y
-- scale=arg.scale
-- -- Run an inputbox
-- OK,picX,picY,scale = inputbox("Image Size")",
-- "Width", picX, 1,2048,0,
-- "Height", picY, 1,2048,0,
-- "Scale", scale, 0,1,0);
-- if OK == true then
-- -- Save the selected values
-- memory.save({x=picX,y=picY,scale=scale})
-- end
memory =
{
serialize = function(o)
if type(o) == "number" then
return tostring(o)
elseif type(o) == "string" then
return string.format("%q", o)
--elseif type(o) == "table" then
-- io.write("{\n")
-- for k,v in pairs(o) do
-- io.write(" ", k, " = ")
-- memory.serialize(v)
-- io.write(",\n")
-- end
-- io.write("}\n")
else
error("cannot serialize a " .. type(o))
end
end;
-- Return a string identifying the calling function.
-- Pass 1 for parent, 2 for grandparent etc.
callername = function(level)
local w
local last_slash
local info = debug.getinfo(level+1,"Sn")
local caller=tostring(info.name)
-- Function name if possible
if (caller~="nil") then
return caller
end
-- Otherwise, get file name, without extension
-- Get part after directory name
last_slash=0
while true do
local pos = string.find(info.source, "/", last_slash+1)
if (pos==nil) then break end
last_slash=pos
end
while true do
local pos = string.find(info.source, "\\", last_slash+1)
if (pos==nil) then break end
last_slash=pos
end
caller=string.sub(info.source, last_slash+1)
-- Remove file extension
if (string.sub(caller,-4, -1)==".lua") then
caller=string.sub(caller, 1, -5)
end
return caller
end;
-- Memorize some parameters.
save = function(o)
local caller=memory.callername(2)
--for k, v in pairs(o) do
-- messagebox(tostring(k))
-- messagebox(tostring(v))
--end
local f, e = io.open(caller..".dat", "w");
if (f ~= nil) then
f:write("Entry {\n")
for k, v in pairs(o) do
if (type(v)=="number") then
f:write(" "..k.."="..memory["serialize"](v)..",\n")
end
end
f:write("}\n")
f:close()
end
end;
-- Recover some saved parameters.
load = function(o)
local caller=memory.callername(2)
local i
function Entry (b)
-- Adds (or replaces) values in arg with those from b
for k, v in pairs(b) do
o[k]=v
end
end
local f = (loadfile(caller..".dat"))
if (f ~= nil) then
f()
end
return o
end;
}
return memory

View File

@@ -0,0 +1,40 @@
--PALETTE Adjust: Desaturate v1.1
--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/>
-- 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,171 @@
--PALETTE: Expand Colors v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- 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/>
-- 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,105 @@
--PALETTE: Fill ColorCube voids v1.0
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- 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/>
--
-- 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,27 @@
--PALETTE Modify: Inverted RGB
--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/>
-- 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,39 @@
--PALETTE Set: 3 Bit (8 Primaries)
--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/>
-- 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,39 @@
--PALETTE Set: Full 6 Bit (64 colors)
--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/>
-- 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,50 @@
--PALETTE Set: C64 Palette (16 colors)
--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/>
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, 256, 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/
-- 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/>
-- This script was adopted from Evalion, a Javascript codecrafting/imageprocessing project
-- http://goto.glocalnet.net/richard_fhager/evalion/evalion.html
--Shift_degrees = 45
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,37 @@
-- cell colour reducer - jan'11, from Paulo Silva, with help from people from GrafX2 google group (DawnBringer, Adrien Destugues (PulkoMandy), and Yves Rizoud)
-- 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/>
w,h=getpicturesize()
ok,xcell,ycell=inputbox("Modify cell pixel size","xcell",8,1,16,4,"ycell",8,1,16,4);
if ok==true then
function grayscaleindexed(c)
r,g,b=getcolor(c);return math.floor((b*11+r*30+g*59)/100);end
celcnt={};for n=0,255,1 do celcnt[n+1]=0;end -- Arraycounter must have initial value
for y1=0,h-1,ycell do
for x1=0,w-1,xcell do
for i=0,255,1 do
celcnt[i+1]=0;end
for y2=0,ycell-1,1 do
for x2=0,xcell-1,1 do
x=x1+x2;y=y1+y2;u=getpicturepixel(x,y)
celcnt[u+1]=celcnt[u+1]+(1000*xcell*ycell)+math.random(0,950);end;end
ikattr=0;paattr=0;ikcnt=0;pacnt=0
for i=0,255,1 do
if ikcnt<celcnt[i+1] then ikcnt=celcnt[i+1];ikattr=i;end;end
celcnt[ikattr+1]=0
for i=0,255,1 do
if pacnt<celcnt[i+1] then pacnt=celcnt[i+1];paattr=i;end;end
if grayscaleindexed(ikattr)>grayscaleindexed(paattr) then tmpr=ikattr;ikattr=paattr;paattr=tmpr;end
wmid=math.floor((grayscaleindexed(paattr)+grayscaleindexed(ikattr))/2)
for y2=0,ycell-1,1 do
for x2=0,xcell-1,1 do
x=x1+x2;y=y1+y2;u=getpicturepixel(x,y)
if u==ikattr then
idou=ikattr
elseif u==paattr then
idou=paattr
else
idou=ikattr
if grayscaleindexed(u)>wmid then idou=paattr;end
end
putpicturepixel(x,y,idou)
end;end;end;end;end

View File

@@ -0,0 +1,13 @@
-- Draw isometric grid - Copyright 2010 Paulo Silva
-- 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/>
w,h=getpicturesize();
ok,gsiz,ik=inputbox("draw isometric grid","size",16,0,128,5,"colour",1,0,255,6);
if ok==true then
for y=0,h-1,gsiz do
for x=0,w-1,1 do
putpicturepixel(x,y+(x/2)%gsiz,ik);
end;end
for y=0,h-1,gsiz do
for x=0,w-1,1 do
putpicturepixel(x+((gsiz/2)-1),y+(gsiz-1)-((x/2)%gsiz),ik);
end;end;end

View File

@@ -0,0 +1,14 @@
-- draw grid - rgb (matchcolor) - Copyright 2010 Paulo Silva
-- 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/>
w,h=getpicturesize()
ok,xsiz,ysiz,r,g,b=inputbox("draw grid - rgb (matchcolor)","x size",8,1,64,5,"y size",8,1,64,6,"r",128,0,255,6,"g",128,0,255,6,"b",128,0,255,6);
if ok==true then
c=matchcolor(r,g,b)
for y=0,h-1,1 do
for x=0,w-1,xsiz do
putpicturepixel(x,y,c);
end;end
for y=0,h-1,ysiz do
for x=0,w-1,1 do
putpicturepixel(x,y,c);
end;end;end

View File

@@ -0,0 +1,11 @@
-- draw grid - indexed colour - Copyright 2010 Paulo Silva
-- 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/>
w,h=getpicturesize();
ok,xsiz,ysiz,c=inputbox("draw grid - indexed colour)","x size",8,1,64,5,"y size",8,1,64,6,"colour id",0,0,255,6);
if ok==true then
for y=0,h-1,1 do
for x=0,w-1,xsiz do
putpicturepixel(x,y,c);end;end
for y=0,h-1,ysiz do
for x=0,w-1,1 do
putpicturepixel(x,y,c);end;end;end

View File

@@ -0,0 +1,12 @@
-- Glass grid filter - Copyright 2010 Paulo Silva
-- 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/>
w,h=getpicturesize();
ok,xsiz,ysiz=inputbox("message","xsize",8,0,64,5,"ysize",8,0,64,6);
if ok==true then
for y1=0,h-1,xsiz do
for x1=0,w-1,ysiz do
for y2=0,(ysiz/2)-1,1 do
for x2=0,xsiz-1,1 do
c1=getpicturepixel(x1+x2,y1+y2);c2=getpicturepixel(x1+(xsiz-1)-x2,y1+(ysiz-1)-y2)
putpicturepixel(x1+x2,y1+y2,c2);putpicturepixel(x1+(xsiz-1)-x2,y1+(ysiz-1)-y2,c1)
end;end;end;end;end

View File

@@ -0,0 +1,11 @@
-- palette to picture - Copyright 2010 Paulo Silva
-- 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/>
w,h=getpicturesize();
ok,xsiz,ysiz=inputbox("palette to picture","x size",8,1,16,5,"y size",8,1,16,6);
if ok==true then
for y1=0,7,1 do
for x1=0,31,1 do
for y2=0,ysiz-1,1 do
for x2=0,xsiz-1,1 do
putpicturepixel(x1*xsiz+x2,y1*ysiz+y2,y1+x1*8)
end;end;end;end;end

View File

@@ -0,0 +1,87 @@
--PICTURE (part of): 2 Isometric v0.1b
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- 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/>
-- 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,68 @@
--PICTURE: Rainbow - Dark to Bright
--by Richard Fhager
--http://hem.fyristorg.com/dawnbringer/
-- Email: dawnbringer@hem.utfors.se
-- MSN: annassar@hotmail.com
--
-- 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/>
-- 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,50 @@
--SCENE: Remap pic to RGB, diag.dith
--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/>
-- 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,69 @@
--SCENE: Remap pic 2 RGB, 1lineED-dith. (Same line simple error-diffusion dither)
--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/>
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,80 @@
--SCENE: Remap pic to 3bit, LineEDdith. (Same line simple error-diffusion dither)
--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/>
--
-- 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

View File

@@ -0,0 +1,12 @@
-- Copyright 2010 Paulo Silva
-- 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/>
w,h=getpicturesize();
ok,bitd=inputbox("colourspace from palette","bitdepth:",4,1,8,5);
if ok==true then
bitd3=(2^bitd);bitd8=(2^(math.floor(bitd/2)));bitd9=(2^((math.floor((bitd-1)/2))+1))
for y1=0,(bitd8-1),1 do
for x1=0,(bitd9-1),1 do
for y2=0,(bitd3-1),1 do
for x2=0,(bitd3-1),1 do
putpicturepixel(x1*bitd3+x2,y1*bitd3+y2,matchcolor((y2*255)/(bitd3-1),((y1*8+x1)*255)/(bitd3-1),(x2*255)/(bitd3-1)))
end;end;end;end;end