The following snippet is database which allows programmers to add, share, preview, test and save images of 2d or 3d filters.
It's a framework for filter draw functions that all can contribute without having to write the management code. Just write the name of the filter, etc, and write its code, copy and paste it in and it handles the previewing and browsing for you.
More importantly, filters can be combined to produce other filters, since it is a shared process, you can combine a series of filters together using your own routines. Thus the more you put in the more you get out.
The TGC Open Source Filter Project - For bored programmers... because we want to!!!
* Draw N at location X and Y, at width W and height H with no hassle
* Change properties and colours with no hassle
* Add your own filter to the library with no hassle
* Use my filters or someone elses filters with no hassle
* Apply filters to what ever you like with no hassle
* Browse, search and compare other peoples filters with no hassle
* Animate the filter to create motion effects with no hassle
* Include in your projects, games, products and snippets with no hassle
The concept here is to structure filter based snippets in a searchable sortable system.
Plugin Links
Advanced 2D - Rapid 2D commands for your games
Matrix1 Utilities - Essential DBP Upgrade
Zero Hassle Open Source Filters
If you are feeling bored; feel free to spend a moment to post a filter (hard coded or shader based special effect) according to the source code and template supplied. I am doing the same.
This is a fun activity rather than a serious project.
If you want to share some of your stuff, you should use Advanced2d over traditional 2D functions where possible. Go ahead and use any plugin you like; but if you do use anything other than Advanced2d or Matrix1, please indicate.
As you can see in the source code; we want to be able to select what ever effect we wish, and see it in action in realtime; and would like to save the effect to a bitmap file for what ever purpose desired.
You may use images, sprites and shaders if you like; so as long as the user gets back an image or object she can use via either the screen, 3D space or on a texture.
Prefix your function with FILTER_ followed by your name, nickname or group name. (Place your code in a function as demonstrated). If you need, append a seperate NO HASSLE source file.
Try to prefix local variables larger than 3 characters to avoid conflicts. Eg: tColour as MyType, rather than Colour as MyType.
12/12/12
`TGC Community Filters
`======================
// Open Source Filter Project
#CONSTANT FILTER_LAST_ANI_STAGE 1000000
Type Float4Type
x#
y#
z#
w#
Endtype
Type FilterType
ForeColour as DWord
BackColour as DWord
TintColour as DWord
Frequency#
Shader
Seed
Strength#
Name$
Img1
Img2
Obj
Sound
Bank
Spr
Func$
Speed
Options as Double Integer
AnimationStage as Double Integer // Increase by step, or simply use as a kind of keyframe value
Author$
Description$
Email$
Type$ // EG: 2D, 3D, Shader
Version
// General purpose properties
Value#
Counter
Float4
Source
Target
Endtype
Type RGBAType
R
G
B
A
Endtype
Type RGBAValType
R#
G#
B#
A#
Endtype
Gosub InitFilters
//----------------------------
Sync On : Sync Rate 30
Color Backdrop 0
Global FilterFont
FilterFont = a2CreateFont("Arial", 30, a2Size_Char(), a2Style_Bold())
Global ResultImage : ResultImage = Reserve Free Image()
iListSize = Max( 9, Min(20,Array Count( Filter() ) ) )
iStart = 1
iEnd = iListSize
//=================================================================
` Add your ZERO HASSLE effects below
//=================================================================
` Assign a valid filter type for sorting
` Effect types are
` 2D Gen (Generate something 2D)
` 2D Text
` 2D Effect (Works on source image and applys result to image in UDT. Shaders can be used if required.)
` 3D Gen (Generate 3D object, doesn't need to regenerate unless you are animating)
` 3D Text (Generate text based 3D object)
` 3D Effect (Use shaders)
` Sound Gen (Generate new sounds, only regenerate if animated)
` Sound Effect (Alter the sound in the UDT)
//=================================================================
` Always delete or restore used memblocks to original value
//=================================================================
// Chris Tate
e = AddFilter("X Lines", "2D Gen", "Chris Tate", 1, "FILTER_ChrisTate_XLines", "Animate horizontal lines. Uses frequency and speed. 2x Option 1.", "[email protected]")
//=================================================================
e = AddFilter("Y Lines", "2D Gen", "Chris Tate", 1, "FILTER_ChrisTate_YLines", "Animate verticle lines. Uses frequency and speed. 2x Option 1.", "[email protected]")
//=================================================================
e = AddFilter("Pixel Grass", "2D Gen", "Chris Tate", 1, "FILTER_ChrisTate_PixelGrass", "Animate an array of pixel grass. Adjust frequency from dense to wavy. Adjust strength for detail.", "[email protected]")
//=================================================================
e = AddFilter("Warp Text", "2D Text", "Chris Tate", 1,"FILTER_ChrisTate_WarpText", "Loop text characters at speed of step. Change speed using step. Smoothness randomized by frequency", "[email protected]")
//=================================================================
//----------------------------
n = Array Count( Filter() )
Repeat
Repeat
Set Cursor 0, 0
Print "Select effect number, [ << Leftkey : Previous page ] || [ >> Rightkey: Next page]"
iStart = iStart + (RightKey() * iListSize)
iStart = iStart - (LeftKey() * iListSize)
iEnd = Min(iStart + iListSize, n )
If iStart > n or iStart < 1
iStart = 1
iEnd = Min( iStart + iListSize, n )
Endif
Print
For e = iStart to iEnd
Print "["; e; "] " ; Filter(e).Name$ ; " v"; Filter(e).Version; " by "; Filter(e).Author$; " ("; Filter(e).Email$ ; ")"
Print " |-- "; Filter(e).Description$
Print " |-- "; Filter(e).Email$
Print
Next e
Sync
Until Scancode()
e = Val(Inkey$())
If e > 0
If e <= 9
//----------------------------
Filter(e).ForeColour = 0xFF00FF00
Filter(e).Options = Bit Set( Filter(e).Options, 1)
//-----------------------
// Required
Randomize Filter(e).Seed
Random Seed Filter(e).Seed
sName$ = Filter(e).Name$
Repeat
Cls
DrawFilter( e, 128, 200, 512, 512, sName$, iImage, 1.0, 1.0)
//----------------------------
If Spacekey() = 0
Print Filter(e).Name$; " v"; Filter(e).Version
Print Filter(e).Description$
Print "---------------------------------------------------------"
Print "FPS: "; Screen FPS()
Print "Press Spacebar to Save"
Print "Press return to select new effect"
Print "Seed: " ; Filter(e).Seed; "[SHIFT up or down key to change]"
Print "Frequency: " ; Filter(e).Frequency#; "[SHIFT left or right to change]"
If ShiftKey()
If UpKey() or DownKey()
Inc Filter(e).Seed, UpKey() - DownKey()
Randomize Filter(e).Seed
Random Seed Filter(e).Seed
Nice Wait 100
Endif
If LeftKey() or RightKey()
Inc Filter(e).Frequency#, ( RightKey() - LeftKey() ) * 0.01
Nice Wait 100
Endif
Else
Print "Speed: " ; Filter(e).Speed; " [up or down key to change]"
Print "Strength: " ; Filter(e).Strength#; " [left or right to change]"
Filter(e).Speed = Clamp(Filter(e).Speed + UpKey() - DownKey(),-100,100)
Inc Filter(e).Strength#, ( RightKey() - LeftKey() ) * 0.01
If UpKey() or DownKey() or RightKey() - LeftKey()
Nice Wait 100
Endif
Endif
Print "Stage: "; Filter(e).AnimationStage
Print "---------------------------------------------------------"
//----------------------------
Else
//----------------------------
Get Image ResultImage, 128, 200, 640, 712
//----------------------------
For i = 1 to 10000000
f$ = "Effect_" + PadLeft$( Str$(i), "0", 5 ) + ".png"
If File Exist( f$ ) = 0
Save Image f$, ResultImage
Exit
Endif
Next i
If i => 10000000
End // Bah!!
Endif
//----------------------------
Cls
Center Text Screen Width() * 0.5, Screen Height() * 0.5, "Saved as " + f$
Sync
Wait 2000
Endif
//----------------------------
a2Box 126, 198, 642, 714, 0x70FFFFFF
Nice Wait 1 // CPU Friendly
Sync
Until ReturnKey()
//----------------------------
Cls
Endif
Endif
Until EscapeKey()
End
//=================================================================
InitFilters:
Global Dim Filter(0) as FilterType
Return
//=================================================================
Function DrawFilter(e, x, y, w, h, sText$, iSourceImage, fIntensity#, fOpacity# )
// Use what ever parameters you need, keep it consistent
//----------------------------
// Validation
// fIntensity# = 0 - 1.0
// fOpacity# = 0 - 1.0
// fFrequency# = up to you
// fSpeed# = Range is up to you; however, this should be a means to animate your affect by keeping a non zero value
//----------------------------
// Always take in consideration the forecolour and backcolour.
// You may also use the source image for something interesting
Call Function Name Filter(e).Func$,e, x, y, w, h, sText$, iSourceImage, fIntensity#, fOpacity#
Endfunction t
//=================================================================
Function AddFilter( sName$, sType$, sAuthor$, iVersion, sFunctionName$, sDescription$, sEmail$ )
Array Insert At Bottom Filter()
t = Array Count( Filter())
Filter().Name$ = sName$
Filter().Img1 = Reserve Free Image()
Filter().Img2 = Reserve Free Image()
Filter().Obj = Reserve Free Object()
Filter().Spr = Reserve Free Sprite()
Filter().Shader = Reserve Free Effect()
Filter().Sound = Reserve Free Sound()
Filter().Bank = Reserve Free Bank()
Filter().Author$ = sAuthor$
Filter().Description$ = sDescription$
Filter().Email$ = sEmail$
Filter().Type$ = sType$
Filter().Func$ = sFunctionName$
Filter().ForeColour = 0xFFFFFFFF
Filter().Frequency# = 1.0
Filter().Strength# = 0.5
Filter().Speed = 1
Filter().Version = iVersion
Call Function Name sFunctionName$+"_Reset", t
Endfunction t
//=================================================================
///////////////////////////////////////////////////////////////////
//=================================================================
// Chris Tate
//-----------------------------------------------------------------
//-----------------------------------------------------------------
Function FILTER_ChrisTate_XLines(e, x, y, w, h, sText$, iSourceImage, fIntensity#, fOpacity#)
//-----------------------
Local fFrequency#
Local tFilter as FilterType
Local tHint as RGBAValType
Local col as DWord
tFilter = Filter(e)
fFrequency# = Clamp(tFilter.Frequency#,0.000001,1.0)
//-----------------------
// Speed things up
a2StartLineBatch 1 + Min( fFrequency# * h, h)
y2 = y + h - 1
x2 = x + w
iStep = h/(fFrequency#*h)
If Bit Get(tFilter.Options, 1)
iStep = iStep * 2
Endif
For r = y to y2 step iStep
l = Wrap(r+tFilter.AnimationStage,y,y2)
a2Line x, l, x2, l, tFilter.foreColour
Next r
// Required end of line batch from above
a2EndBatch
//----------------------------
// Something to animate with
Filter(e).AnimationStage = Wrap( Filter(e).AnimationStage + tFilter.Speed, 0, FILTER_LAST_ANI_STAGE )
Endfunction
//-----------------------------------------------------------------
Function FILTER_ChrisTate_XLines_Reset(e)
// Placeholder must exist; reset values here
Endfunction
//=================================================================
Function FILTER_ChrisTate_YLines(e, x, y, w, h, sText$, iSourceImage, fIntensity#, fOpacity#)
//-----------------------
Local fFrequency#
Local tFilter as FilterType
Local tHint as RGBAValType
Local col as DWord
tFilter = Filter(e)
fFrequency# = Clamp(tFilter.Frequency#,0.000001,1.0)
//-----------------------
// Speed things up
a2StartLineBatch 1 + Min( fFrequency# * h, h)
y2 = y + h
x2 = x + w - 1
iStep = w/(fFrequency#*w)
If Bit Get(tFilter.Options, 1)
iStep = iStep * 2
Endif
For r = x to x2 step iStep
l = Wrap(r+tFilter.AnimationStage,x,x2)
a2Line l, y, l, y2, tFilter.foreColour
Next r
// Required end of line batch from above
a2EndBatch
//----------------------------
// Something to animate with
Filter(e).AnimationStage = Wrap( Filter(e).AnimationStage + tFilter.Speed, 0, FILTER_LAST_ANI_STAGE )
Endfunction
//-----------------------------------------------------------------
Function FILTER_ChrisTate_YLines_Reset(e)
// Placeholder must exist; reset values here
Endfunction
//=================================================================
//-----------------------------------------------------------------
Function FILTER_ChrisTate_PixelGrass(e, x, y, w, h, sText$, iSourceImage, fIntensity#, fOpacity#)
//-----------------------
Local fFrequency#
Local tFilter as FilterType
Local tHint as RGBAValType
Local col as DWord
tFilter = Filter(e)
fFrequency# = Clamp(tFilter.Frequency#,0.000001,1.0)
//-----------------------
// Speed things up
a2StartLineBatch 1 + Min( fFrequency# * h, h)
y2 = y + h - 1
x2 = x + w
iStep = h/(tFilter.Strength#*h)
If Bit Get(tFilter.Options, 1)
iStep = iStep * 2
Endif
s# = (1.0-fFrequency#)*fIntensity#
//----------------------------
iU = Max((s#*w)*0.5,2)
For r = y to y2 step iStep
for u = 1 to w Step iU
l = Wrap(r+tFilter.AnimationStage+(Sin(tFilter.AnimationStage*s#)*h),y,y2)
a2Line Min(x+U,x2), Min(y2,l+Random(fIntensity#*h*0.25 )), Min(x+U+iU,x2), Min(y2,l+Random(fIntensity#*h*0.25 )), tFilter.foreColour
next u
Next r
// Required end of line batch from above
a2EndBatch
//----------------------------
// Something to animate with
Filter(e).AnimationStage = Wrap( Filter(e).AnimationStage + tFilter.Speed, 0, FILTER_LAST_ANI_STAGE )
Endfunction
//-----------------------------------------------------------------
Function FILTER_ChrisTate_PixelGrass_Reset(e)
// Placeholder must exist; reset values here
Endfunction
//=================================================================
Function FILTER_ChrisTate_WarpText(e, x, y, w, h, sText$, iSourceImage, fIntensity#, fOpacity#)
//----------------------------
Local tFilter as FilterType
tFilter = Filter(e)
Local fFrequency#
fFrequency# = Floor( tFilter.Frequency# * 8 )
col = RGB(fOpacity#*255, RGBR(tFilter.ForeColour), RGBG(tFilter.ForeColour), RGBB(tFilter.ForeColour))
col = tFilter.ForeColour
If sText$ <> ""
x2 = x + w
ty = y + (0.5 * h) - (0.5 * a2GetLineHeight( FilterFont ))
l = Fast Len( sText$ )
cw = 0
cx = Wrap( tFilter.AnimationStage, x, x2)
mcw = Filter(e).Counter
//----------------------------
For i = 1 to l
c$ = Mid$(sText$,i)
cw = a2GetTextWidth( FilterFont, c$ ) + Random(tFilter.Frequency#)
If cx + cw => x2
cx = x + (cx-x2)
Endif
a2Text FilterFont, cx, ty, c$, col
cx = cx+cw
Next i
Endif
//----------------------------
// Change animation stage
Filter(e).Counter = mcw
Filter(e).AnimationStage = Wrap( Filter(e).AnimationStage + tFilter.Speed, 0, FILTER_LAST_ANI_STAGE )
Endfunction
//-----------------------------------------------------------------
Function FILTER_ChrisTate_WarpText_Reset(e)
// Placeholder must exist; reset values here
Endfunction
///////////////////////////////////////////////////////////////////
//=================================================================
//=================================================================
// Next author
//-----------------------------------------------------------------
Function FILTER_INSERTNAME_INSERTFILTER(e, x, y, w, h, sText$, iSourceImage, fIntensity#, fOpacity#)
Local tFilter as FilterType
tFilter = Filter(e)
// Insert zero hassle code here
//----------------------------
// Change animation stage
Filter(e).AnimationStage = Wrap( Filter(e).AnimationStage + tFilter.Speed, 0, FILTER_LAST_ANI_STAGE )
Endfunction
//-----------------------------------------------------------------
Function FILTER_INSERTNAME_INSERTFILTER_Reset(e)
// Reset UDT values
Endfunction
//=================================================================
//=================================================================
// Next author
