Posted: 5th Jul 2018 16:16
Thanks Sphinx and puzzler2018

The shader was a bit tricky to convert to 3D but the shader mix command don't want to work for me
which the plan was to have a second texture as a mask. So the kali could be round etc I can get the
mix command to work but not the way the colors work with this shader. I posted on the shader thread
but no solution yet

It would be a great spawn enemy location and can easily be turned on or off by choosing to update the
the shader or not

I been working on a Maze Generator for the Coding Train one

They are tricky to produce I believe it was phaelax who produced a good one in here already with various
sizing capabilities. I used that one to produce a 2D game with the gyroscope. I believe with any array a
map could produce a great 3D world so curious how yours turns out
Posted: 5th Jul 2018 19:33
Moving 2D objects with the mouse no matter where the mouse is positioned on the sprite

+ Code Snippet

// Project: spritemoveexample 
// Created: 2018-07-04

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "spritemoveexample" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts


type _button
	id
	x#
	y#
	selected
endtype
global button as _button[10]

for a=0 to button.length
	button[a].id = createsprite(0)
	SetSpriteSize(button[a].id,50,50)
	
	button[a].x# = a * 2
	button[a].y# = 100
	
	SetSpritePosition(button[a].id, button[a].x# * GetSpriteWidth(button[a].id)+10, button[a].y#)
	
next

mouse = createsprite(0) : setspritesize(mouse,1,1)
hit=0


do
    SetSpritePosition(mouse, getpointerx(), getpointery())
    
    
    for a=0 to button.length
		if GetSpriteCollision(mouse,button[a].id)
			selectedsprite=button[a].id
		endif
		
		if GetRawMouseLeftPressed()
			
			
				
		endif
		
		if GetSpriteCollision(mouse, button[a].id) and GetRawMouseLeftState()
			if hit=0

// get the offsets on the first hit - only need to get this once

				offsetx# = getspritex(button[a].id) - getpointerx()
				offsety# = getspritey(button[a].id) - getpointery() 
				hit=1
			endif


			if selectedsprite= button[a].id 
// set the sprite in the new position of where the mouse is + that offset#
				button[a].x# = getpointerx() + offsetx#
				button[a].y# = getpointery() + offsety#
				SetSpritePosition(button[a].id, button[a].x#, button[a].y#)
				selectedsprite=button[a].id
			endif
		endif
		if GetRawMouseLeftReleased()

// we let go - so reset the hit to be able to retreive a new offset value if hit another sprite
			hit=0
		endif
		


	next
    Print( ScreenFPS() )
    Sync()
loop


Posted: 13th Jul 2018 17:04
Hi

Here is a 1D array conversion to 2D array - insprired by TensorFlow.js

+ Code Snippet
// Project: TensorFlow_Maybe 
// Created: 2018-07-13

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "TensorFlow_Maybe" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

global values as integer[]
global txtID as integer[]

//size of the 1D array
rows = 8
cols = 5

for a=1 to rows*cols
	values.insert(random(1,100))
next



// convert 1 dimension array to 2D one

dim newarray[0,0]
newarray = tensor2D(values,rows,cols)


// build some text to represent them on screen from the new 2D array

	for a=1 to rows
		for b=1 to cols

			txtID.insert (CreateText(str(newarray[a,b]))) // for presentation purposes
			settextsize	(txtID[count], 30)

			inc count
		next
	next




do
	// see the output
	count=0
	for a=1 to rows
		for b=1 to cols
			SetTextPosition(txtID[count], a * 50, b * 50)
			inc count
		next
	next
	
	
    Print( ScreenFPS() )
    Sync()
loop


function tensor2D (valuedata as integer[], rows, cols)
	
	dim array1[rows,cols]
	
	count=0
	for a=1 to rows
		for b=1 to cols
			array1[a,b]=valuedata[count]
			inc count
		next
	next
	
	
endfunction array1


Maybe useful one day
Posted: 13th Jul 2018 17:16
1D to 3D array

+ Code Snippet
// Project: TensorFlow_Maybe 
// Created: 2018-07-13

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "TensorFlow_Maybe" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

global values as integer[]
global txtID as integer[]

//size of the 1D array
depth = 2
rows = 8
cols = 5

for a=1 to rows*cols * depth
	values.insert(a)
next



// convert 1 dimension array to 3D one

dim newarray[0,0,0]
newarray = tensor3D(values, rows,cols,depth)


// build some text to represent them on screen from the new 2D array

	for a=1 to rows
		for b=1 to cols
			for c=1 to depth
				txtID.insert (CreateText(str(newarray[a,b,c]))) // for presentation purposes
				settextsize	(txtID[count], 30)
				
				inc count
			next
		next
	next




do
	// see the output
	count=0
	for a=1 to rows
		for b=1 to cols
			for c=1 to depth
				SetTextPosition(txtID[count], a * 50, b * 50)
				inc count
			next
		next
	next
	
	
    Print( ScreenFPS() )
    Sync()
loop


function tensor3D (valuedata as integer[], rows, cols,depth)
	
		dim array2[rows,cols,depth]
		count=0
		for a=1 to rows
			for b=1 to cols
				for c=1 to depth
					array2[a,b,c]=valuedata[count]
					inc count
				next
			next
		next
	
endfunction array2


1D to 4D

+ Code Snippet
// Project: TensorFlow_Maybe 
// Created: 2018-07-13

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "TensorFlow_Maybe" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

global values as integer[]
global txtID as integer[]

//size of the 1D array
depth = 2
rows = 8
cols = 5
fourD = 3

for a=1 to rows*cols * depth * fourD
	values.insert(a)
next



// convert 1 dimension array to 4D one

dim newarray[0,0,0,0]
newarray = tensor4D(values, rows,cols,depth, fourD)


// build some text to represent them on screen from the new 2D array

	for a=1 to rows
		for b=1 to cols
			for c=1 to depth
				for d=1 to fourD
					txtID.insert (CreateText(str(newarray[a,b,c,d]))) // for presentation purposes
					settextsize	(txtID[count], 30)
					
					inc count
				next
			next
		next
	next




do
	// see the output
	count=0
	for a=1 to rows
		for b=1 to cols
			for c=1 to depth
				for d=1 to fourD
					SetTextPosition(txtID[count], a * 50, b * 50)
					inc count
				next
			next
		next
	next
	
	
    Print( ScreenFPS() )
    Sync()
loop


function tensor4D (valuedata as integer[], rows, cols,depth, fourD)
	
		dim array2[rows,cols,depth, fourD]
		count=0
		for a=1 to rows
			for b=1 to cols
				for c=1 to depth
					for d=1 to fourD
						array2[a,b,c,d]=valuedata[count]
						inc count
					next
				next
			next
		next
	
endfunction array2


and it goes on and on just like that...
Posted: 13th Jul 2018 19:11
Thanks @Puzzler

3D Kaleidoscope using 3 textures and blended allowing for the kali to be placed on a wall for example
+ Code Snippet
#constant screenWidth=1024
#constant screenHeight=768

SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
// set variables for camera's starting position
pos_x# = 0
pos_y# = 50
pos_z# = 0
createEllipseForPortals(2)
createWallTexture(3)
// orientate camera
SetCameraRotation(1,30,0,0)
SetCameraPosition(1,pos_x#,pos_y#,pos_z#)
CreateObjectPlane(2,500,500)
SetObjectRotation(2,90,0,0)
SetObjectPosition(2,0,-17,250)
//dont set a second image if you dont want to have transparency layer added where any color that isnt transparent makes use of the Kali
SetObjectImage(2,2,1) 
SetObjectImage(2,3,2) 
SetObjectTransparency(2,1) //needed or the transparency will show as black on the object

createShader()
Shader=LoadShader( "Kaliset.vs","Kaliset.ps" )
SetObjectShader(2,Shader)
SetShaderConstantByName( Shader,"iResolution",500,500,0,0 )
do

    SetShaderConstantByName( Shader,"iGlobalTime",Timer()*.5,0,0,0 ) `tell the shader what time it is - so it can update its animations
    print(ScreenFPS())
    sync()
loop
function createEllipseForPortals(img as integer)
	rem create an ellipse that can be used as a sprite 
	SetClearColor(0,0,0)
	ClearScreen()
    Render()
    DrawBox(0,0,512,512,MakeColor(0,0,0),MakeColor(0,0,0),MakeColor(0,0,0),MakeColor(0,0,0),1)
    //DrawEllipse(50,50,50,50,MakeColor(255,255,255),MakeColor(255,255,255),1)
    DrawEllipse(256,256,256,256,MakeColor(255,255,255),MakeColor(0,0,0),1) //comment out this line if you dont like donuts lol
    
    Swap()
    getimage(img,0,0,512,512)
    SetImageTransparentColor(img,0,0,0)
    sync()
endfunction 

function createWallTexture(img as integer)
	ClearScreen()
    Render()
    DrawBox(0,0,512,512,MakeColor(155,155,155),MakeColor(155,155,155),MakeColor(155,155,155),MakeColor(155,155,155),1)
    x=-5:y=0:oldX=0
    repeat
		repeat
			DrawBox(x,y,x+5,y+1,MakeColor(155,5,5),MakeColor(155,5,5),MakeColor(155,5,5),MakeColor(155,5,5),1)
			x=x+6
		until x>512+5
		if oldx=-5
			x=-2:oldx=-2
		else
			x=-5:oldx=-5
		endif	
		y=y+3
	until y>512+2
    Swap()
    getimage(img,0,0,512,512)
    sync()
endfunction

function createShader()
//create the shader used for the port holes	
if GetFileExists("Kaliset.vs") then DeleteFile("Kaliset.vs")		
file = OpenToWrite("Kaliset.vs")
WriteLine(file,"attribute highp vec3 position;")
WriteLine(file,"attribute mediump vec3 normal;")
WriteLine(file,"attribute mediump vec2 uv;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uv0Varying;")
WriteLine(file,"varying mediump vec2 uv1Varying;")
WriteLine(file,"varying mediump vec2 uv2Varying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(file,"uniform float iGlobalTime; // shader playback time (in seconds)")
WriteLine(file,"uniform float iChannelTime[10]; // channel playback time (in seconds)")
WriteLine(file,"uniform vec3 iChannelResolution[10]; // channel resolution (in pixels)")
WriteLine(file,"//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down)")
WriteLine(file,"uniform sampler2D texture0; // input channel")
WriteLine(file,"uniform vec4 iDate; // (year, month, day, time in seconds)")
WriteLine(file,"uniform highp mat3 agk_WorldNormal;")
WriteLine(file,"uniform highp mat4 agk_World;")
WriteLine(file,"uniform highp mat4 agk_ViewProj;")
WriteLine(file,"uniform mediump vec4 uvBounds0;")
WriteLine(file,"uniform mediump vec4 uvBounds1;")
WriteLine(file,"uniform mediump vec4 uvBounds2;")
WriteLine(file,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"void main()")
WriteLine(file,"{") 
WriteLine(file,"    uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file,"    uv1Varying = uv * uvBounds1.xy + uvBounds1.zw;")
WriteLine(file,"    uv2Varying = uv * uvBounds2.xy + uvBounds2.zw;")
WriteLine(file,"    highp vec4 pos = agk_World * vec4(position,1.0);")
WriteLine(file,"    gl_Position = agk_ViewProj * pos;")
WriteLine(file,"    mediump vec3 norm = normalize(agk_WorldNormal * normal);")
WriteLine(file,"    posVarying = pos.xyz;")
WriteLine(file,"    normalVarying = norm;")
WriteLine(file,"    lightVarying = GetVSLighting( norm, posVarying );")
WriteLine(file,"}") 
CloseFile(file)

if GetFileExists("Kaliset.ps") then DeleteFile("Kaliset.ps")	
file = OpenToWrite("Kaliset.ps")
WriteLine(file,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(file,"uniform float iGlobalTime; // shader playback time (in seconds)")
WriteLine(file,"uniform float iChannelTime[10]; // channel playback time (in seconds)")
WriteLine(file,"")
WriteLine(file,"//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down)")
WriteLine(file,"uniform sampler2D texture0; // input channel ")
WriteLine(file,"uniform sampler2D texture1; // input channel ")
WriteLine(file,"uniform sampler2D texture2; // input channel ")
WriteLine(file,"uniform vec4 iDate; // (year, month, day, time in seconds)")
WriteLine(file,"varying mediump vec2 uv0Varying;")
WriteLine(file,"varying mediump vec2 uv1Varying;")
WriteLine(file,"varying mediump vec2 uv2Varying;")
WriteLine(file,"const int iterations=12;")
WriteLine(file,"void main(void)")
WriteLine(file,"{")
WriteLine(file,"//this takes the pixel we are working with to determine where it is on the screen")
//WriteLine(file,"vec2 z = gl_FragCoord.xy/iResolution.xy;")
WriteLine(file,"vec2 z = uv0Varying;")
WriteLine(file,"//fixes aspect ratio in favor of symmety. comment it and see what it looks like")
WriteLine(file,"//z.y*=iResolution.y/iResolution.x;")
WriteLine(file,"//gloobywavez")
WriteLine(file,"z.x += sin(z.y*2.0+iGlobalTime * .2)/10.0;")
WriteLine(file,"//zooom")
WriteLine(file,"//z*= 1.2 + sin(iGlobalTime*.15);")
WriteLine(file,"//pan")
WriteLine(file,"//z+=vec2(sin(iGlobalTime*.2),cos(iGlobalTime*.01));")
WriteLine(file,"//rotate")
WriteLine(file,"//z=vec2(z.x*cos(iGlobalTime*.2)- z.y*sin(iGlobalTime*.2),z.y*cos(iGlobalTime*.2));")
WriteLine(file,"vec2 c=vec2(0.5, 1.1);")
WriteLine(file,"")
WriteLine(file,"float average=0.;")
WriteLine(file,"float l=length(z);")
WriteLine(file,"float prevl;")
WriteLine(file,"for (int i=0; i<iterations; i++)")
WriteLine(file,"{")
WriteLine(file,"//kaliset base form")
WriteLine(file,"z=abs(z)/dot(z,z) -c;")
WriteLine(file,"//this is another function that can be iterated to produce some different fractals")
WriteLine(file,"//comment out the previous kaliset and experiment with values with this one!!")
WriteLine(file,"//z = abs(z)/(z.x*z.y)-c;")
WriteLine(file,"prevl=l;")
WriteLine(file,"l=length(z);")
WriteLine(file,"average+=abs(l-prevl);")
WriteLine(file,"}")
WriteLine(file,"//get the average length based upon the amount of iterations elapsed. multiply it to adjust definition")
WriteLine(file,"average/=float(iterations) * 15.;")
WriteLine(file,"//color fluctuation")
WriteLine(file,"average+=iGlobalTime*0.08;")
WriteLine(file,"vec3 myColor=vec3(0.2,0.21,.62);")
WriteLine(file,"vec3 finalColor;")
WriteLine(file,"//set the colors!")
WriteLine(file,"finalColor.r = (fract(float(average)/myColor.r));")
WriteLine(file,"finalColor.g = (fract(float(average)/myColor.g));")
WriteLine(file,"finalColor.b = (fract(float(average)/myColor.b));")
WriteLine(file,"vec4 colorResult1  = texture2D(texture1, uv1Varying);")
WriteLine(file,"vec4 colorResult2  = mix(colorResult1,vec4(finalColor,1.0), colorResult1.a);")
//WriteLine(file,"vec4 colorResult3  = texture2D(texture2, uv2Varying);")
WriteLine(file,"vec4 colorResult3  = mix(texture2D(texture2,uv2Varying),colorResult2,colorResult1.a);")
//WriteLine(file,"gl_FragColor = mix(colorResult3,colorResult1,colorResult2);")
WriteLine(file,"gl_FragColor = colorResult3;")
WriteLine(file,"}") 
CloseFile(file)
endfunction


3D Kaleidoscope A slightly different method of blending that should just be tried but the most usefull of the lot I think
+ Code Snippet
#constant screenWidth=1024
#constant screenHeight=768

SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
// set variables for camera's starting position
pos_x# = 0
pos_y# = 50
pos_z# = 0
createEllipseForPortals(2)
createWallTexture(3)
// orientate camera
SetCameraRotation(1,30,0,0)
SetCameraPosition(1,pos_x#,pos_y#,pos_z#)
CreateObjectPlane(2,500,500)
SetObjectRotation(2,90,0,0)
SetObjectPosition(2,0,-17,250)
//dont set a second image if you dont want to have transparency layer added where any color that isnt transparent makes use of the Kali
SetObjectImage(2,2,1) 
SetObjectImage(2,3,2) 
SetObjectTransparency(2,1) //needed or the transparency will show as black on the object

createShader()
Shader=LoadShader( "Kaliset.vs","Kaliset.ps" )
SetObjectShader(2,Shader)
SetShaderConstantByName( Shader,"iResolution",500,500,0,0 )
do

    SetShaderConstantByName( Shader,"iGlobalTime",Timer()*.5,0,0,0 ) `tell the shader what time it is - so it can update its animations
    print(ScreenFPS())
    sync()
loop
function createEllipseForPortals(img as integer)
	rem create an ellipse that can be used as a sprite 
	SetClearColor(0,0,0)
	ClearScreen()
    Render()
    DrawBox(0,0,512,512,MakeColor(0,0,0),MakeColor(0,0,0),MakeColor(0,0,0),MakeColor(0,0,0),1)
    //DrawEllipse(50,50,50,50,MakeColor(255,255,255),MakeColor(255,255,255),1)
    DrawEllipse(256,256,256,256,MakeColor(255,255,255),MakeColor(0,0,0),1) //comment out this line if you dont like donuts lol
    
    Swap()
    getimage(img,0,0,512,512)
    SetImageTransparentColor(img,0,0,0)
    sync()
endfunction 

function createWallTexture(img as integer)
	ClearScreen()
    Render()
    DrawBox(0,0,512,512,MakeColor(155,155,155),MakeColor(155,155,155),MakeColor(155,155,155),MakeColor(155,155,155),1)
    x=-5:y=0:oldX=0
    repeat
		repeat
			DrawBox(x,y,x+5,y+1,MakeColor(155,5,5),MakeColor(155,5,5),MakeColor(155,5,5),MakeColor(155,5,5),1)
			x=x+6
		until x>512+5
		if oldx=-5
			x=-2:oldx=-2
		else
			x=-5:oldx=-5
		endif	
		y=y+3
	until y>512+2
    Swap()
    getimage(img,0,0,512,512)
    sync()
endfunction

function createShader()
//create the shader used for the port holes	
if GetFileExists("Kaliset.vs") then DeleteFile("Kaliset.vs")		
file = OpenToWrite("Kaliset.vs")
WriteLine(file,"attribute highp vec3 position;")
WriteLine(file,"attribute mediump vec3 normal;")
WriteLine(file,"attribute mediump vec2 uv;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uv0Varying;")
WriteLine(file,"varying mediump vec2 uv1Varying;")
WriteLine(file,"varying mediump vec2 uv2Varying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(file,"uniform float iGlobalTime; // shader playback time (in seconds)")
WriteLine(file,"uniform float iChannelTime[10]; // channel playback time (in seconds)")
WriteLine(file,"uniform vec3 iChannelResolution[10]; // channel resolution (in pixels)")
WriteLine(file,"//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down)")
WriteLine(file,"uniform sampler2D texture0; // input channel")
WriteLine(file,"uniform vec4 iDate; // (year, month, day, time in seconds)")
WriteLine(file,"uniform highp mat3 agk_WorldNormal;")
WriteLine(file,"uniform highp mat4 agk_World;")
WriteLine(file,"uniform highp mat4 agk_ViewProj;")
WriteLine(file,"uniform mediump vec4 uvBounds0;")
WriteLine(file,"uniform mediump vec4 uvBounds1;")
WriteLine(file,"uniform mediump vec4 uvBounds2;")
WriteLine(file,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"void main()")
WriteLine(file,"{") 
WriteLine(file,"    uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file,"    uv1Varying = uv * uvBounds1.xy + uvBounds1.zw;")
WriteLine(file,"    uv2Varying = uv * uvBounds2.xy + uvBounds2.zw;")
WriteLine(file,"    highp vec4 pos = agk_World * vec4(position,1.0);")
WriteLine(file,"    gl_Position = agk_ViewProj * pos;")
WriteLine(file,"    mediump vec3 norm = normalize(agk_WorldNormal * normal);")
WriteLine(file,"    posVarying = pos.xyz;")
WriteLine(file,"    normalVarying = norm;")
WriteLine(file,"    lightVarying = GetVSLighting( norm, posVarying );")
WriteLine(file,"}") 
CloseFile(file)

if GetFileExists("Kaliset.ps") then DeleteFile("Kaliset.ps")	
file = OpenToWrite("Kaliset.ps")
WriteLine(file,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(file,"uniform float iGlobalTime; // shader playback time (in seconds)")
WriteLine(file,"uniform float iChannelTime[10]; // channel playback time (in seconds)")
WriteLine(file,"")
WriteLine(file,"//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down)")
WriteLine(file,"uniform sampler2D texture0; // input channel ")
WriteLine(file,"uniform sampler2D texture1; // input channel ")
WriteLine(file,"uniform sampler2D texture2; // input channel ")
WriteLine(file,"uniform vec4 iDate; // (year, month, day, time in seconds)")
WriteLine(file,"varying mediump vec2 uv0Varying;")
WriteLine(file,"varying mediump vec2 uv1Varying;")
WriteLine(file,"varying mediump vec2 uv2Varying;")
WriteLine(file,"const int iterations=12;")
WriteLine(file,"void main(void)")
WriteLine(file,"{")
WriteLine(file,"//this takes the pixel we are working with to determine where it is on the screen")
//WriteLine(file,"vec2 z = gl_FragCoord.xy/iResolution.xy;")
WriteLine(file,"vec2 z = uv0Varying;")
WriteLine(file,"//fixes aspect ratio in favor of symmety. comment it and see what it looks like")
WriteLine(file,"//z.y*=iResolution.y/iResolution.x;")
WriteLine(file,"//gloobywavez")
WriteLine(file,"z.x += sin(z.y*2.0+iGlobalTime * .2)/10.0;")
WriteLine(file,"//zooom")
WriteLine(file,"//z*= 1.2 + sin(iGlobalTime*.15);")
WriteLine(file,"//pan")
WriteLine(file,"//z+=vec2(sin(iGlobalTime*.2),cos(iGlobalTime*.01));")
WriteLine(file,"//rotate")
WriteLine(file,"//z=vec2(z.x*cos(iGlobalTime*.2)- z.y*sin(iGlobalTime*.2),z.y*cos(iGlobalTime*.2));")
WriteLine(file,"vec2 c=vec2(0.5, 1.1);")
WriteLine(file,"")
WriteLine(file,"float average=0.;")
WriteLine(file,"float l=length(z);")
WriteLine(file,"float prevl;")
WriteLine(file,"for (int i=0; i<iterations; i++)")
WriteLine(file,"{")
WriteLine(file,"//kaliset base form")
WriteLine(file,"z=abs(z)/dot(z,z) -c;")
WriteLine(file,"//this is another function that can be iterated to produce some different fractals")
WriteLine(file,"//comment out the previous kaliset and experiment with values with this one!!")
WriteLine(file,"//z = abs(z)/(z.x*z.y)-c;")
WriteLine(file,"prevl=l;")
WriteLine(file,"l=length(z);")
WriteLine(file,"average+=abs(l-prevl);")
WriteLine(file,"}")
WriteLine(file,"//get the average length based upon the amount of iterations elapsed. multiply it to adjust definition")
WriteLine(file,"average/=float(iterations) * 15.;")
WriteLine(file,"//color fluctuation")
WriteLine(file,"average+=iGlobalTime*0.08;")
WriteLine(file,"vec3 myColor=vec3(0.2,0.21,.62);")
WriteLine(file,"vec3 finalColor;")
WriteLine(file,"//set the colors!")
WriteLine(file,"finalColor.r = (fract(float(average)/myColor.r));")
WriteLine(file,"finalColor.g = (fract(float(average)/myColor.g));")
WriteLine(file,"finalColor.b = (fract(float(average)/myColor.b));")
WriteLine(file,"vec4 colorResult1  = texture2D(texture1, uv1Varying);")
WriteLine(file,"vec4 colorResult2  = mix(colorResult1,vec4(finalColor,1.0), colorResult1.a);")
WriteLine(file,"vec4 colorResult3  = texture2D(texture2, uv2Varying);")
WriteLine(file,"gl_FragColor = mix(colorResult3,colorResult1,colorResult2);")
//WriteLine(file,"vec4 colorResult3  = mix(texture2D(texture2,uv2Varying),colorResult2,colorResult1);")
//WriteLine(file,"gl_FragColor = colorResult3;")
WriteLine(file,"}") 
CloseFile(file)
endfunction


It now can be added to a model perhaps you want to use it for the fire from the engine of a fighter jet or a
walkthrough gateway inside the ship etc

Shader Help
Texture0 is where the kaleidosope is drawn
Texture1 is a masking layer, anything on this layer that isn't transparent is used for drawing the Kali in texture0
Texture2 is the texture you want to replace the transparent parts in texture1

If no textures are set to an object the whole object will be a kaleidoscope
if texture1 and setobjecttransparency is used then the transparent parts in texture1 will be transparent
If texture2 is used with or without setobjecttransparency the parts visible on this texture will be drawn on the invisible bits in texture1
Posted: 13th Jul 2018 21:30
Here is what happens when you turn the bonnet of the car into a Kali



the code for that was quite easy so to illustrate what I did il share it
but as you don't have the images or the car object it wont
run but im demonstrating just how easy it was to do
+ Code Snippet
#constant screenWidth=1024
#constant screenHeight=768

SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
// set variables for camera's starting position
carID=1
SetCameraPosition(1,0,100,-250)
loadObject(carId,"car01.obj")

loadImage(1,"carRed01.png") //the masking layer only the bonnet section would be white the rest transparency
loadImage(2,"carRed02.png") //the complete normal texture

SetObjectImage(carID,1,1) 
SetObjectImage(carID,2,2) 
SetObjectImage(carID,2,0) 

createShader()
Shader=LoadShader( "Kaliset.vs","Kaliset.ps" )
SetObjectShader(carID,Shader)
SetShaderConstantByName( Shader,"iResolution",500,500,0,0 )
do
    RotateObjectLocalY(carID,.25)
    SetShaderConstantByName( Shader,"iGlobalTime",Timer()*.5,0,0,0 ) `tell the shader what time it is - so it can update its animations
    print(ScreenFPS())
    sync()
loop


function createShader()
//create the shader used for the port holes	
if GetFileExists("Kaliset.vs") then DeleteFile("Kaliset.vs")		
file = OpenToWrite("Kaliset.vs")
WriteLine(file,"attribute highp vec3 position;")
WriteLine(file,"attribute mediump vec3 normal;")
WriteLine(file,"attribute mediump vec2 uv;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uv0Varying;")
WriteLine(file,"varying mediump vec2 uv1Varying;")
WriteLine(file,"varying mediump vec2 uv2Varying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(file,"uniform float iGlobalTime; // shader playback time (in seconds)")
WriteLine(file,"uniform float iChannelTime[10]; // channel playback time (in seconds)")
WriteLine(file,"uniform vec3 iChannelResolution[10]; // channel resolution (in pixels)")
WriteLine(file,"//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down)")
WriteLine(file,"uniform sampler2D texture0; // input channel")
WriteLine(file,"uniform vec4 iDate; // (year, month, day, time in seconds)")
WriteLine(file,"uniform highp mat3 agk_WorldNormal;")
WriteLine(file,"uniform highp mat4 agk_World;")
WriteLine(file,"uniform highp mat4 agk_ViewProj;")
WriteLine(file,"uniform mediump vec4 uvBounds0;")
WriteLine(file,"uniform mediump vec4 uvBounds1;")
WriteLine(file,"uniform mediump vec4 uvBounds2;")
WriteLine(file,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"void main()")
WriteLine(file,"{") 
WriteLine(file,"    uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file,"    uv1Varying = uv * uvBounds1.xy + uvBounds1.zw;")
WriteLine(file,"    uv2Varying = uv * uvBounds2.xy + uvBounds2.zw;")
WriteLine(file,"    highp vec4 pos = agk_World * vec4(position,1.0);")
WriteLine(file,"    gl_Position = agk_ViewProj * pos;")
WriteLine(file,"    mediump vec3 norm = normalize(agk_WorldNormal * normal);")
WriteLine(file,"    posVarying = pos.xyz;")
WriteLine(file,"    normalVarying = norm;")
WriteLine(file,"    lightVarying = GetVSLighting( norm, posVarying );")
WriteLine(file,"}") 
CloseFile(file)

if GetFileExists("Kaliset.ps") then DeleteFile("Kaliset.ps")	
file = OpenToWrite("Kaliset.ps")
WriteLine(file,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(file,"uniform float iGlobalTime; // shader playback time (in seconds)")
WriteLine(file,"uniform float iChannelTime[10]; // channel playback time (in seconds)")
WriteLine(file,"")
WriteLine(file,"//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down)")
WriteLine(file,"uniform sampler2D texture0; // input channel ")
WriteLine(file,"uniform sampler2D texture1; // input channel ")
WriteLine(file,"uniform sampler2D texture2; // input channel ")
WriteLine(file,"uniform vec4 iDate; // (year, month, day, time in seconds)")
WriteLine(file,"varying mediump vec2 uv0Varying;")
WriteLine(file,"varying mediump vec2 uv1Varying;")
WriteLine(file,"varying mediump vec2 uv2Varying;")
WriteLine(file,"const int iterations=12;")
WriteLine(file,"void main(void)")
WriteLine(file,"{")
WriteLine(file,"//this takes the pixel we are working with to determine where it is on the screen")
//WriteLine(file,"vec2 z = gl_FragCoord.xy/iResolution.xy;")
WriteLine(file,"vec2 z = uv0Varying;")
WriteLine(file,"//fixes aspect ratio in favor of symmety. comment it and see what it looks like")
WriteLine(file,"//z.y*=iResolution.y/iResolution.x;")
WriteLine(file,"//gloobywavez")
WriteLine(file,"z.x += sin(z.y*2.0+iGlobalTime * .2)/10.0;")
WriteLine(file,"//zooom")
WriteLine(file,"//z*= 1.2 + sin(iGlobalTime*.15);")
WriteLine(file,"//pan")
WriteLine(file,"//z+=vec2(sin(iGlobalTime*.2),cos(iGlobalTime*.01));")
WriteLine(file,"//rotate")
WriteLine(file,"//z=vec2(z.x*cos(iGlobalTime*.2)- z.y*sin(iGlobalTime*.2),z.y*cos(iGlobalTime*.2));")
WriteLine(file,"vec2 c=vec2(0.5, 1.1);")
WriteLine(file,"")
WriteLine(file,"float average=0.;")
WriteLine(file,"float l=length(z);")
WriteLine(file,"float prevl;")
WriteLine(file,"for (int i=0; i<iterations; i++)")
WriteLine(file,"{")
WriteLine(file,"//kaliset base form")
WriteLine(file,"z=abs(z)/dot(z,z) -c;")
WriteLine(file,"//this is another function that can be iterated to produce some different fractals")
WriteLine(file,"//comment out the previous kaliset and experiment with values with this one!!")
WriteLine(file,"//z = abs(z)/(z.x*z.y)-c;")
WriteLine(file,"prevl=l;")
WriteLine(file,"l=length(z);")
WriteLine(file,"average+=abs(l-prevl);")
WriteLine(file,"}")
WriteLine(file,"//get the average length based upon the amount of iterations elapsed. multiply it to adjust definition")
WriteLine(file,"average/=float(iterations) * 15.;")
WriteLine(file,"//color fluctuation")
WriteLine(file,"average+=iGlobalTime*0.08;")
WriteLine(file,"vec3 myColor=vec3(0.2,0.21,.62);")
WriteLine(file,"vec3 finalColor;")
WriteLine(file,"//set the colors!")
WriteLine(file,"finalColor.r = (fract(float(average)/myColor.r));")
WriteLine(file,"finalColor.g = (fract(float(average)/myColor.g));")
WriteLine(file,"finalColor.b = (fract(float(average)/myColor.b));")
WriteLine(file,"vec4 colorResult1  = texture2D(texture1, uv1Varying);")
WriteLine(file,"vec4 colorResult2  = mix(colorResult1,vec4(finalColor,1.0), colorResult1.a);")
//WriteLine(file,"vec4 colorResult3  = texture2D(texture2, uv2Varying);")
WriteLine(file,"vec4 colorResult3  = mix(texture2D(texture2,uv2Varying),colorResult2,colorResult1.a);")
//WriteLine(file,"gl_FragColor = mix(colorResult3,colorResult1,colorResult2);")
WriteLine(file,"gl_FragColor = colorResult3;")
WriteLine(file,"}") 
CloseFile(file)
endfunction
Posted: 13th Jul 2018 22:35
Wow - these are really cool - well done for your learning experiences with Shaders and objects
Posted: 13th Jul 2018 23:07
Thanks Puzzler
I was pretty stoked when I got that to work hence the video

Not sure what to use it for apart from portals at the moment perhaps for warpspeed and perhaps use the
version which would blend the bonnet with the kali instead of replacing it.

WarpSpeed
Posted: 16th Jul 2018 0:47
I was looking for an old encryption algorithm I had but to no avail

but I came across Phaelaxs solution for media here https://forum.thegamecreators.com/thread/205037
Which uses a water mark technique to encrypt pictures. It didn't quite work out of the box possible cos of obsolete
commands or a pseudocode approach the thread is also locked.

1 Functions to watermark media and 1 to remove watermark USE AT OWN RISK and always store your original images safe
+ Code Snippet
function watermarkImage(imgToWaterMarkID as integer, imageKeyID as integer)
mem = createMemblockFromImage(imgToWaterMarkID)
memKey = createMemblockFromImage(imageKeyID)
width  = getMemblockInt(mem, 0)
height = getMemblockInt(mem, 4)
width2  = getMemblockInt(memKey, 0)
height2 = getMemblockInt(memKey, 4)
for y = 0 to height-1
    for x = 0 to width-1
        pos    = y*width*4 + x*4 + 12
        keyPos = (mod(y,height2)*width2 + mod(x,width2))*4 + 12

        i = getMemblockInt(mem, pos)
        k = getMemblockInt(memKey, keyPos)
        c = i+k
        setMemblockInt(mem, pos, c)
    next x
next y

keyedImage = createImageFromMemblock(mem)
DeleteMemblock(mem):DeleteMemblock(memkey)
endfunction keyedImage

function removeWatermark(watermarkedImage  as integer, imageKeyID as integer)

mem = createMemblockFromImage(watermarkedImage )
memKey = createMemblockFromImage(imageKeyID)
width  = getMemblockInt(mem, 0)
height = getMemblockInt(mem, 4)
width2  = getMemblockInt(memKey, 0)
height2 = getMemblockInt(memKey, 4)

for y = 0 to height-1
    for x = 0 to width-1
        pos    = y*width*4 + x*4 + 12
        keyPos = (mod(y,height2)*width2 + mod(x,width2))*4 + 12

        i = getMemblockInt(mem, pos)
        k = getMemblockInt(memKey, keyPos)
        c = i-k
        setMemblockInt(mem, pos, c)
    next x
next y

keyedImage = createImageFromMemblock(mem)
DeleteMemblock(mem):DeleteMemblock(memkey)	
endfunction keyedImage



the example code I used to test it
+ Code Snippet

img = loadImage("cars.png")
imgKey = loadImage("watermark.png")

img=watermarkImage(img,imgKey)
saveImage(img, "media\cars-watermark.png")

DeleteImage(img)
LoadImage(img,"media\cars-watermark.png")
img=removeWatermark(img,imgKey)
saveImage(img, "media\cars-unwatermark.png")


The media it saves can be found on a windows10 machine at
C:\users\username\AppData\local\AGKApps\nameofproject\media

I may have a go at doing similar with sound files using a waterMarkSound(whitenoise)
and when we have a save mesh command it should be possible to use a similar technique

could also use a ROT13 approach The way its done with strings is as follows
The simplest encryption is simply just add an amount to the asci value of a character at a time
ie your key might be 13
cipher = (value + key) Mod(26) .......... to restrict it to the first 26 printable characters for example
to convert back
ciphertextLetter = (cipher + 65).......65 the starting character

using ROT13 and a watermark on a image
+ Code Snippet
#constant rot13Key=13 //between 0 and 255 work well
img = loadImage("cars.png")
imgKey = loadImage("watermark.png")

img=watermarkImage(img,imgKey)
saveImage(img, "media\cars-watermark.png")

DeleteImage(img)
LoadImage(img,"media\cars-watermark.png")
img=removeWatermark(img,imgKey)
saveImage(img, "media\cars-unwatermark.png")

end

function watermarkImage(imgToWaterMarkID as integer, imageKeyID as integer)
mem = createMemblockFromImage(imgToWaterMarkID)
memKey = createMemblockFromImage(imageKeyID)
width  = getMemblockInt(mem, 0)
height = getMemblockInt(mem, 4)
width2  = getMemblockInt(memKey, 0)
height2 = getMemblockInt(memKey, 4)
for y = 0 to height-1
    for x = 0 to width-1
        pos    = y*width*4 + x*4 + 12
        keyPos = (mod(y,height2)*width2 + mod(x,width2))*4 + 12

        i = getMemblockInt(mem, pos)
        k = getMemblockInt(memKey, keyPos)
        c = cipher(i+k,rot13Key,256)
        setMemblockInt(mem, pos, c)
    next x
next y

keyedImage = createImageFromMemblock(mem)
DeleteMemblock(mem):DeleteMemblock(memkey)
endfunction keyedImage

function removeWatermark(watermarkedImage  as integer, imageKeyID as integer)

mem = createMemblockFromImage(watermarkedImage )
memKey = createMemblockFromImage(imageKeyID)
width  = getMemblockInt(mem, 0)
height = getMemblockInt(mem, 4)
width2  = getMemblockInt(memKey, 0)
height2 = getMemblockInt(memKey, 4)

for y = 0 to height-1
    for x = 0 to width-1
        pos    = y*width*4 + x*4 + 12
        keyPos = (mod(y,height2)*width2 + mod(x,width2))*4 + 12

        i = getMemblockInt(mem, pos)
        k = getMemblockInt(memKey, keyPos)
        c = deCipher((i-k),rot13Key,256)
        setMemblockInt(mem, pos, c)
    next x
next y

keyedImage = createImageFromMemblock(mem)
DeleteMemblock(mem):DeleteMemblock(memkey)	
endfunction keyedImage

function cipher(value as integer,key2 as integer,restrict as integer)
	//cipher = Mod((value + key2),restrict) 
	cipher = value + key2
	if (value + key2) > restrict
         cipher = mod((value + key2),restrict)
    endif
endfunction cipher

function deCipher(value as integer,key2 as integer,restrict as integer)
	//cipher = Mod((value + key2),restrict) 
	deCipher = value - key2
	if (value - key2) < 0
		deCipher = deCipher+restrict
    endif
endfunction deCipher
Posted: 28th Jul 2018 4:28
Always wanted to do a 3D puzzle well last night I stopped procrastinating and got to work
and wanted to show my progress it is very short but i took advantage of using includes so
to test it you will have to make a project and add the following files

Labrynth 3D

main.agc
+ Code Snippet
// Project: maze gen v3 
// Created: 2018-07-06

// show all errors
SetErrorMode(2)

#include "Declarations.agc"
#include "CreateMaze.agc"


// set window properties
SetWindowTitle( "Labrynth" )
SetWindowSize( swidth, sheight, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( swidth, sheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
createtexture(grassTexture,512,512, makecolor(55,155,55),256)
createWallTexture(wallTexture)
SetImageWrapU(grassTexture,1 ) 
SetImageWrapV(grassTexture,1 ) 
CreateSprite(playerSpr,0)
SetSpriteImage(playerSpr,createPlayerSprImage())
SetSpriteVisible(playerSpr,1)
SetSpriteSize(playerSpr,40,40) //:SetSpriteTransparency(playerSpr,1)
SetSpriteDepth(playerSpr,0)
CreateSprite(enemySpr,0)
SetSpriteImage(enemySpr,createEnemySprImage())
SetSpriteVisible(enemySpr,0)
SetSpriteSize(enemySpr,40,40)
SetSpriteDepth(enemySpr,0)

//CreateSprite(mapSpr,0)
//SetSpriteVisible(mapSpr,0)
//SetSpriteDepth(mapSpr,1)
global cols,rows,width

type _cells
	ObjID0
	ObjID1
	ObjID2
	ObjID3
	x,y
	walls as integer[3]
	visited
	current
	direction
endtype

type _visit
	x,y
	time as float
endtype

global visited as _visit[]
global cells as _cells[]
//global emptycell as _cells
global stack as _cells[]
global stackcount, completed=0
global current=0
ground = CreateObjectBox(500,1,500)
SetObjectPosition(ground,0,-1.0,0)
SetObjectImage(ground,grassTexture,0)
SetObjectUVScale(ground,0,15, 15 )
CreateObjectBox(playerObj,1,1,1)
SetObjectPosition(playerObj,0,1.0,0)
SetObjectVisible(playerObj,0)	
SetObjectCollisionMode(playerObj, 0 ) 
//emptyArrays()
createMaze(50)
emptyArrays()
loadmaze("Level1.Dat")
createWalls()
roof = CreateObjectBox(65,1,45)
SetObjectPosition(roof,30,4.0,20)
global viewmaze=1
CreateText(1,"Use Arrow keys to move around")
CreateText(2,"Press 'V' to toggle Maze View")
CreateText(textGameOver,"GameOver")
CreateText(textLevel,"GO")
SetTextSize(1,25):SetTextSize(2,25):SetTextSize(3,25)
SetTextPosition(1,0,690):SetTextPosition(2,0,715)
SetTextSize(textLevel,100)
SetTextPosition(textLevel,(sWidth*.5)-54,300)
SetTextColor(textLevel,0,255,0,255)
SetTextVisible(textLevel,1):iAlpha=255
SetTextColorAlpha(textLevel, iAlpha )
SetTextSize(textGameOver,100)
SetTextPosition(textGameOver,(sWidth*.5)-200,200)
SetTextColor(textGameOver,255,0,0,255)
SetTextVisible(textGameOver,0)

startTime#=Timer():ResetTimer()
flag=0
do

	if viewmaze=1
		//SetClearColor(0,0,0)
		//ClearScreen()
		//Render()
		for x=0 to cells.length
			xx = cells[x].x * width
			yy = cells[x].y * width

			if cells[x].walls[0]=1 then DrawLine(xx      ,552-yy      ,xx+width, 552-yy      ,white,white)
			if cells[x].walls[1]=1 then DrawLine(xx+width,552-yy      ,xx+width, 552-(yy+width),white,white)
			if cells[x].walls[2]=1 then DrawLine(xx+width,552-(yy+width),xx      , 552-(yy+width),white,white)
			if cells[x].walls[3]=1 then DrawLine(xx      ,552-(yy+width),xx      , 552-yy      ,white,white)
		next
		
		for x=0 to visited.length
			DrawBox((visited[x].x * width)+shrink,(552-(visited[x].y*width))-shrink,(visited[x].x*width+width)-shrink,(552-(visited[x].y*width+width))+shrink ,green,green,green,green,1)
		next x: dec  x
		//if visited.length>0 then DrawBox((visited[x].x * width)+shrink,(552-(visited[x].y*width))-shrink,(visited[x].x*width+width)-shrink,(552-(visited[x].y*width+width))+shrink ,blue,blue,blue,blue,1)
		//swap()
		//if GetImageExists(mapImg) then DeleteImage(mapImg)
		//getimage(mapImg,0,0,swidth-220,sheight-210)
		//SetImageTransparentColor(mapImg,0,0,0)
		//SetSpriteImage(mapSpr,mapImg)
		//SetSpriteSize(mapSpr,swidth-220,sheight-210)
		x#=GetObjectX(playerObj)/4.0:y#=(GetObjectZ(playerObj)/4.0)
	     //DrawBox(x# * width+2      ,y# * width+2      ,x#* width+width-2      ,y# * width+width - 2,blue,blue,blue,blue,1)
		angle=GetObjectAngleY(playerObj) //:if angle = 0 or angle =180 then angle=angle + 180
		SetSpriteAngle(playerSpr,angle) 
		SetSpritePositionByOffset(playerSpr,x#* width+(width*.5),552-(y#* width+(width*.5)))
	endif
	if startTime#+10<timer() 
		flag=1
		if viewmaze=1 then SetSpriteVisible(enemySpr,1)
	endif`
	for num=0 to visited.length
		if visited[num].time+.25<timer() and flag=1 
			x#=visited[num].x:y#=visited[num].y
			SetSpritePositionByOffset(enemySpr,x#* width+(width*.5),552-(y#* width+(width*.5)))
			visited.remove(num)
			ResetTimer()
		endif 
	next num
	updatePlayerMovement()
		
	if GetRawKeyPressed(KEY_V) 
		if viewmaze=1 
			viewmaze=0
			SetSpriteVisible(playerSpr,0)
			SetSpriteVisible(enemySpr,0)
			//SetSpriteVisible(mapSpr,0)
		else
			viewmaze = 1
			SetSpriteVisible(playerSpr,1)
			SetSpriteVisible(enemySpr,1)
			//SetSpriteVisible(mapSpr,1)
		endif
	endif
	if GetSpriteCollision( playerSpr, enemySpr ) and flag=1
		SetTextVisible(textGameOver,1)
		repeat
			Print("Press space to play again")
			sync()
		until GetRawKeyPressed(KEY_SPACE)
		SetTextVisible(textGameOver,0)
	    SetObjectVisible(roof,0)
		emptyArrays()
		completed=0:current=0
		createMaze(50)
		emptyArrays()
		loadmaze("Level1.Dat")
		completed=0:current=0:flag=0
		SetObjectPosition(playerObj,0,1.0,0)
		createWalls()	
		SetObjectVisible(roof,1)
		SetSpriteVisible(enemySpr,0)
		x#=-20:y#=0
		SetSpritePositionByOffset(enemySpr,x#* width+(width*.5),552-(y#* width+(width*.5)))
		iAlpha=255:flag=0:startTime#=Timer():ResetTimer()
	endif    
	
	if getObjectX(playerObj)>=59 and getObjectZ(playerObj)>=39
		SetObjectVisible(roof,0)
		emptyArrays()
		completed=0:current=0
		createMaze(50)
		emptyArrays()
		loadmaze("Level1.Dat")
		completed=0:current=0:flag=0
		SetObjectPosition(playerObj,0,1.0,0)
		createWalls()	
		SetObjectVisible(roof,1)
		SetSpriteVisible(enemySpr,0)
		x#=-20:y#=0
		SetSpritePositionByOffset(enemySpr,x#* width+(width*.5),552-(y#* width+(width*.5)))
		iAlpha=255:flag=0:startTime#=Timer():ResetTimer()
	endif
	
	if iAlpha>2 then iAlpha=iAlpha-2
	SetTextColorAlpha(textLevel, iAlpha )
	   
    SetCameraRotation(1,0,GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj) ) 
    SetCameraPosition(1,GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj))
    Sync()
    
loop


function loadmaze(mazefile as string)
	loadfile = OpenToRead(mazefile)
	length = ReadInteger(loadfile)
	width = ReadInteger(loadfile)
	
	cells.length = length
	for loops = 0 to length

		cells[loops].x = ReadInteger(loadfile)
		cells[loops].y = ReadInteger(loadfile)
		cells[loops].walls[0] = ReadInteger(loadfile)
		cells[loops].walls[1] = ReadInteger(loadfile)
		cells[loops].walls[2] = ReadInteger(loadfile)
		cells[loops].walls[3] = ReadInteger(loadfile)

	next
	CloseFile(loadfile)
endfunction

function createWalls()
for a=0 to cells.length
	//change 4 to 5 for no more gaps
	if cells[a].walls[0] = 1 // top or bottom 
		//cells[a].ObjID = InstanceObject(playerObj)
		cells[a].ObjID0=CreateObjectBox(1,wallheight,1)
		SetObjectPosition(cells[a].ObjID0, cells[a].x*4, 1, cells[a].y*4-2)
		SetObjectScale(cells[a].ObjID0, 5,1,1)
		SetObjectImage(cells[a].ObjID0,wallTexture,0)
		SetObjectCollisionMode( cells[a].ObjID0, 1 ) 
	endif

	if cells[a].walls[2] = 1 // top or bottom 
		//cells[a].ObjID = InstanceObject(playerObj)
		cells[a].ObjID1=CreateObjectBox(1,wallheight,1)
		SetObjectPosition(cells[a].ObjID1, cells[a].x*4, 1, cells[a].y*4+2)
		SetObjectScale(cells[a].ObjID1, 5,1,1)
		SetObjectImage(cells[a].ObjID1,wallTexture,0)
		SetObjectCollisionMode( cells[a].ObjID1, 1 ) 
	endif
	
	if cells[a].walls[1] = 1 // left or right
		//cells[a].ObjID = InstanceObject(playerObj)
		cells[a].ObjID2=CreateObjectBox(1,wallheight,1)
		SetObjectPosition(cells[a].ObjID2, cells[a].x*4+2, 1, cells[a].y*4)
		SetObjectRotation(cells[a].ObjID2, 0,90,0)
		SetObjectScale(cells[a].ObjID2,5,1,1)
		SetObjectImage(cells[a].ObjID2,wallTexture,0)
		SetObjectCollisionMode( cells[a].ObjID2, 1 ) 
	endif

	if cells[a].walls[3] = 1 // left or right
		//cells[a].ObjID = InstanceObject(playerObj)
		cells[a].ObjID3=CreateObjectBox(1,wallheight,1)
		SetObjectPosition(cells[a].ObjID3, cells[a].x*4-2, 1, cells[a].y*4)
		SetObjectRotation(cells[a].ObjID3, 0,90,0)
		SetObjectScale(cells[a].ObjID3,5,1,1)
		SetObjectImage(cells[a].ObjID3,wallTexture,0)
		SetObjectCollisionMode( cells[a].ObjID3, 1 ) 
	endif
next
endfunction

function createWallTexture(img as integer)
	ClearScreen()
    Render()
    DrawBox(0,0,64,64,MakeColor(155,155,155),MakeColor(155,155,155),MakeColor(155,155,155),MakeColor(155,155,155),1)
    x=-5:y=0:oldX=0
    repeat
		repeat
			DrawBox(x,y,x+5,y+1,MakeColor(155,5,5),MakeColor(155,5,5),MakeColor(155,5,5),MakeColor(155,5,5),1)
			x=x+6
		until x>64+5
		if oldx=-5
			x=-2:oldx=-2
		else
			x=-5:oldx=-5
		endif	
		y=y+3
	until y>64+2
    Swap()
    getimage(img,0,0,64,64)
    sync()
endfunction

//used to create grass texture
function createtexture(imgID as integer,sizex# as float, sizey# as float, color, density as integer)
    swap()
    drawbox(0,0,sizex#, sizey#, color, color,color,color, 1)
    render()
    img = getimage(0,0,sizex#, sizey#)
        
    memblockid = CreateMemblockFromImage (img)
    imgwidth = GetMemblockInt(memblockid, 0)
    imgheight = GetMemblockInt(memblockid, 4)
        
    size=GetMemblockSize(memblockid)
    for offset=12 to size-4 step 4
          
        r=GetMemblockByte(memblockid, offset)
        g=GetMemblockByte(memblockid, offset+1)
        b=GetMemblockByte(memblockid, offset+2)
        a=GetMemblockByte(memblockid, offset+3)
                
            
        strength=random(1,density)
    
        SetMemblockByte (memblockid, offset, r-strength)
        SetMemblockByte (memblockid, offset+1, g-strength)
        SetMemblockByte (memblockid, offset+2, b-strength )
        SetMemblockByte (memblockid, offset+3, a-strength)
    next
    deleteimage (img)
    CreateImageFromMemblock(imgID,memblockid)
    DeleteMemblock(memblockid)
endfunction 

function createPlayerSprImage()
	rem draw a triangle image used for the player sprite on radar
	SetClearColor(0,0,0)
	ClearScreen()
    Render()
    DrawLine(5,0,9,9,green,green)
	DrawLine(1,8,8,8,green,green)
	DrawLine(1,9,5,0,green,green)
	//DrawLine(5,0,5,9,green,green)
	
	//draw these if you want it filled
	DrawLine(4,0,8,9,green,green)
	DrawLine(0,9,8,9,green,green)
	DrawLine(0,9,4,0,green,green)	
	DrawBox(4,1,6,8,green,green,green,green,1)
	
	swap()
    img = getimage(0,0,10,10)
    SetImageTransparentColor(img,0,0,0)
endfunction img

function createEnemySprImage()
	rem draw a triangle image used for the player sprite on radar
	SetClearColor(0,0,0)
	ClearScreen()
    Render()
	DrawEllipse(6,6,4,4,yellow,yellow,0)
	DrawEllipse(6,6,3,3,yellow,yellow,0)
	swap()
    img = getimage(0,0,12,12)
    SetImageTransparentColor(img,0,0,0)
endfunction img

function updatePlayerMovement()
	
	if GetRawKeyPressed(KEY_LEFT)  
		RotateObjectLocalY(playerObj,-90)
	endif
	if GetRawKeyPressed(KEY_RIGHT) 
		RotateObjectLocalY(playerObj,90)
	endif
	
	if GetRawKeyState(KEY_UP) //move forward
		old_x#=getObjectWorldX(playerObj)
		old_y#=GetObjectWorldY(playerObj)
		old_z#=getObjectWorldZ(playerObj)
		MoveObjectLocalZ(playerObj,2 )
		if checkCollision(playerObj)>0 
			SetObjectPosition(playerObj,old_x#,old_y#,old_z# )
		endif
		visits as _visit
		visits.x=getObjectWorldX(playerObj)/4.0
		visits.y=getObjectWorldZ(playerObj)/4.0
		visits2.time=timer()
		visited.insert(visits)
	endif
	
	if GetRawKeyState(KEY_DOWN) //move backwards
		old_x#=getObjectWorldX(playerObj)
		old_y#=GetObjectWorldY(playerObj)
		old_z#=getObjectWorldZ(playerObj)
		MoveObjectLocalZ(playerObj,-2 )
		if checkCollision(playerObj)>0 
			SetObjectPosition(playerObj,old_x#,old_y#,old_z# )
		endif
		visits2 as _visit
		visits2.x=getObjectWorldX(playerObj)/4.0
		visits2.y=getObjectWorldZ(playerObj)/4.0
		visits2.time=timer()
		visited.insert(visits2)
	endif
	
	if GetrawkeyPressed(KEY_SPACE) or GetRawMouseRightPressed() //jump
		Jump3DPhysicsCharacterController(playerObj)
	endif
	
	if GetrawkeyPressed(KEY_ENTER) or GetPointerPressed() //shoot
		//ThrowBall( 1000.0, 10.0)
	endif
endfunction 

function checkCollision(object  as integer)
//this checks for colliion between an object with any other object and returns its id
width#=1
height#=1 
depth#=1 
 
x#=getObjectWorldX(object)
y#=GetObjectWorldY(object)
z#=getObjectWorldZ(object)
// calculate the start of the ray cast
start_x# = x#-width#
start_y# = y#+height#
start_z# = z#-depth# 
// calculate the end of the ray cast
end_x# = x#+width#   
end_y# = y#-height#
end_z# = z#+depth# 
// determine which object has been hit
object_hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
endfunction object_hit 	

function emptyArrays()
	num2=cells.length
	for num=num2 to 0 step -1
		DeleteObject(cells[num].ObjID0):DeleteObject(cells[num].ObjID1)
		DeleteObject(cells[num].ObjID2):DeleteObject(cells[num].ObjID3)
		cells.remove(num)
	next
	
	num2=visited.length
	for num=num2 to 0 step -1
		visited.remove(num)
	next num
	
	num2=stack.length
	for num=num2 to 0 step -1
		stack.remove(num)
	next num
endfunction



Declarations.agc
+ Code Snippet
#constant	 KEY_BACK     =   8
#constant    KEY_TAB      =   9
#constant    KEY_ENTER    =   13
#constant    KEY_SHIFT    =   16
#constant    KEY_CONTROL  =   17
#constant    KEY_ESCAPE   =   27
#constant    KEY_SPACE    =   32
#constant    KEY_PAGEUP   =   33
#constant    KEY_PAGEDOWN =   34
#constant    KEY_END      =   35
#constant    KEY_HOME     =   36
#constant    KEY_LEFT     =   37
#constant    KEY_UP       =   38
#constant    KEY_RIGHT    =   39
#constant    KEY_DOWN     =   40
#constant    KEY_INSERT   =   45
#constant    KEY_DELETE   =   46
#constant    KEY_0        =   48
#constant    KEY_1        =   49
#constant    KEY_2        =   50
#constant    KEY_3        =   51
#constant    KEY_4        =   52
#constant    KEY_5        =   53
#constant    KEY_6        =   54
#constant    KEY_7        =   55
#constant    KEY_8        =   56
#constant    KEY_9        =   57
#constant    KEY_A        =   65
#constant    KEY_B        =   66
#constant    KEY_C        =   67
#constant    KEY_D        =   68
#constant    KEY_E        =   69
#constant    KEY_F        =   70
#constant    KEY_G        =   71
#constant    KEY_H        =   72
#constant    KEY_I        =   73
#constant    KEY_J        =   74
#constant    KEY_K        =   75
#constant    KEY_L        =   76
#constant    KEY_M        =   77
#constant    KEY_N        =   78
#constant    KEY_O        =   79
#constant    KEY_P        =   80
#constant    KEY_Q        =   81
#constant    KEY_R        =   82
#constant    KEY_S        =   83
#constant    KEY_T        =   84
#constant    KEY_U        =   85
#constant    KEY_V        =   86
#constant    KEY_W        =   87
#constant    KEY_X        =   88
#constant    KEY_Y        =   89
#constant    KEY_Z        =   90
#constant    KEY_F1       =   112
#constant    KEY_F2       =   113
#constant    KEY_F3       =   114
#constant    KEY_F4       =   115
#constant    KEY_F5       =   116
#constant    KEY_F6       =   117
#constant    KEY_F7       =   118
#constant    KEY_F8       =   119
#constant    wallTexture  =	  1
#constant    grassTexture =	  2
#constant    mapImg       =   3
#constant 	 playerObj    =   500 //object ID of player
#constant 	 playerGunObj =   501//The player gun object ID its invisible but location is used to shoot from
#constant    playerSpr    =   1	//Player sprite on the map
#constant    enemySpr     =   2	
#constant    mapSpr       =   3	
#constant 	 textLevel	  =   3
#constant 	 textGameOver =   4
#constant    shrink       =   20 //a value used to shrink the size of the draw boxes
#constant    camOff_y#    =   0  //Camera y offset
#constant 	 swidth 	  =   1024
#constant    sheight      =   768 
#constant    white        =   MakeColor(0,0,255)
#constant    green        =   MakeColor(0,255,0)
#constant    blue         =   MakeColor(0,0,255)
#constant    yellow       =   MakeColor(255,255,0)
#constant    black        =   MakeColor(0,0,0)
#constant    wallheight   =   5


CreateMaze.agc
+ Code Snippet
function createMaze(width)
// Change this value - lower the larger the map - the higher to smaller the maze
//width = 50
// Change this value - lower the larger the map - the higher to smaller the maze

completed=0
cols = floor(swidth / width)-5
rows = floor (sheight /width)-5
current=0
initialisegrid()
//currentcell.insert (cells[current])
saved=0

repeat
	//if viewmaze=1
		for x=0 to cells.length
			xx = cells[x].x * width
			yy = cells[x].y * width

			if completed=0 and cells[x].visited = 1 then DrawBox(xx      ,552-yy      ,xx+width, 552-(yy+width),green,green,green,green,1)
			if cells[x].walls[0]=1 then DrawLine(xx      ,552-yy      ,xx+width, 552-yy      ,white,white)
			if cells[x].walls[1]=1 then DrawLine(xx+width,552-yy      ,xx+width, 552-(yy+width),white,white)
			if cells[x].walls[2]=1 then DrawLine(xx+width,552-(yy+width),xx      , 552-(yy+width),white,white)
			if cells[x].walls[3]=1 then DrawLine(xx      ,552-(yy+width),xx      , 552-yy      ,white,white)
		next
		DrawBox(cells[current].x * width+2      ,552-(cells[current].y * width+2)      ,cells[current].x * width+width-2      ,552-(cells[current].y * width+width - 2),blue,blue,blue,blue,1)
	//endif
	checkneighbours(cells[current])	
	
	cells[current].visited=1

	if completed=1
		// lets save the current maze out 
		if saved=0 
			cells[current].walls[0]=0
			cells[current].walls[1]=0
			cells[current].walls[2]=0
			cells[current].walls[3]=0
			saved=1
			if GetFileExists("level1.dat") then DeleteFile("level1.dat")
			savefile = OpenToWrite("level1.dat")
			WriteInteger(savefile,cells.length)
			WriteInteger(savefile,width)
			for loops = 0 to cells.length
				WriteInteger(savefile,cells[loops].x)
				WriteInteger(savefile,cells[loops].y)
				WriteInteger(savefile,cells[loops].walls[0])
				WriteInteger(savefile,cells[loops].walls[1])
				WriteInteger(savefile,cells[loops].walls[2])
				WriteInteger(savefile,cells[loops].walls[3])

			next
			CloseFile(savefile)
			print("Saved")
			sync()
			sleep(1000)
		endif
		
	endif


    Sync()
until saved=1


endfunction 
function initialisegrid()
	i=0
	local emptycell as _cells
	for x=0 to cols
		for y=0 to rows
		
			emptycell.current = i
			emptycell.x = x
			emptycell.y = y
			
			emptycell.walls[0] = 1 //top
			emptycell.walls[1] = 1 //right
			emptycell.walls[2] = 1 //bottom
			emptycell.walls[3] = 1 // left
			
			emptycell.visited = 0
			cells.insert(emptycell)
			inc i
		
		next
	next


endfunction



function checkneighbours(cell ref  as _cells)

	neighbours as _cells[]
	top as _cells
	cright as _cells
	cleft as _cells
	cbottom as _cells
	r as _cells
	
//top	
	if index(cell.x, cell.y-1) <> -1 and cells[index(cell.x, cell.y-1)].visited = 0
		
		top     = cells[index(cell.x, cell.y - 1)]
		top.current = index(cell.x, cell.y - 1)
		top.visited=1
		top.direction=0
		neighbours.insert(top)
	endif

//right
	if index(cell.x+1,cell.y) <> -1 and cells[index(cell.x+1, cell.y)].visited = 0
		cright     = cells[index(cell.x+1, cell.y)]
		cright.current = cells[index(cell.x+1, cell.y)].current
		cright.visited=1
		cright.direction=1
	

		neighbours.insert(cright)
	endif

// bottom
	if index(cell.x, cell.y+1) <> -1 and cells[index(cell.x, cell.y+1)].visited = 0
		cbottom = cells[index(cell.x, cell.y + 1)]
		cbottom.current = index(cell.x, cell.y + 1)
		cbottom.visited=1
		cbottom.direction = 2

		neighbours.insert(cbottom)
	endif

//left
	if index(cell.x-1,cell.y) <> -1 and cells[index(cell.x-1, cell.y)].visited = 0
		cleft     = cells[index(cell.x-1, cell.y)]
		cleft.current = index(cell.x-1, cell.y)
		cleft.visited=1
		cleft.direction = 3

	
		neighbours.insert(cleft)

	endif



	oldc=current
	if neighbours.length>=0
		r = neighbours[floor(random(0,neighbours.length))]
		
		// remove necessary walls that your heading towards
		select (r.direction)
			case 0: //up /top
				cells[index(cell.x,cell.y)].walls[0]=0
				cells[index(cell.x,cell.y-1)].walls[2]=0
			endcase
			case 1: // right
				cells[index(cell.x,cell.y)].walls[1]=0
				cells[index(cell.x+1,cell.y)].walls[3]=0

			endcase
			case 2: // bottom / down
				cells[index(cell.x,cell.y)].walls[2]=0
				cells[index(cell.x,cell.y+1)].walls[0]=0

			endcase
			
			case 3: // left
				cells[index(cell.x,cell.y)].walls[3]=0
				cells[index(cell.x-1,cell.y)].walls[1]=0
			endcase
			
		endselect

		
		current = r.current
		stack.insert (r)
		inc stackcount
	else

		if stackcount-1<0 
			print ("COMPLETED")
			completed = 1
		else
			cells[index(r.x,r.y)] = stack[stackcount-1]
			current = index(r.x,r.y)
		
			stack.remove(stackcount-1)
			dec stackcount
		endif
		
	endif
	for num=0 to neighbours.length
		num2=num:neighbours.remove(num2)
	next num
endfunction r

function index ( i, j )
	if (i <0 or j <0 or i > cols or j > rows )
		
	else
		returnvalue = (i * (rows+1))  + j
	endif
endfunction  returnvalue



I had to invert the maze drawing so as rotations of sprites would be correct etc
How to play
Start at bottom left of maze and work your way to top right corner
If you take to long a munchkin will eat you he eats everything in site
including the trail of bread crumbs you leave behind


The maze is generated real time i still need to not use the save load method
I am currently using. The maze generator was designed by puzzler2018
https://forum.thegamecreators.com/thread/222579
Posted: 4th Aug 2018 21:11
3D Neon Glow Shader With help from Santman finalizing it
+ Code Snippet
function createShader()
file = OpenToWrite("neon.vs")
WriteLine(file,"attribute highp vec3 position;")
WriteLine(file,"attribute mediump vec3 normal;")
WriteLine(file,"attribute mediump vec2 uv;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"uniform highp mat3 agk_WorldNormal;")
WriteLine(file,"uniform highp mat4 agk_World;")
WriteLine(file,"uniform highp mat4 agk_ViewProj;")
WriteLine(file,"uniform mediump vec4 uvBounds0;")
WriteLine(file,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"void main()")
WriteLine(file,"{") 
WriteLine(file,"    uvVarying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file,"    highp vec4 pos = agk_World * vec4(position,1.0);")
WriteLine(file,"    gl_Position = agk_ViewProj * pos;")
WriteLine(file,"    mediump vec3 norm = normalize(agk_WorldNormal * normal);")
WriteLine(file,"    posVarying = pos.xyz;")
WriteLine(file,"    normalVarying = norm;")
WriteLine(file,"    lightVarying = GetVSLighting( norm, posVarying );")
WriteLine(file,"}") 
CloseFile(file)
  
//pixel shader
file = OpenToWrite("neon.ps")
WriteLine(file,"uniform sampler2D texture0;")
WriteLine(file,"uniform sampler2D texture1;")
WriteLine(file,"varying highp vec3 posVarying;")
WriteLine(file,"varying mediump vec3 normalVarying;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"varying mediump vec3 lightVarying;")
WriteLine(file,"mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(file,"mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );")
WriteLine(file,"uniform vec4 myColor;")
WriteLine(file,"uniform mediump vec4 agk_MeshDiffuse;")
WriteLine(file,"mediump vec4 colorResult;")
WriteLine(file,"uniform float lightint;")
WriteLine(file,"uniform float lightson;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"	mediump vec3 norm = normalize(normalVarying);")
WriteLine(file,"	mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying );")
WriteLine(file,"	vec4 colorA = texture2D(texture0, uvVarying);")
WriteLine(file,"	vec4 colorB = texture2D(texture1, uvVarying);")
WriteLine(file,"	if (lightson < 1.0) {")
WriteLine(file,"		colorResult = vec4(colorA * vec4(light,1.0))*lightint;")
WriteLine(file," 	} else {")
WriteLine(file,"		if (colorB.a > 0.0) {")
WriteLine(file,"			colorResult = vec4 ((colorA * vec4(light,1.0))*lightint) + (colorB*colorB.a);")
WriteLine(file,"		} else {")
WriteLine(file,"			colorResult =vec4(colorA * vec4(light,1.0))*lightint;")
WriteLine(file,"		}")
WriteLine(file,"	}")
WriteLine(file,"gl_FragColor = colorResult;")
WriteLine(file,"}")
CloseFile(file)
endfunction


Example code on how you use it no media required
+ Code Snippet
// Project: 3D neon lights shader demo 
// Created: 2018-07-25

// show all errors
SetErrorMode(2)
#constant green = MakeColor(0,255,0)
#constant white = MakeColor(255,255,255)

#constant screenWidth=1920
#constant screenHeight=1080
 
SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
// set variables for camera's starting position
carID=1
SetCameraPosition(1,0,100,-250)
SetFogMode( 1 ) 
SetFogColor(10,10,10)
SetFogRange(6,16)
 
//loadObject(carId,"car.obj")
//SetObjectScale(carId,0.5,0.5,0.5)
box=CreateObjectBox(150,150,150)
 
createShader() 
SetObjectImage(box,createBoxImage(),0)
SetObjectImage(box,createTriangleImage(),1)
 
//createShader()
Shader=LoadShader( "neon.vs","neon.ps" )
SetObjectShader(box,Shader)

lightint#=1.0
lightson=1
SetShaderConstantByName(Shader,"lightint",lightint#,0.0,0.0,0.0)
SetShaderConstantByName(Shader,"lightson",lightson*1.0,0.0,0.0,0.0)
     
do
     
    RotateObjectLocalY(box,.5)
    //SetShaderConstantByName(Shader,"pointPos",1,1,1,1)
    //SetShaderConstantByName(Shader,"myColor",r#,g#,b#,0.02) //red green blue factor
    if GetRawKeyState(49)=1
		lightint#=lightint#-0.01
		if lightint#<0.0 then lightint#=0.0
		SetShaderConstantByName(Shader,"lightint",lightint#,0.0,0.0,0.0)
	endif
    if GetRawKeyState(50)=1
		lightint#=lightint#+0.01
		if lightint#>1.0 then lightint#=1.0
		SetShaderConstantByName(Shader,"lightint",lightint#,0.0,0.0,0.0)
	endif
    if GetRawKeypressed(76)=1
		lightson=1-lightson
		SetShaderConstantByName(Shader,"lightson",lightson*1.0,0.0,0.0,0.0)
	endif
	//SetShaderConstantByName(Shader,"lightint",lightint#,0.0,0.0,0.0)
	//SetShaderConstantByName(Shader,"lightson",lightson*1.0,0.0,0.0,0.0)
    print("Press L to toggle lights")
    print("Use 1 and 2 to increase/decrease light")
    print ("Current value "+str(lightint#))
    sync()
loop

function createBoxImage()
    rem draw a triangle image used for the player sprite on radar
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    DrawBox(0,0,10,10,white,white,white,white,1)
     
    swap()
    img = getimage(0,0,10,10)
    SetImageTransparentColor(img,0,0,0)
endfunction img


function createTriangleImage()
    rem draw a triangle image used for the player sprite on radar
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    DrawLine(5,0,9,9,green,green)
    DrawLine(1,8,8,8,green,green)
    DrawLine(1,9,5,0,green,green)
    //DrawLine(5,0,5,9,green,green)
     
    //draw these if you want it filled
    DrawLine(4,0,8,9,green,green)
    DrawLine(0,9,8,9,green,green)
    DrawLine(0,9,4,0,green,green)   
    //DrawBox(4,1,6,8,green,green,green,green,1)
     
    swap()
    img = getimage(0,0,10,10)
    SetImageTransparentColor(img,0,0,0)
endfunction img
 
Posted: 4th Aug 2018 21:47
Awesome - very good at your shaders now well done
Posted: 7th Aug 2018 21:06
Thanks Puzzler2018
Edited fixed a bug which it got when the back buffer wasn't cleared properly

A simple 2D Lunar Lander template using color detection for collisions no media needed

+ Code Snippet
#constant KEY_LEFT    = 37  //the left arrow key scancode
#constant KEY_RIGHT   = 39  //the right arrow key scancode
#constant KEY_SPACE	  = 32  //the space bar
#constant KEY_ESCAPE  = 27  //the escape key used to exit program
#constant swidth	  =1024
#constant sheight	  =768
#constant white 	  = MakeColor(255,255,255)
#constant offWhite 	  = MakeColor(200,200,200)
#constant offRed 	  = MakeColor(200,0,0)
#constant green 	  = MakeColor(0,255,0)
#constant black 	  = MakeColor(0,0,0)
#constant scoreTxt	  =1
#constant timeTxt	  =2
#constant fuelTxt	  =3
#constant livesTxt	  =4
#constant backGround  =1
#constant ship		  =2	
#constant timerRed    =100
#constant timerGreen  =101
#constant fuelRed     =102
#constant fuelGreen   =103

SetWindowTitle("Lunar Lander" ) 
SetWindowSize( swidth, sheight, 0 )
SetVirtualResolution( swidth, sheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

global thrust#,background_memblock,background_imgwidth,background_imgheight
thrust#=0.1:maxthrust=100:fuel#=100:gravity#=1:score=0:lives=3
landImage=CreateLand()
background_memblock = CreateMemblockFromImage (LandImage)
background_imgwidth = GetMemblockInt(background_memblock, 0)
background_imgheight = GetMemblockInt(background_memblock, 4)
createSprite(background,landImage)
createSprite(ship,CreateCraft(24))
SetSpritePositionByOffset(ship,400,100)
SetSpriteOffset(ship,8,8)
SetSpriteTransparency(ship,1)

CreateTheText()
CreateFuelandTimeBars()

flameY=24:ammount=100:ResetTimer()
repeat
	if GetRawKeyState(KEY_SPACE)
		if flameY<50 
			inc flameY
			img=GetSpriteImageID(ship)
			img2=CreateCraft(flameY)
			DeleteImage(img)
			SetSpriteImage(ship,img2)
			SetSpriteSize(ship,-1,-1)
			//SetSpriteOffset(ship,8,GetSpriteScaleY(ship)*.5)
		endif
		if thrust#<2 then thrust#=thrust#+.1
	else
		if flameY>24 
			dec flameY:
			img=GetSpriteImageID(ship)
			img2=CreateCraft(flameY)
			DeleteImage(img)
			SetSpriteImage(ship,img2)
			SetSpriteSize(ship,-1,-1)
			//SetSpriteOffset(ship,8,GetSpriteScaleY(ship)*.5)
		endif
		if thrust#>0 then thrust#=thrust#-.1
	endif
	if GetRawKeyState(KEY_LEFT)
		SetSpriteAngle(ship,GetSpriteAngle(ship)-1) 
	endif
	if GetRawKeyState(KEY_RIGHT)
		SetSpriteAngle(ship,GetSpriteAngle(ship)+1) 		
	endif
	if fuel#>0 and timer()<100
		angle# = GetSpriteAngle(ship) - 90 //: If angle# < 360 Then angle# = angle# + 360
		//Calculate x / velocity based on sprite angle         
		xvel# = (Cos( angle# ) * (thrust#) )
		yvel# = (Sin( angle# ) * (thrust#) ) 
		//move sprite according to its angle and apply a gravity to the y axis
		if GetSpriteYByOffset(ship)>20 
			SetSpritePositionByOffset(ship, GetSpriteXByOffset(ship)+ xvel# ,(GetSpriteYByOffset(ship) + yvel# )+ gravity# )
		elseif yvel#>0
			SetSpritePositionByOffset(ship, GetSpriteXByOffset(ship)+ xvel# ,(GetSpriteYByOffset(ship) + yvel# )+ gravity# )			
		endif
	else //out of fuel or timer has run out
		flameY=20
		img=GetSpriteImageID(ship):img2=CreateCraft(flameY):DeleteImage(img)
		SetSpriteImage(ship,img2):SetSpriteSize(ship,-1,-1):SetSpriteOffset(ship,8,8)
		SetSpritePositionByOffset(ship, GetSpriteXByOffset(ship),GetSpriteYByOffset(ship)+ gravity# )		
	endif
	
	check=collisionCheck(GetSpriteXByOffset(ship),GetSpriteYByOffset(ship))
	if check=3 or timer()>99 //player crashed or timer has expired
		lives=lives-1:fuel#=100:ResetTimer() 
		SetSpritePositionByOffset(ship,400,100)
	endif
	
	if check=1 or check=2 //player landed
		img=GetSpriteImageID(backGround)
		DeleteSprite(backGround)
		DeleteImage(img)
		hideStuff()
		If GetImageExists(landImage) then deleteImage(landImage)
		LandImage=CreateLand()
		DeleteMemblock(background_memblock)
		background_memblock = CreateMemblockFromImage (LandImage)
		background_imgwidth = GetMemblockInt(background_memblock, 0)
		background_imgheight = GetMemblockInt(background_memblock, 4)
		createSprite(1,landImage)
		SetSpritePositionByOffset(ship,400,100)
		showStuff():fuel#=100
		if check=1 then score=score+100 //landed on green
		if check=2 then score=score+200 //landed on red 
		ResetTimer()
    endif
    
    fuel#=fuel#-(thrust#/12.0):if fuel#<0 then fuel#=0
    SetSpriteSize(fuelGreen,fuel#,20)
    SetSpriteSize(timerGreen,100-timer(),20)
	SetTextString(scoreTxt,"Score     "+str(score))
	SetTextString(livesTxt,"Lives     "+str(lives))
	sync()
until GetRawKeyPressed(KEY_ESCAPE) 


function CreateLand()
	SetPrintSize(90)
	repeat
		ClearScreen()
		Sync() //sync is needed to reset the print locations to top 
		landSpots=0
		Print("                 Lunar Lander")
		y1=768
		for x = 1 to swidth step 32
			y2=random(450,768)
			if random(0,5)>0
				DrawLine(x,y1,x+32,y2,offWhite,offWhite)  //offwhite is used for collision so its different than the lander and title etc
				DrawLine(x,y1-1,x+32,y2-1,offWhite,offWhite)  
				y1=y2	
			else
				if random(0,1)=0
					Drawline(x,y1-1,x+52,y1-1,green,green)
					Drawline(x,y1,x+52,y1,green,green):x=x+20 //easy landing spot
				else
					Drawline(x,y1-1,x+32,y1-1,offRed,offRed)
					Drawline(x,y1,x+32,y1,offRed,offRed) //harder landing spot
				endif	
				inc landSpots
			endif
		next x	
		Render()
	until landSpots>=5 //ensures there is atleast 5 landing spots
	img = getImage(0,0,swidth,sheight)
endfunction img

function CreateCraft(y as integer)
	SetClearColor(0,0,0)
	ClearScreen()
	//draw craft
	DrawBox(0,0,18,16+Y,black,black,black,black,1)
	DrawEllipse(8,8,8,8,white,white,0)
	DrawLine(3,15,0,24,white,white)
	DrawLine(13,15,18,24,white,white)
	//drawflame
	//DrawLine(4,0,12,0,white,white)
	DrawLine(4,16,8,16+y,white,white)
	DrawLine(12,16,8,16+y,white,white)
	
	render()
	img = getImage(0,0,18,16+Y)
	SetImageTransparentColor(img,0,0,0)
endfunction img

function createFuelandTimeBars()
//Time bar two sprites used one for the green and one for the red which is behind the green
//the red bar size changes (getting bigger gradually hiding the green bar
	CreateSprite(timerRed,0)
	CreateSprite(timerGreen,0)
	SetSpriteSize(timerRed,100,20)
	SetSpriteSize(timerGreen,100,20)
	SetSpriteColor(timerRed,255,0,0,255)
	SetSpriteColor(timerGreen,0,255,0,255)
	SetSpritePosition(timerRed,118,35)
	SetSpritePosition(timerGreen,118,35)
	SetSpriteDepth(timerRed,5)
	SetSpriteDepth(timerGreen,4)

//Fuel bar two sprites used one for the green and one for the red which is behind the green
//the red bar size changes (getting bigger gradually hiding the green bar
	CreateSprite(fuelRed,0)
	CreateSprite(fuelGreen,0)
	SetSpriteSize(fuelRed,100,20)
	SetSpriteSize(fuelGreen,100,20)
	SetSpriteColor(fuelRed,255,0,0,255)
	SetSpriteColor(fuelGreen,0,255,0,255)
	SetSpritePosition(fuelRed,118,65)
	SetSpritePosition(fuelGreen,118,65)
	SetSpriteDepth(fuelRed,5)
	SetSpriteDepth(fuelGreen,4)
endfunction

	
function CreateTheText()
	text1$="Score     "
	text2$="Time      "
	text3$="Fuel      "
	text4$="Lives     "
	CreateText(scoreTxt,text1$)
	CreateText(timeTxt,text2$)
	CreateText(fuelTxt,text3$)
	CreateText(livesTxt,text4$)
	SetTextSize(scoreTxt,30)
	SetTextSize(timeTxt,30)
	SetTextSize(fuelTxt,30)
	SetTextSize(livesTxt,30)
	SetTextPosition(scoreTxt,30,0)
	SetTextPosition(timeTxt,30,30)
	SetTextPosition(fuelTxt,30,60)
	SetTextPosition(livesTxt,900,0)
endfunction


function collisionCheck(x,y)
   local color1,color2,color3,color4	
   local collision=0
   if x<0 or x>swidth-1 or y<0 or y>sheight-1 then exitfunction collision 
   color1=pickColor2(x-10,y-10):color2=pickColor2(x+10,y-10)
   color3=pickColor2(x-10,y+10):color4=pickColor2(x+10,y+10)
   
   if color1 = offWhite then collision=3 `crashed
   if color2 = offWhite then collision=3 `crashed
   if color3 = offWhite then collision=3 `crashed
   if color4 = offWhite then collision=3 `crashed
   
   if color3 = green or color4 =green 
		if thrust#>0 and thrust#<1`landed
			collision =1
		else
			collision =3
		endif
   endif
   if color3 = offRed or color4 =offRed 
		if thrust#>0 and thrust#<1`landed
			collision =2
		else
			collision =3
		endif
   endif   
endfunction  collision `return collision value
 
Function pickColor(X,Y)
    local color,img 
    //color as integer
    rem prepare image grab area
    clearScreen()
    render()
   
    img = getImage(X,Y,X+1,Y+1)
   
    rem create memblock
      
    mem = createMemblockfromImage(img)
   
    rem get memblock data
    r = getMemblockbyte(mem,12):rem gets red channel data
    g = getMemblockbyte(mem,13):rem gets green channel data
    b = getMemblockbyte(mem,14):rem gets blue channel data
   
      
    rem tidy up
    deletememblock(mem)
    deleteimage(img)
    clearScreen()
    color = makeColor(r,g,b)
    //color=0
endfunction color

function pickColor2( X, Y)
	offset = 12 + (((Y * background_imgwidth) + X) * 4)

	r=GetMemblockByte(background_memblock, offset)
	g=GetMemblockByte(background_memblock, offset+1)
	b=GetMemblockByte(background_memblock, offset+2)

	c = MakeColor(r,g,b)
endfunction c


function hideStuff()
	SetTextVisible(scoreTxt,0):SetTextVisible(timeTxt,0):SetTextVisible(fuelTxt,0):SetTextVisible(livesTxt,0)
	SetSpriteVisible(timerRed,0):SetSpriteVisible(timerGreen,0):SetSpriteVisible(fuelRed,0):SetSpriteVisible(fuelGreen,0)
	SetSpriteVisible(ship,0)
endfunction

Function showStuff()
	SetTextVisible(scoreTxt,1):SetTextVisible(timeTxt,1):SetTextVisible(fuelTxt,1):SetTextVisible(livesTxt,1)
	SetSpriteVisible(timerRed,1):SetSpriteVisible(timerGreen,1):SetSpriteVisible(fuelRed,1):SetSpriteVisible(fuelGreen,1)
	SetSpriteVisible(ship,1)
endfunction


Instructions
Left and Right Arrows steer
Space Thrusts
Land on green you score 100
Land on red you score 200
Don't thrust enough you crash and burn
Posted: 10th Aug 2018 22:30
For those that remember the Carnival Shooting games at shows I created this
Its not much of a game at present but it does demonstrate picking a 3d object
with a mouse and rotating it
+ Code Snippet
#constant 	 swidth	  	  =	  1024
#constant 	 sheight	  =   768
#constant    white        =   MakeColor(0,0,255)
#constant    green        =   MakeColor(0,255,0)
#constant    blue         =   MakeColor(0,0,255)
#constant    yellow       =   MakeColor(255,255,0)
#constant    black        =   MakeColor(0,0,0)
SetWindowTitle("Pop UPs" ) 
SetWindowSize( swidth, sheight, 0 )
SetVirtualResolution( swidth, sheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

type objectType
	ID as integer
	time as float
endtype

dim objects[4] as objectType
circleImg=createCircleImage()
triangleImg=createTriangleImage()
for num = 0 to 4
	obj=CreateObjectPlane(2,4)
	SetObjectPosition(obj,num*5-10,0,0)
	imgRan=random(0,1)
	if imgRan=0
		SetObjectImage(obj,circleImg,0)
	else
		SetObjectImage(obj,triangleImg,0)
	endif
	SetObjectTransparency(obj,1)
	objects[num].ID=obj
	objects[num].time=0
next num
//SetObjectImage(obj1,circleImg,0)
//obj2=CreateObjectPlane(2,4)
SetCameraPosition(1,0,10,-20)
do
	if GetPointerPressed() 
		hit=checkCollision()
		if hit > 0 
			if getObjectAngleX(hit)=0
				RotateObjectLocalX(hit,90) 
				rem set timer for the correct object
				For num=0 to 4
					if objects[num].ID=hit then objects[num].time=timer()
				next num 
			endif
		endif
	endif
	for num = 0 to 4
		//only rotate the objects needed and if they have been down for 2 seconds
		if getObjectAngleX(objects[num].ID)>89 and objects[num].time+2<timer() 
			RotateObjectLocalX(objects[num].ID,-90)
		endif 
	next num
	sync()
loop
end


function checkCollision()
	 // get the position of the pointer (mouse)
     pointer_x = GetPointerX()
     pointer_y = GetPointerY()

     // get the x, y and z unit vectors based on the pointer position
     unit_x# = Get3DVectorXFromScreen(pointer_x,pointer_y)
     unit_y# = Get3DVectorYFromScreen(pointer_x,pointer_y)
     unit_z# = Get3DVectorZFromScreen(pointer_x,pointer_y)

     // calculate the start of the ray cast, which is the unit vector + the camera position
     start_x# = unit_x# + 0
     start_y# = unit_y# + 10
     start_z# = unit_z# - 20

     // calculate the end of the vector, which is the unit vector multiplied by the length of the ray cast and then add the camera position to it
     end_x# = 800*unit_x# + 0
     end_y# = 800*unit_y# + 10
     end_z# = 800*unit_z# - 20

     // determine which object has been hit
     object_hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
endfunction object_hit
	
function createTriangleImage()
    rem draw a triangle image used for the player sprite on radar
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    DrawLine(5,0,9,9,green,green)
    DrawLine(1,8,8,8,green,green)
    DrawLine(1,9,5,0,green,green)
    //DrawLine(5,0,5,9,green,green)
     
    //draw these if you want it filled
    DrawLine(4,0,8,9,green,green)
    DrawLine(0,9,8,9,green,green)
    DrawLine(0,9,4,0,green,green)   
    DrawBox(4,1,6,8,green,green,green,green,1)
     
    swap()
    img = getimage(0,0,10,10)
    SetImageTransparentColor(img,0,0,0)
endfunction img
 
function createCircleImage()
    rem draw a triangle image used for the player sprite on radar
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    DrawEllipse(6,6,4,4,yellow,yellow,0)
    DrawEllipse(6,6,3,3,yellow,yellow,0)
    swap()
    img = getimage(0,0,12,12)
    SetImageTransparentColor(img,0,0,0)
endfunction img



Needs allot of work but Carnival Time Shooting
+ Code Snippet
#constant 	 swidth	  	  =	  1024
#constant 	 sheight	  =   768
#constant    white        =   MakeColor(0,0,255)
#constant    green        =   MakeColor(0,255,0)
#constant    blue         =   MakeColor(0,0,255)
#constant    yellow       =   MakeColor(255,255,0)
#constant    black        =   MakeColor(0,0,0)
#constant    playerObj    =   500 //object ID of player
#constant 	 camOff_y#    =   5
#constant    bulletLife   = 3  //time to keep bullets alive
SetWindowTitle("Pop UPs" ) 
SetWindowSize( swidth, sheight, 0 )
SetVirtualResolution( swidth, sheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
create3DPhysicsWorld()

type objectType
	ID as integer
	time as float
endtype

// the type used for bullets  
type bullet
    ID as integer
    time as float // a time used because bullets die over time
endtype
global myBullet as bullet[0]
dim objects[7] as objectType
global bulletCount=0 //keeps track of the ammount of bullets currently alive used for processing
global Angle_x#   
global Angle_y#   
circleImg=createCircleImage()
triangleImg=createTriangleImage()
for num = 0 to 7
	obj=CreateObjectBox(2,4,.1)
	SetObjectPosition(obj,num*5-20,-10,20)
	imgRan=random(0,1)
	if imgRan=0
		SetObjectImage(obj,circleImg,0)
	else
		SetObjectImage(obj,triangleImg,0)
	endif
	SetObjectTransparency(obj,1)
	//SetObjectCollisionMode(obj,1)
	objects[num].ID=obj
	objects[num].time=0
next num
//SetObjectImage(obj1,circleImg,0)
//obj2=CreateObjectPlane(2,4)
CreateObjectBox(playerObj,20,20,20)
SetObjectPosition(playerObj,0,-15,-20)
SetObjectVisible(playerObj,0)
//SetCameraPosition(1,0,10,-120)
do
	Angle_x#=GetPointerY()
	Angle_y#=GetPointerX()
		
//	SetObjectRotation(playerObj,Angle_x#,Angle_y#,GetObjectAngleZ(playerObj))	
	if GetPointerPressed() 
			ThrowBall( 400.0, 10.0)
	endif
	
	Step3DPhysicsWorld()
	for num = 0 to 7
		hit=checkCollision(objects[num].ID)
		if hit>0
			if GetObjectAngleX(objects[num].ID)=0
                RotateObjectLocalX(objects[num].ID,90) 
                objects[num].time=timer()
            endif
		endif
		MoveObjectLocalX(objects[num].ID,-.1)
		if getObjectX(objects[num].ID)<-20 then SetObjectPosition(objects[num].ID,20,-10,20)
		if GetObjectAngleX(objects[num].ID)>89 and objects[num].time+2<timer() 
			RotateObjectLocalX(objects[num].ID,-90)
			objects[num].time=0
		endif 
	next num
	
	//There is no limit to bullets but a timer of bulletlife for how long they live
	for num=1 to bulletCount
		if (myBullet[num].time)+bulletLife<timer() 
			DeleteObject(myBullet[num].ID)
			myBullet.remove(num)
			dec bulletCount
		endif
	next num
	sync()
	//SetCameraRotation(1,GetObjectWorldAngleX(playerObj),GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj) ) 
loop
end


function ThrowBall( initialSpeed as float, mass as float)
	//To move dynamic physics bodies we need to apply velocity to the physics body.
	gunPositionVec= CreateVector3(GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj)) //im using the camera position as the gun position 
    //Create a tempory projectile block to calculate movement vectors of bullets
    projectileDirBox as integer
    projectileDirBox = CreateObjectBox( 1.0, 1.0, 1.0 )
    SetObjectPosition( projectileDirBox, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
    setobjectrotation(projectiledirbox,Angle_x#,GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj))
        
    MoveObjectLocalZ( projectileDirBox, 1.0 )
    projectileDirVec = CreateVector3( GetobjectWorldX( projectileDirBox )-GetVector3X( gunPositionVec ), GetobjectWorldY( projectileDirBox )-GetVector3Y( gunPositionVec ), GetobjectWorldZ( projectileDirBox )-GetVector3Z( gunPositionVec ) )
    DeleteObject( projectileDirBox )
    throwBall as integer    
    throwBall = CreateObjectSphere( 10, 16, 32 )
    SetObjectColor( throwBall, 255, 0,0,255 )
    SetObjectPosition( throwBall, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
    //3D Physics code
    Create3DPhysicsDynamicBody( throwBall )
    SetObjectShapeSphere( throwBall )
    SetObject3DPhysicsMass( throwBall, mass )
    SetObject3DPhysicsLinearVelocity( throwBall, projectileDirVec, initialSpeed )
    
    //SetObject3DPhysicsFriction( throwBall, 0.8 )
    //SetObject3DPhysicsRollingFriction( throwBall, 0.7 )
    //SetObject3DPhysicsCanSleep(throwBall,0)
    myItem as bullet
    myItem.ID = throwBall //the object id of the bullet
	myItem.time = timer()  //timer is used to set there life time as bullets will die off after so long
	myBullet.insert(myItem) //update bullet arrow as there is unlimeted bullets 
	inc bulletCount //used for a bullet counter to check if theyve timed out or not 
    deletevector3(projectileDirVec)
    deletevector3(gunPositionVec)
endfunction

function checkCollision(object)
//this checks for colliion between an object with any other object and returns its id
width#=.5
height#=1.5
depth#=.025
 
x#=getObjectWorldX(object)
y#=GetObjectWorldY(object)
z#=getObjectWorldZ(object)
// calculate the start of the ray cast
start_x# = x#-width#
start_y# = y#+height#
start_z# = z#-depth# 
// calculate the end of the ray cast
end_x# = x#+width#   
end_y# = y#-height#
end_z# = z#+depth# 
// determine which object has been hit
object_hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
endfunction object_hit 	

function createTriangleImage()
    rem draw a triangle image used for the player sprite on radar
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    DrawLine(5,0,9,9,green,green)
    DrawLine(1,8,8,8,green,green)
    DrawLine(1,9,5,0,green,green)
    //DrawLine(5,0,5,9,green,green)
     
    //draw these if you want it filled
    DrawLine(4,0,8,9,green,green)
    DrawLine(0,9,8,9,green,green)
    DrawLine(0,9,4,0,green,green)   
    DrawBox(4,1,6,8,green,green,green,green,1)
     
    swap()
    img = getimage(0,0,10,10)
    SetImageTransparentColor(img,0,0,0)
endfunction img
 
function createCircleImage()
    rem draw a triangle image used for the player sprite on radar
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    DrawEllipse(6,6,4,4,yellow,yellow,0)
    DrawEllipse(6,6,3,3,yellow,yellow,0)
    swap()
    img = getimage(0,0,12,12)
    SetImageTransparentColor(img,0,0,0)
endfunction img
Posted: 11th Aug 2018 17:54
Supernova Shader

+ Code Snippet
SetErrorMode(2)

// set window properties
SetWindowTitle( "SuperNova" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createVSShaderFile()
createPSshaderFile()



chunk = CreateObjectPlane(1000,1000)
SetObjectColor(chunk,255,255,255,255)
Shader=LoadShader("supernova.vs","supernova.ps")
SetObjectShader(chunk,Shader)
SetShaderConstantByName( Shader,"iResolution",900,900,0,0 )

do
    
    SetShaderConstantByName( Shader,"time",Timer()*.5,0,0,0 )


    Print( ScreenFPS() )
    Sync()

loop



// This is the function which creates the two files VS and PS
// These just simply output lines of code to the two files

function createVSShaderFile()
	
    fw = OpenToWrite("supernova.vs")
    WriteLine(fw,"attribute highp vec3 position;")
    WriteLine(fw,"attribute mediump vec3 normal;")
    WriteLine(fw,"varying highp vec3 posVarying;")
    WriteLine(fw,"varying mediump vec3 normalVarying;")
    WriteLine(fw,"varying mediump vec3 lightVarying;")
    WriteLine(fw,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
    WriteLine(fw,"uniform highp mat3 agk_WorldNormal;")
    WriteLine(fw,"uniform highp mat4 agk_World;")
    WriteLine(fw,"uniform highp mat4 agk_ViewProj;")
    WriteLine(fw,"attribute highp vec2 uv;")
    WriteLine(fw,"varying highp vec2 uvVarying;")
    WriteLine(fw,"uniform highp vec4 uvBounds0;")
     
    WriteLine(fw,"void main()")
    WriteLine(fw,"{ ")
    WriteLine(fw,"uvVarying = uv * uvBounds0.xy + uvBounds0.zw;")
    WriteLine(fw,"highp vec4 pos = agk_World * vec4(position,1.0);")
    WriteLine(fw,"mediump vec3 norm = normalize(agk_WorldNormal * normal);")
    WriteLine(fw,"gl_Position = agk_ViewProj * pos;")
    WriteLine(fw,"posVarying = pos.xyz;")
    WriteLine(fw,"normalVarying = norm;")
    WriteLine(fw,"lightVarying = GetVSLighting( norm, posVarying );")
    WriteLine(fw,"}")
    CloseFile(fw)
 
	
	
endfunction

function createPSshaderFile()

fw=OpenToWrite("supernova.ps")

WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 iResolution;")
WriteLine(fw,"//#define BOTH")
WriteLine(fw,"// uncomment this string to see left part")
WriteLine(fw,"#define LEFT")
WriteLine(fw,"//#define LOW_QUALITY")
WriteLine(fw,"#define DITHERING")
WriteLine(fw,"//#define TONEMAPPING")
WriteLine(fw,"//-------------------")
WriteLine(fw,"#define pi 3.14159265")
WriteLine(fw,"#define R(p, a) p=cos(a)*p+sin(a)*vec2(p.y, -p.x)")
WriteLine(fw,"vec3 hash( vec3 p )")
WriteLine(fw,"{")
WriteLine(fw,"	p = vec3( dot(p,vec3(127.1,311.7, 74.7)),")
WriteLine(fw,"			  dot(p,vec3(269.5,183.3,246.1)),")
WriteLine(fw,"			  dot(p,vec3(113.5,271.9,124.6)));")
WriteLine(fw,"	return -1.0 + 2.0*fract(sin(p)*43758.5453123);")
WriteLine(fw,"}")
WriteLine(fw,"float noise( in vec3 p )")
WriteLine(fw,"{")
WriteLine(fw,"    vec3 i = floor( p );")
WriteLine(fw,"    vec3 f = fract( p );")
WriteLine(fw,"	vec3 u = f*f*(3.0-2.0*f);")
WriteLine(fw,"    return mix( mix( mix( dot( hash( i + vec3(0.0,0.0,0.0) ), f - vec3(0.0,0.0,0.0) ), ")
WriteLine(fw,"                          dot( hash( i + vec3(1.0,0.0,0.0) ), f - vec3(1.0,0.0,0.0) ), u.x),")
WriteLine(fw,"                     mix( dot( hash( i + vec3(0.0,1.0,0.0) ), f - vec3(0.0,1.0,0.0) ), ")
WriteLine(fw,"                          dot( hash( i + vec3(1.0,1.0,0.0) ), f - vec3(1.0,1.0,0.0) ), u.x), u.y),")
WriteLine(fw,"                mix( mix( dot( hash( i + vec3(0.0,0.0,1.0) ), f - vec3(0.0,0.0,1.0) ), ")
WriteLine(fw,"                          dot( hash( i + vec3(1.0,0.0,1.0) ), f - vec3(1.0,0.0,1.0) ), u.x),")
WriteLine(fw,"                     mix( dot( hash( i + vec3(0.0,1.0,1.0) ), f - vec3(0.0,1.0,1.0) ), ")
WriteLine(fw,"                          dot( hash( i + vec3(1.0,1.0,1.0) ), f - vec3(1.0,1.0,1.0) ), u.x), u.y), u.z );")
WriteLine(fw,"}")
WriteLine(fw,"float fbm( vec3 p )")
WriteLine(fw,"{")
WriteLine(fw,"   return noise(p*.06125)*.5 + noise(p*.125)*.25 + noise(p*.25)*.125 + noise(p*.4)*.2;")
WriteLine(fw,"}")

WriteLine(fw,"float rand(vec2 co)")
WriteLine(fw,"{")
WriteLine(fw,"   return fract(sin(dot(co*0.123,vec2(12.9898,78.233))) * 43758.5453);")
WriteLine(fw,"}")

WriteLine(fw,"float Sphere( vec3 p, float r )")
WriteLine(fw,"{")
WriteLine(fw,"   return length(p)-r;")
WriteLine(fw,"}")
//==============================================================
// otaviogood's noise from https://www.shadertoy.com/view/ld2SzK
//--------------------------------------------------------------
// This spiral noise works by successively adding and rotating sin waves while increasing frequency.
// It should work the same on all computers since it's not based on a hash function like some other noises.
// It can be much faster than other noise functions if you're ok with some repetition.
WriteLine(fw,"const float nudge = 4.;	// size of perpendicular vector")
WriteLine(fw,"float normalizer = 1.0 / sqrt(1.0 + nudge*nudge);	// pythagorean theorem on that perpendicular to maintain scale")
WriteLine(fw,"float SpiralNoiseC(vec3 p)")
WriteLine(fw,"{")
WriteLine(fw,"    float n = -mod(time * 0.2,-2.); // noise amount")
WriteLine(fw,"    float iter = 2.0;")
WriteLine(fw,"    for (int i = 0; i < 8; i++)")
WriteLine(fw,"    {")
        // add sin and cos scaled inverse with the frequency
WriteLine(fw,"        n += -abs(sin(p.y*iter) + cos(p.x*iter)) / iter;	// abs for a ridged look")
WriteLine(fw,"        // rotate by adding perpendicular and scaling down")
WriteLine(fw,"        p.xy += vec2(p.y, -p.x) * nudge;")
WriteLine(fw,"        p.xy *= normalizer;")
WriteLine(fw,"        // rotate on other axis")
WriteLine(fw,"        p.xz += vec2(p.z, -p.x) * nudge;")
WriteLine(fw,"        p.xz *= normalizer;")
        // increase the frequency
WriteLine(fw,"        iter *= 1.733733;")
WriteLine(fw,"    }")
WriteLine(fw,"    return n;")
WriteLine(fw,"}")
WriteLine(fw,"float VolumetricExplosion(vec3 p)")
WriteLine(fw,"{")
WriteLine(fw,"    float final = Sphere(p,4.);")
WriteLine(fw,"    #ifdef LOW_QUALITY")
WriteLine(fw,"    final += noise(p*12.5)*.2;")
WriteLine(fw,"    #else")
WriteLine(fw,"    final += fbm(p*50.);")
WriteLine(fw,"    #endif")
WriteLine(fw,"    final += SpiralNoiseC(p.zxy*0.4132+333.)*3.0; //1.25;")
WriteLine(fw,"    return final;")
WriteLine(fw,"}")
WriteLine(fw,"float map(vec3 p) ")
WriteLine(fw,"{")
WriteLine(fw,"	R(p.xz, mouse.x*0.008*pi+time*0.1);")
WriteLine(fw,"	float VolExplosion = VolumetricExplosion(p/0.5)*0.5; // scale")
WriteLine(fw,"	return VolExplosion;")
WriteLine(fw,"}")
//--------------------------------------------------------------
// assign color to the media
WriteLine(fw,"vec3 computeColor( float density, float radius )")
WriteLine(fw,"{")
	// color based on density alone, gives impression of occlusion within
	// the media
WriteLine(fw,"	vec3 result = mix( vec3(1.0,0.9,0.8), vec3(0.4,0.15,0.1), density );")
	// color added to the media
WriteLine(fw,"	vec3 colCenter = 7.*vec3(0.8,1.0,1.0);")
WriteLine(fw,"	vec3 colEdge = 1.5*vec3(0.48,0.53,0.5);")


WriteLine(fw,"	result *= mix( colCenter, colEdge, min( (radius+.05)/.9, 1.15 ) );")
WriteLine(fw,"	return result;")
WriteLine(fw,"}")
WriteLine(fw,"bool RaySphereIntersect(vec3 org, vec3 dir, out float near, out float far)")
WriteLine(fw,"{")
WriteLine(fw,"	float b = dot(dir, org);")
WriteLine(fw,"	float c = dot(org, org) - 8.;")
WriteLine(fw,"	float delta = b*b - c;")
WriteLine(fw,"	if( delta < 0.0) ")
WriteLine(fw,"		return false;")
WriteLine(fw,"	float deltasqrt = sqrt(delta);")
WriteLine(fw,"	near = -b - deltasqrt;")
WriteLine(fw,"	far = -b + deltasqrt;")
WriteLine(fw,"	return far > 0.0;")
WriteLine(fw,"}")
// Applies the filmic curve from John Hable's presentation
// More details at : http://filmicgames.com/archives/75
WriteLine(fw,"vec3 ToneMapFilmicALU(vec3 _color)")
WriteLine(fw,"{")
WriteLine(fw,"	_color = max(vec3(0), _color - vec3(0.004));")
WriteLine(fw,"	_color = (_color * (6.2*_color + vec3(0.5))) / (_color * (6.2 * _color + vec3(1.7)) + vec3(0.06));")
WriteLine(fw,"	return _color;")
WriteLine(fw,"}")
WriteLine(fw,"void main( void )")
WriteLine(fw,"{ ") 
WriteLine(fw,"    	vec2 uv = gl_FragCoord.xy/iResolution.xy;")
	// ro: ray origin
	// rd: direction of the ray
WriteLine(fw,"	vec3 rd = normalize(vec3((gl_FragCoord.xy-0.5*iResolution.xy)/iResolution.y, 1.));")
WriteLine(fw,"	vec3 ro = vec3(0., 0., -6.);")
WriteLine(fw,"	#ifdef DITHERING")
WriteLine(fw,"	vec2 seed = uv + fract(time);")
WriteLine(fw,"	#endif ")
	// ld, td: local, total density 
	// w: weighting factor
WriteLine(fw,"	float ld=0., td=0., w=0.;")
	// t: length of the ray
	// d: distance function
WriteLine(fw,"	float d=1., t=0.;")
WriteLine(fw,"   	const float h = 0.1;")
WriteLine(fw,"	vec4 sum = vec4(0.0);")
WriteLine(fw,"    	float min_dist=0.0, max_dist=0.0;")
WriteLine(fw,"   	if(RaySphereIntersect(ro, rd, min_dist, max_dist))") 
 WriteLine(fw,"{")
WriteLine(fw,"	t = min_dist*step(t,min_dist);")
	// raymarch loop
WriteLine(fw,"   	#ifdef LOW_QUALITY")
WriteLine(fw,"	for (int i=0; i<56; i++)")
WriteLine(fw,"    	#else")
WriteLine(fw,"    	for (int i=0; i<86; i++)")
WriteLine(fw,"    	#endif")
WriteLine(fw,"	{")
WriteLine(fw,"	    vec3 pos = ro + t*rd;")
	    // Loop break conditions.
WriteLine(fw,"	    if(td>0.9 || d<0.12*t || t>10. || sum.a > 0.99 || t>max_dist) break;")
	    // evaluate distance function
WriteLine(fw,"	    float d = map(pos);")
        
WriteLine(fw,"	    #ifdef BOTH")
WriteLine(fw,"	    if (uv.x<0.5)")
WriteLine(fw,"	    {")
WriteLine(fw,"            	d = abs(d)+0.07;")
WriteLine(fw,"	    }")
WriteLine(fw,"	    #else")
WriteLine(fw,"	    #ifdef LEFT")
WriteLine(fw,"	    d = abs(d)+0.07;")
WriteLine(fw,"	    #endif")
WriteLine(fw,"	    #endif")
	    // change this string to control density 
WriteLine(fw,"	    d = max(d,0.03);")
	    // point light calculations
WriteLine(fw,"	    vec3 ldst = vec3(0.0)-pos;")
WriteLine(fw,"	    float lDist = max(length(ldst), 0.001);")
	    // the color of light 
WriteLine(fw,"	    vec3 lightColor=vec3(1.0,0.5,0.25);")
WriteLine(fw,"	    sum.rgb+=(lightColor/exp(lDist*lDist*lDist*.08)/30.); // bloom")
WriteLine(fw,"	    if (d<h)") 
WriteLine(fw,"	    {")
	    // compute local density 
WriteLine(fw,"	    ld = h - d;")
	    // compute weighting factor 
WriteLine(fw,"	    w = (1. - td) * ld;")
	    // accumulate density
WriteLine(fw,"	    td += w + 1./200.;")
WriteLine(fw,"	    vec4 col = vec4( computeColor(td,lDist), td );")
            // emission
WriteLine(fw,"            sum += sum.a * vec4(sum.rgb, 0.0) * 0.2 / lDist;	")
	    // uniform scale density
WriteLine(fw,"	    col.a *= 0.2;")
	    // colour by alpha
WriteLine(fw,"	    col.rgb *= col.a;")
	    // alpha blend in contribution
WriteLine(fw,"	    sum = sum + col*(1.0 - sum.a);  ")
WriteLine(fw,"	    }")
WriteLine(fw,"	    td += 1./70.;")
WriteLine(fw,"	    #ifdef DITHERING")
WriteLine(fw,"	    d=abs(d)*(.8+0.2*rand(seed*vec2(i)));")
WriteLine(fw,"	    #endif ")
	    // trying to optimize step size
WriteLine(fw,"	    #ifdef LOW_QUALITY")
WriteLine(fw,"	    t += max(d*0.25,0.01);")
WriteLine(fw,"	    #else")
WriteLine(fw,"	    t += max(d * 0.08 * max(min(length(ldst),d),2.0), 0.01);")
WriteLine(fw,"	    #endif")
WriteLine(fw,"	}")
	// simple scattering
WriteLine(fw,"	#ifdef LOW_QUALITY    ")
WriteLine(fw,"	sum *= 1. / exp( ld * 0.2 ) * 0.9;")
WriteLine(fw,"	#else")
WriteLine(fw,"	sum *= 1. / exp( ld * 0.2 ) * 0.8;")
WriteLine(fw,"	#endif")
WriteLine(fw,"  	sum = clamp( sum, 0.0, 1.0 );")   
WriteLine(fw,"	sum.xyz = sum.xyz*sum.xyz*(3.0-2.0*sum.xyz);")
WriteLine(fw,"	}")
   
WriteLine(fw,"	#ifdef TONEMAPPING")
WriteLine(fw,"	gl_FragColor = vec4(ToneMapFilmicALU(sum.xyz*2.2),1.0);")
WriteLine(fw,"	#else")
WriteLine(fw,"	gl_FragColor = vec4(sum.xyz,1.0);")
WriteLine(fw,"	#endif")
WriteLine(fw,"}")
CloseFile(fw)
endfunction


Three 2D Circuit Shaders
+ Code Snippet
SetErrorMode(2)
#constant KEY_SPACE	  = 32  //the space bar
// set window properties
SetWindowTitle( "circuit" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()
CreateSprite(1,0)
CreateSprite(2,0)
CreateSprite(3,0)

NoiseInit()
SetSpriteImage (3,createRandomBgImage()) 
SetSpriteAdditionalImage (3,generateperlinimage(),1) 

SetSpriteSize(1,1024,768)
SetSpriteSize(2,1024,768)
SetSpriteSize(3,1024,768)

LoadSpriteShader(1,"circuit.ps")
LoadSpriteShader(2,"circuit2.ps")
LoadSpriteShader(3,"circuit3.ps")


SetSpriteShader( 1,1 )
SetSpriteShader( 2,2 )
SetSpriteShader( 3,3 )

SetShaderConstantByName(1,"resolution",1024,768,0,0)
SetShaderConstantByName(2,"resolution",1024,768,0,0)
SetShaderConstantByName(3,"iResolution",1024,768,0,0)

num=1
SetSpriteDepth(num,0) 
do 
	print("press space to switch shaders")
	If GetRawKeyPressed(KEY_SPACE)
		if num = 1
			num=2:SetSpriteDepth(1,10):SetSpriteDepth(2,0):SetSpriteDepth(3,10)
		elseif num =2
			num=3:SetSpriteDepth(1,10):SetSpriteDepth(2,10):SetSpriteDepth(3,0)
		else
			num=1:SetSpriteDepth(1,0):SetSpriteDepth(2,10):SetSpriteDepth(3,10)			
		endif
	endif	
    SetShaderConstantByName(num,"time",timer(),0,0,0)
    print(num)
    sync()   
loop

function createShaderFile()

fw=OpenToWrite("circuit.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"float iTime = 0.0;")
WriteLine(fw,"vec3  iResolution = vec3(0.0);")
WriteLine(fw,"#define texture(s, uv) vec4(0.0)")
WriteLine(fw,"#define textureLod(s, uv, lod) vec4(0.0)")
WriteLine(fw,"#define time iTime*.02")
WriteLine(fw,"#define width .005")
WriteLine(fw,"float zoom = .18;")
WriteLine(fw,"float shape=0.;")
WriteLine(fw,"vec3 color=vec3(0.),randcol;")
WriteLine(fw,"void formula(vec2 z, float c) {")
WriteLine(fw,"	float minit=0.;")
WriteLine(fw,"	float o,ot2,ot=ot2=1000.;")
WriteLine(fw,"	for (int i=0; i<9; i++) {")
WriteLine(fw,"		z=abs(z)/clamp(dot(z,z),.1,.5)-c;")
WriteLine(fw,"		float l=length(z);")
WriteLine(fw,"		o=min(max(abs(min(z.x,z.y)),-l+.25),abs(l-.25));")
WriteLine(fw,"		ot=min(ot,o);")
WriteLine(fw,"		ot2=min(l*.1,ot2);")
WriteLine(fw,"		minit=max(minit,float(i)*(1.-abs(sign(ot-o))));")
WriteLine(fw,"	}")
WriteLine(fw,"	minit+=1.;")
WriteLine(fw,"	float w=width*minit*2.;")
WriteLine(fw,"	float circ=pow(max(0.,w-ot2)/w,6.);")
WriteLine(fw,"	shape+=max(pow(max(0.,w-ot)/w,.25),circ);")
WriteLine(fw,"	vec3 col=normalize(.1+texture(iChannel1,vec2(minit*.1)).rgb);")
WriteLine(fw,"	color+=col*(.4+mod(minit/9.-time*10.+ot2*2.,1.)*1.6);")
WriteLine(fw,"	color+=vec3(1.,.7,.3)*circ*(10.-minit)*3.*smoothstep(0.,.5,.15+texture(iChannel0,vec2(.0,1.)).x-.5);")
WriteLine(fw,"}")
WriteLine(fw,"void mainImage( out vec4 fragColor, in vec2 fragCoord )")
WriteLine(fw,"{")
WriteLine(fw,"	vec2 pos = fragCoord.xy / iResolution.xy - .5;")
WriteLine(fw,"	pos.x*=iResolution.x/iResolution.y;")
WriteLine(fw,"	vec2 uv=pos;")
WriteLine(fw,"	float sph = length(uv); sph = sqrt(1. - sph*sph); // curve for spheric distortion")
WriteLine(fw,"	uv=normalize(vec3(uv,sph)).xy;")
WriteLine(fw,"	float a=.5+mod(.5,1.)*.5;")
WriteLine(fw,"	vec2 luv=uv;")
WriteLine(fw,"	float b=a*5.48535;")
WriteLine(fw,"//	zoom*=1.+sin(time*3.758123)*.8;")
WriteLine(fw,"	uv*=mat2(cos(b),sin(b),-sin(b),cos(b));")
WriteLine(fw,"	uv+=vec2(sin(a),cos(a*.5))*8.;")
WriteLine(fw,"	uv*=zoom;")
WriteLine(fw,"	float pix=.5/iResolution.x*zoom/sph;")
WriteLine(fw,"	float dof=max(1.,(10.-mod(time,1.)/.01));")
WriteLine(fw,"	float c=1.5+mod(floor(time),6.)*.125;")
WriteLine(fw,"	for (int aa=0; aa<36; aa++) {")
WriteLine(fw,"		vec2 aauv=floor(vec2(float(aa)/6.,mod(float(aa),6.)));")
WriteLine(fw,"		formula(uv+aauv*pix*dof,c);")
WriteLine(fw,"	}")
WriteLine(fw,"	shape/=36.; color/=36.;")
WriteLine(fw,"	vec3 colo=mix(vec3(.15),color,shape)*(1.-length(pos))*min(1.,abs(.5-mod(time+.5,1.))*10.);	")
WriteLine(fw,"	colo*=vec3(1.2,1.1,1.0);")
WriteLine(fw,"	fragColor = vec4(colo,1.0);")
WriteLine(fw,"}")
WriteLine(fw,"#undef time")
WriteLine(fw,"void main(void)")
WriteLine(fw,"{")
WriteLine(fw,"    iTime = time;")
WriteLine(fw,"    iResolution = vec3(resolution, 0.0);")
WriteLine(fw,"    mainImage(gl_FragColor, gl_FragCoord.xy);")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("circuit2.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"float iTime = 0.0;")
WriteLine(fw,"vec3  iResolution = vec3(0.0);")
WriteLine(fw,"#define texture(s, uv) vec4(0.0)")
WriteLine(fw,"#define textureLod(s, uv, lod) vec4(0.0)")
WriteLine(fw,"#define time iTime*.009")
WriteLine(fw,"#define width .005")
WriteLine(fw,"float zoom = .18;")
WriteLine(fw,"float shape=0.;")
WriteLine(fw,"vec3 color=vec3(0.),randcol;")
WriteLine(fw,"void formula(vec2 z, float c) {")
WriteLine(fw,"	float minit=0.;")
WriteLine(fw,"	float o,ot2,ot=ot2=1000.;")
WriteLine(fw,"	for (int i=0; i<9; i++) {")
WriteLine(fw,"		z=abs(z)/clamp(dot(z,z),.1,.5)-c;")
WriteLine(fw,"		float l=length(z);")
WriteLine(fw,"		o=min(max(abs(min(z.x,z.y)),-l+.25),abs(l-.25));")
WriteLine(fw,"		ot=min(ot,o);")
WriteLine(fw,"		ot2=min(l*.1,ot2);")
WriteLine(fw,"		minit=max(minit,float(i)*(1.-abs(sign(ot-o))));")
WriteLine(fw,"	}")
WriteLine(fw,"	minit+=1.;")
WriteLine(fw,"	float w=width*minit*2.;")
WriteLine(fw,"	float circ=pow(max(0.,w-ot2)/w,6.);")
WriteLine(fw,"	shape+=max(pow(max(0.,w-ot)/w,.25),circ);")
WriteLine(fw,"	vec3 col=normalize(.1+texture(iChannel1,vec2(minit*.1)).rgb);")
WriteLine(fw,"	color+=col*(.4+mod(minit/9.-time*10.+ot2*2.,1.)*1.6);")
WriteLine(fw,"	color+=vec3(1.,.7,.3)*circ*(10.-minit)*3.*smoothstep(0.,.5,.15+texture(iChannel0,vec2(.0,1.)).x-.5);")
WriteLine(fw,"}")
WriteLine(fw,"void mainImage( out vec4 fragColor, in vec2 fragCoord )")
WriteLine(fw,"{")
WriteLine(fw,"	vec2 pos = fragCoord.xy / iResolution.xy - .5;")
WriteLine(fw,"	pos.x*=iResolution.x/iResolution.y;")
WriteLine(fw,"	vec2 uv=pos;")
WriteLine(fw,"	float sph = length(uv); sph = sqrt(1. - sph*sph)*1.5; // curve for spheric distortion")
WriteLine(fw,"	uv=normalize(vec3(uv,sph)).xy;")
WriteLine(fw,"	float a=time+mod(time,1.)*.5;")
WriteLine(fw,"	vec2 luv=uv;")
WriteLine(fw,"	float b=a*5.48535;")
WriteLine(fw,"//	zoom*=1.+sin(time*3.758123)*.8;")
WriteLine(fw,"	uv*=mat2(cos(b),sin(b),-sin(b),cos(b));")
WriteLine(fw,"	uv+=vec2(sin(a),cos(a*.5))*8.;")
WriteLine(fw,"	uv*=zoom;")
WriteLine(fw,"	float pix=.5/iResolution.x*zoom/sph;")
WriteLine(fw,"	float dof=max(1.,(10.-mod(time,1.)/.01));")
WriteLine(fw,"	float c=1.5+mod(floor(time),6.)*.125;")
WriteLine(fw,"	for (int aa=0; aa<36; aa++) {")
WriteLine(fw,"		vec2 aauv=floor(vec2(float(aa)/6.,mod(float(aa),6.)));")
WriteLine(fw,"		formula(uv+aauv*pix*dof,c);")
WriteLine(fw,"	}")
WriteLine(fw,"	shape/=36.; color/=36.;")
WriteLine(fw,"	vec3 colo=mix(vec3(.15),color,shape)*(1.-length(pos))*min(1.,abs(.5-mod(time+.5,1.))*10.);	")
WriteLine(fw,"	colo*=vec3(1.2,1.1,1.0);")
WriteLine(fw,"	fragColor = vec4(colo,1.0);")
WriteLine(fw,"}")
WriteLine(fw,"#undef time")
WriteLine(fw,"void main(void)")
WriteLine(fw,"{")
WriteLine(fw,"    iTime = time;")
WriteLine(fw,"    iResolution = vec3(resolution, 0.0);")
WriteLine(fw,"    mainImage(gl_FragColor, gl_FragCoord.xy);")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("circuit3.ps")
WriteLine(fw,"uniform vec3      iResolution;     // viewport resolution (in pixels)")
WriteLine(fw,"uniform float     time;     		 // shader playback time (in seconds)")
WriteLine(fw,"uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"uniform sampler2D texture1;")
WriteLine(fw,"#define iTime time*.02")
WriteLine(fw,"#define width .005")
WriteLine(fw,"float zoom = .18;")
WriteLine(fw,"float shape=0.;")
WriteLine(fw,"vec3 color=vec3(0.),randcol;")
WriteLine(fw,"void formula(vec2 z, float c) {")
WriteLine(fw,"	float minit=0.;")
WriteLine(fw,"	float o,ot2,ot=ot2=1000.;")
WriteLine(fw,"	for (int i=0; i<9; i++) {")
WriteLine(fw,"		z=abs(z)/clamp(dot(z,z),.1,.5)-c;")
WriteLine(fw,"		float l=length(z);")
WriteLine(fw,"		o=min(max(abs(min(z.x,z.y)),-l+.25),abs(l-.25));")
WriteLine(fw,"		ot=min(ot,o);")
WriteLine(fw,"		ot2=min(l*.1,ot2);")
WriteLine(fw,"		minit=max(minit,float(i)*(1.-abs(sign(ot-o))));")
WriteLine(fw,"	}")
WriteLine(fw,"	minit+=1.;")
WriteLine(fw,"	float w=width*minit*2.;")
WriteLine(fw,"	float circ=pow(max(0.,w-ot2)/w,6.);")
WriteLine(fw,"	shape+=max(pow(max(0.,w-ot)/w,.25),circ);")
WriteLine(fw,"	vec3 col=normalize(.1+texture2D(texture1,vec2(minit*.1)).rgb);")
WriteLine(fw,"	color+=col*(.4+mod(minit/9.-iTime*10.+ot2*2.,1.)*1.6);")
WriteLine(fw,"	color+=vec3(1.,.7,.3)*circ*(10.-minit)*3.*smoothstep(0.,.5,.15+texture2D(texture0,vec2(.0,1.)).x-.5);")
WriteLine(fw,"}")
WriteLine(fw,"void main(void)")
WriteLine(fw,"{")
WriteLine(fw,"	vec2 pos = gl_FragCoord.xy / iResolution.xy - .5;")
WriteLine(fw,"	pos.x*=iResolution.x/iResolution.y;")
WriteLine(fw,"	vec2 uv=pos;")
WriteLine(fw,"	float sph = length(uv); sph = sqrt(1. - sph*sph)*1.5; // curve for spheric distortion")
WriteLine(fw,"	uv=normalize(vec3(uv,sph)).xy;")
WriteLine(fw,"	float a=iTime+mod(iTime,1.)*.5;")
WriteLine(fw,"	vec2 luv=uv;")
WriteLine(fw,"	float b=a*5.48535;")
WriteLine(fw,"	//	zoom*=1.+sin(iTime*3.758123)*.8;")
WriteLine(fw,"	uv*=mat2(cos(b),sin(b),-sin(b),cos(b));")
WriteLine(fw,"	uv+=vec2(sin(a),cos(a*.5))*8.;")
WriteLine(fw,"	uv*=zoom;")
WriteLine(fw,"	float pix=.5/iResolution.x*zoom/sph;")
WriteLine(fw,"	float dof=max(1.,(10.-mod(iTime,1.)/.01));")
WriteLine(fw,"	float c=1.5+mod(floor(iTime),6.)*.125;")
WriteLine(fw,"	for (int aa=0; aa<36; aa++) {")
WriteLine(fw,"		vec2 aauv=floor(vec2(float(aa)/6.,mod(float(aa),6.)));")
WriteLine(fw,"		formula(uv+aauv*pix*dof,c);")
WriteLine(fw,"	}")
WriteLine(fw,"	shape/=36.; color/=36.;")
WriteLine(fw,"	vec3 colo=mix(vec3(.15),color,shape)*(1.-length(pos))*min(1.,abs(.5-mod(iTime+.5,1.))*10.);	")
WriteLine(fw,"	colo*=vec3(1.2,1.1,1.0);")
WriteLine(fw,"	gl_FragColor = vec4(colo,1.0);")
WriteLine(fw,"}")
CloseFile(fw)
endfunction
//creates texture 0 for sprite 3
function createRandomBgImage()
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    For num = 1 to 500
		DrawEllipse(Random(1,1023),Random(1,787),random(10,30),random(10,30),makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),1)
    next num
    swap()
    img = getimage(0,0,1024,768)
    //SetImageTransparentColor(img,0,0,0)
endfunction img

//the rest just creates a noise image for texture 1 for sprite x

function generateperlinimage()
    // Generate image from memblock
w as integer = 100
h as integer =100    
size = w * h * 4 + 12
mem = CreateMemblock(size)
SetMemblockInt(mem,0,w)
SetMemblockInt(mem,4,h)
SetMemblockInt(mem,8,32)
   
offset as integer = 12
a as float, b as float
a = 5.0
b = 2.0
   
for y = 0 to h - 1
    for x = 0 to w - 1
        a = a + 0.0001
        b = b + 0.002
           
        // Try out these two noise methods
        //noise = 255.0*Noise2D(x/10.0,y/10.0)
        noise = 255.0*Noise2D(x/100.0,y/100.0)
           
        noise = abs(noise)
          
        
        //clouds
        if noise>200
            SetMemblockByte(mem, offset, noise)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, noise)
            SetMemblockByte(mem, offset+3, 255)
        endif
          
   
         //greenary
        if noise>150 and noise<=200
            SetMemblockByte(mem, offset, 0)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, 0)
            SetMemblockByte(mem, offset+3, 255)
        endif
        //sand
        if noise>100 and noise<=150
            SetMemblockByte(mem, offset, noise)
            SetMemblockByte(mem, offset+1, noise)
            SetMemblockByte(mem, offset+2, 0)
            SetMemblockByte(mem, offset+3, 255)
        endif
        // water
        if noise<=100
            SetMemblockByte(mem, offset, 0)
            SetMemblockByte(mem, offset+1, 0)
            SetMemblockByte(mem, offset+2, noise)
            SetMemblockByte(mem, offset+3, 255)
        endif
        offset = offset + 4
    next
next
   
map=CreateImageFromMemblock(mem)
endfunction map
 
// ***************************************************************************************************
// Ken Perlin's Simplex Noise 2D. AGK Version.
// Ported from Stefan Gustavson's Java implementation
// (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf)
// 2015.02.03
// AGK reference https://forum.thegamecreators.com/thread/213532
// Thank you Thank you 
   
#constant PN3DF2 = 0.5*(sqrt(3.0)-1.0)
#constant PN3DG2 = (3.0-sqrt(3.0))/6.0
   
Type sPNVECTOR
    x as float
    y as float
    z as float
endtype
   
Global PNHash as integer[512]
Global PNGrad3 as sPNVECTOR[256]
   
   
Function NoiseInit()
    Local n as integer, rn as integer
    For n=0 To 255
        PNHash[n] = n
    Next n 
    For n=0 To 255
        rn=Random(0, 255) 
        PNHash.swap(n,rn)
    Next n
    For n=0 To 255
        PNHash[256 + n] = PNHash[n]
    Next n
    PNHash[511] = PNHash[0]
   
    For n=0 To 15
        PNGrad3[n * 16 + 0].x = 1 : PNGrad3[n * 16 + 0].y = 1 : PNGrad3[n * 16 + 0].z = 0
        PNGrad3[n * 16 + 1].x = -1 : PNGrad3[n * 16 + 1].y = 1 : PNGrad3[n * 16 + 1].z = 0
        PNGrad3[n * 16 + 2].x = 1 : PNGrad3[n * 16 + 2].y = -1 : PNGrad3[n * 16 + 2].z = 0
        PNGrad3[n * 16 + 3].x = -1 : PNGrad3[n * 16 + 3].y = -1 : PNGrad3[n * 16 + 3].z = 0
   
        PNGrad3[n * 16 + 4].x = 1 : PNGrad3[n * 16 + 4].y = 0 : PNGrad3[n * 16 + 4].z = 1
        PNGrad3[n * 16 + 5].x = -1 : PNGrad3[n * 16 + 5].y = 0 : PNGrad3[n * 16 + 5].z = 1
        PNGrad3[n * 16 + 6].x = 1 : PNGrad3[n * 16 + 6].y = 0 : PNGrad3[n * 16 + 6].z = -1
        PNGrad3[n * 16 + 7].x = -1 : PNGrad3[n * 16 + 7].y = 0 : PNGrad3[n * 16 + 7].z = -1
   
        PNGrad3[n * 16 + 8].x = 0 : PNGrad3[n * 16 + 8].y = 1 : PNGrad3[n * 16 + 8].z = 1
        PNGrad3[n * 16 + 9].x = 0 : PNGrad3[n * 16 + 9].y = -1 : PNGrad3[n * 16 + 9].z = 1
        PNGrad3[n * 16 + 10].x = 0 : PNGrad3[n * 16 + 10].y = 1 : PNGrad3[n * 16 + 10].z = -1
        PNGrad3[n * 16 + 11].x = 0 : PNGrad3[n * 16 + 11].y = -1 : PNGrad3[n * 16 + 11].z = -1
   
        PNGrad3[n * 16 + 12].x = 1 : PNGrad3[n * 16 + 12].y = 1 : PNGrad3[n * 16 + 12].z = 0
        PNGrad3[n * 16 + 13].x = -1 : PNGrad3[n * 16 + 13].y = 1 : PNGrad3[n * 16 + 13].z = 0
        PNGrad3[n * 16 + 14].x = 0 : PNGrad3[n * 16 + 14].y = -1 : PNGrad3[n * 16 + 14].z = 1
        PNGrad3[n * 16 + 15].x = 0 : PNGrad3[n * 16 + 15].y = -1 : PNGrad3[n * 16 + 15].z = -1
    Next n 
endfunction
   
function Noise2D(xin as float, yin as float)
    local n0 as float, n1 as float, n2 as float, s as float, t as float, x0 as float, y0 as float, xs as float, ys as float
    local i as integer, j as integer, i1 as integer, j1 as integer, i2 as integer, j2 as integer, gi0 as integer, gi1 as integer, gi2 as integer
    local x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float, t0 as float, t1 as float, t2 as float
       
    s = (xin + yin) * PN3DF2
    xs = xin + s
   
    i = floor(xs)
    ys = yin + s
   
    j = floor(ys)
    t = (i + j) * PN3DG2
   
    x0 = xin - (i - t)
    y0 = yin - (j - t)
   
    if x0>y0
        i1=1
        j1=0
    else
        i1=0
        j1=1
    endif
   
    x1 = x0 - i1 + PN3DG2
    y1 = y0 - j1 + PN3DG2
    x2 = x0 - 1.0 + 2.0 * PN3DG2
    y2 = y0 - 1.0 + 2.0 * PN3DG2
   
    i = i && 255
    j = j && 255
   
    gi0 =  PNHash[i + PNHash[j]] && 15
    gi1 = PNHash[i + i1 + PNHash[j + j1]] && 15
    gi2 = PNHash[i + 1 + PNHash[j+ 1]] && 15
   
    t0 = 0.5 - x0*x0-y0*y0
    if t0<0
        n0 = 0.0
    else
        t0 = t0 * t0
        n0 = t0 * t0 * (PNGrad3[gi0].x * x0 + PNGrad3[gi0].y * y0)
    endif
   
    t1 = 0.5 - x1*x1-y1*y1
    if t1<0
        n1 = 0.0
    else
        t1 = t1 * t1
        n1 = t1 * t1 * (PNGrad3[gi1].x * x1 + PNGrad3[gi1].y * y1)
    endif
   
    t2 = 0.5 - x2*x2-y2*y2
    if t2<0
        n2 = 0.0
    else
        t2 = t2 * t2
        n2 = t2 * t2 * (PNGrad3[gi2].x * x2 + PNGrad3[gi2].y * y2)
    endif
   
endfunction  70.0 * (n0 + n1 + n2)
Posted: 12th Aug 2018 5:40
Scanlines Shader
+ Code Snippet
SetErrorMode(2)

// set window properties
SetWindowTitle( "Scanlines" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createVSShaderFile()
createPSshaderFile()

chunk = CreateObjectPlane(1000,1000)
SetObjectColor(chunk,255,255,255,255)
Shader=LoadShader("scanlines.vs","scanlines.ps")
SetObjectShader(chunk,Shader)
SetShaderConstantByName( Shader,"iResolution",1024,768,0,0 )

do
    //SetShaderConstantByName( Shader,"iResolution",Timer()*100,Timer()*100,0,0 )
    SetShaderConstantByName( Shader,"time",Timer()*.5,0,0,0 )


    Print( ScreenFPS() )
    Sync()

loop



// This is the function which creates the two files VS and PS
// These just simply output lines of code to the two files

function createVSShaderFile()
	
    fw = OpenToWrite("scanlines.vs")
    WriteLine(fw,"attribute highp vec3 position;")
    WriteLine(fw,"attribute mediump vec3 normal;")
    WriteLine(fw,"varying highp vec3 posVarying;")
    WriteLine(fw,"varying mediump vec3 normalVarying;")
    WriteLine(fw,"varying mediump vec3 lightVarying;")
    WriteLine(fw,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
    WriteLine(fw,"uniform highp mat3 agk_WorldNormal;")
    WriteLine(fw,"uniform highp mat4 agk_World;")
    WriteLine(fw,"uniform highp mat4 agk_ViewProj;")
    WriteLine(fw,"attribute highp vec2 uv;")
    WriteLine(fw,"varying highp vec2 uvVarying;")
    WriteLine(fw,"uniform highp vec4 uvBounds0;")
     
    WriteLine(fw,"void main()")
    WriteLine(fw,"{ ")
    WriteLine(fw,"uvVarying = uv * uvBounds0.xy + uvBounds0.zw;")
    WriteLine(fw,"highp vec4 pos = agk_World * vec4(position,1.0);")
    WriteLine(fw,"mediump vec3 norm = normalize(agk_WorldNormal * normal);")
    WriteLine(fw,"gl_Position = agk_ViewProj * pos;")
    WriteLine(fw,"posVarying = pos.xyz;")
    WriteLine(fw,"normalVarying = norm;")
    WriteLine(fw,"lightVarying = GetVSLighting( norm, posVarying );")
    WriteLine(fw,"}")
    CloseFile(fw)	
endfunction

function createPSshaderFile()

fw=OpenToWrite("scanlines.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"uniform vec2 iResolution;")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"#define num 60.0")
WriteLine(fw,"float random(vec2 p){")
WriteLine(fw,"	return fract(sin(dot(p, vec2(12.9898,78.233))) * 43758.5453+time*4.0);	")
WriteLine(fw,"}")
WriteLine(fw,"void main() {")
WriteLine(fw,"    	vec2 p = ( gl_FragCoord.xy / (iResolution.xy) );")
WriteLine(fw,"	//- vec2(0.5, 0.5);")
WriteLine(fw,"	//vec2 p = (gl_FragCoord.xy * 2.0 - iResolution.xy) / min(iResolution.x, iResolution.y) - vec2(.5 , .5);")
WriteLine(fw,"    	float top, bottom, linewidth;")
WriteLine(fw,"	float offSet = 0.5;")
WriteLine(fw,"	float span = 0.01;")
WriteLine(fw,"	linewidth = 0.01;")
WriteLine(fw,"  	top = fract(time);")
WriteLine(fw,"	bottom = fract(time) + linewidth;")
WriteLine(fw,"	vec4 border = vec4(0.0, 0.0, 0.0, 1.0);")
WriteLine(fw,"	for(float i = 1.0; i < num; i++){")
WriteLine(fw,"		top += i * span; ")
WriteLine(fw,"		top = fract(top);")
WriteLine(fw,"		bottom += i *span;")
WriteLine(fw,"		bottom = fract(bottom);")
WriteLine(fw,"		if(p.y > top && p.y < bottom){")
WriteLine(fw,"		border = vec4(abs(1.0 * sin(time)), 0.0, 0.0, 1.0);")
WriteLine(fw,"		}")
WriteLine(fw,"	}")
WriteLine(fw,"	float c = random(p);")
WriteLine(fw,"	vec3 col = mix(vec3(c, c, c), border.xyz, 0.6);")
WriteLine(fw,"	//float r = mix(c, border.x, 0.6);")
WriteLine(fw,"	//vec4 col= vec4(mix(vec3(p, p, p), border.xyz), 1.0);")
WriteLine(fw,"   	gl_FragColor = vec4(col, 1.0);")
WriteLine(fw,"	/*")
WriteLine(fw,"	if(p.y < -0.5){")
WriteLine(fw,"		gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);")
WriteLine(fw,"	*/")
WriteLine(fw,"	}")
CloseFile(fw)
endfunction


2D Pixelate Shader
+ Code Snippet
SetErrorMode(2)

// set window properties
SetWindowTitle( "Pixelate" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()
imgId=createRandomBgImage()
CreateSprite(1,imgId)
LoadSpriteShader(2, "pixelate.ps")
SetSpriteShader( 1,2 )
do
    SetShaderConstantByName(2,"pixels",1024/5,768/5,0,0) //the bigger the numbers the more pixels
    sync()   
loop

function createShaderFile()

fw=OpenToWrite("pixelate.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"precision mediump int;")
WriteLine(fw,"#endif")
WriteLine(fw,"#define PROCESSING_TEXTURE_SHADER")
WriteLine(fw,"varying mediump vec2 uvVarying;")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"uniform vec2 pixels;")
WriteLine(fw,"void main(void)")
WriteLine(fw,"{")
WriteLine(fw,"  vec2 p = uvVarying;")
WriteLine(fw,"	p.x -= mod(p.x, 1.0 / pixels.x);")
WriteLine(fw,"	p.y -= mod(p.y, 1.0 / pixels.y);")
WriteLine(fw,"	vec3 col = texture2D(texture0, p).rgb;")
WriteLine(fw,"	gl_FragColor = vec4(col, 1.0);")
WriteLine(fw,"}")
CloseFile(fw)
endfunction

function createRandomBgImage()
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    For num = 1 to 500
		DrawEllipse(Random(1,1023),Random(1,787),random(10,30),random(10,30),makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),1)
    next num
    swap()
    img = getimage(0,0,1024,768)
    //SetImageTransparentColor(img,0,0,0)
endfunction img

you could change SetShaderConstantByName(2,"pixels",1024/5,768/5,0,0) //the bigger the numbers the more pixels
to this SetShaderConstantByName(2,"pixels",1024/timer(),768/timer(),0,0) //the bigger the numbers the more pixels
for effect
Posted: 14th Aug 2018 6:27
2D Fireball Shader
+ Code Snippet
// set window properties
SetWindowTitle( "fireball" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()
CreateSprite(1,0)
SetSpriteSize(1,1024,768)
LoadSpriteShader(1,"fireball.ps")
SetSpriteShader( 1,1 )

SetShaderConstantByName(1,"resolution",1024,768 ,0,0)
do 
	SetShaderConstantByName(1,"time",timer(),0,0,0)
	//SetShaderConstantByName(1,"mouse",GetPointerX(),getPointery(),0,0)
	
    sync()   
loop
function createShaderFile()

fw=OpenToWrite("fireball.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision highp float;")
WriteLine(fw,"#endif")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"//uniform float zoom;")
WriteLine(fw,"#define saturate(oo) clamp(oo, 0.0, 1.0)")
WriteLine(fw,"// Quality Settings")
WriteLine(fw,"#define MarchSteps 6")
WriteLine(fw,"// Scene Settings")
WriteLine(fw,"#define ExpPosition vec3(0.0)")
WriteLine(fw,"#define Radius 2.0")
WriteLine(fw,"#define Background vec4(0.1, 0.0, 0.0, 1.0)")
WriteLine(fw,"// Noise Settings")
WriteLine(fw,"#define NoiseSteps 4")
WriteLine(fw,"#define NoiseAmplitude 0.1")
WriteLine(fw,"#define NoiseFrequency 2.2")
WriteLine(fw,"#define Animation vec3(0.0, -3.0, 0.5)")
WriteLine(fw,"// Colour Gradient")
WriteLine(fw,"#define Color1 vec4(1.0, 1.0, 1.0, 1.0)")
WriteLine(fw,"#define Color2 vec4(1.0, 0.8, 0.2, 1.0)")
WriteLine(fw,"#define Color3 vec4(1.0, 0.03, 0.0, 1.0)")
WriteLine(fw,"#define Color4 vec4(0.05, 0.02, 0.02, 1.0)")
WriteLine(fw,"//noise functions.")
WriteLine(fw,"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }")
WriteLine(fw,"vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }")
WriteLine(fw,"vec4 permute(vec4 x) { return mod289(((x*34.0)+1.0)*x); }")
WriteLine(fw,"vec4 taylorInvSqrt(vec4 r){ return 1.79284291400159 - 0.85373472095314 * r; }")
WriteLine(fw,"float snoise(vec3 v)")
WriteLine(fw,"{")
WriteLine(fw,"	const vec2  C = vec2(1.0/6.0, 1.0/3.0);")
WriteLine(fw,"	const vec4  D = vec4(0.0, 0.5, 1.0, 2.0);")
WriteLine(fw,"	// First corner")
WriteLine(fw,"	vec3 i  = floor(v + dot(v, C.yyy));")
WriteLine(fw,"	vec3 x0 = v - i + dot(i, C.xxx);")
WriteLine(fw,"	// Other corners")
WriteLine(fw,"	vec3 g = step(x0.yzx, x0.xyz);")
WriteLine(fw,"	vec3 l = 1.0 - g;")
WriteLine(fw,"	vec3 i1 = min(g.xyz, l.zxy);")
WriteLine(fw,"	vec3 i2 = max(g.xyz, l.zxy);")
WriteLine(fw,"	vec3 x1 = x0 - i1 + C.xxx;")
WriteLine(fw,"	vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y")
WriteLine(fw,"	vec3 x3 = x0 - D.yyy;      // -1.0+3.0*C.x = -0.5 = -D.y")
WriteLine(fw,"// Permutations")
WriteLine(fw,"	i = mod289(i);")
WriteLine(fw,"	vec4 p = permute( permute( permute( i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));")
WriteLine(fw,"  // Gradients: 7x7 points over a square, mapped onto an octahedron.")
WriteLine(fw,"	// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)")
WriteLine(fw,"	float n_ = 0.142857142857; // 1.0/7.0")
WriteLine(fw,"	vec3  ns = n_ * D.wyz - D.xzx;")
WriteLine(fw,"	vec4 j = p - 49.0 * floor(p * ns.z * ns.z);  //  mod(p,7*7)")
WriteLine(fw,"  vec4 x_ = floor(j * ns.z);")
WriteLine(fw,"	vec4 y_ = floor(j - 7.0 * x_);    // mod(j,N)")
WriteLine(fw,"	vec4 x = x_ *ns.x + ns.yyyy;")
WriteLine(fw,"	vec4 y = y_ *ns.x + ns.yyyy;")
WriteLine(fw,"	vec4 h = 1.0 - abs(x) - abs(y);")
WriteLine(fw,"	vec4 b0 = vec4(x.xy, y.xy);")
WriteLine(fw,"	vec4 b1 = vec4(x.zw, y.zw);")
WriteLine(fw,"	vec4 s0 = floor(b0) * 2.0 + 1.0;")
WriteLine(fw,"	vec4 s1 = floor(b1) * 2.0 + 1.0;")
WriteLine(fw,"	vec4 sh = -step(h, vec4(0.0));")
WriteLine(fw,"	vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;")
WriteLine(fw,"	vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;")
WriteLine(fw,"	vec3 p0 = vec3(a0.xy, h.x);")
WriteLine(fw,"	vec3 p1 = vec3(a0.zw, h.y);")
WriteLine(fw,"	vec3 p2 = vec3(a1.xy, h.z);")
WriteLine(fw,"	vec3 p3 = vec3(a1.zw, h.w);")
WriteLine(fw,"	//Normalise gradients")
WriteLine(fw,"  vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));")
WriteLine(fw,"  p0 *= norm.x;")
WriteLine(fw,"	p1 *= norm.y;")
WriteLine(fw,"	p2 *= norm.z;")
WriteLine(fw,"	p3 *= norm.w;")
WriteLine(fw,"  // Mix final noise value")
WriteLine(fw,"  vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);")
WriteLine(fw,"  m = m * m;")
WriteLine(fw,"  return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3)));")
WriteLine(fw,"}")
WriteLine(fw,"float Turbulence(vec3 position, float minFreq, float maxFreq, float qWidth)")
WriteLine(fw,"{")
WriteLine(fw,"	float value = 0.0;")
WriteLine(fw,"	float cutoff = clamp(0.5/qWidth, 0.0, maxFreq);")
WriteLine(fw,"	float fade;")
WriteLine(fw,"	float fOut = minFreq;")
WriteLine(fw,"	for(int i=NoiseSteps ; i>=0 ; i++)")
WriteLine(fw,"	{")
WriteLine(fw,"		if(fOut >= 0.5 * cutoff) break;")
WriteLine(fw,"		fOut *= 2.0;")
WriteLine(fw,"		value += abs(snoise(position * fOut))/fOut;")
WriteLine(fw,"	}")
WriteLine(fw,"  fade = clamp(2.0 * (cutoff-fOut)/cutoff, 0.0, 1.0);")
WriteLine(fw,"	value += fade * abs(snoise(position * fOut))/fOut;")
WriteLine(fw,"	return 1.0-value;")
WriteLine(fw,"}")
WriteLine(fw,"float SphereDist(vec3 position)")
WriteLine(fw,"{")
WriteLine(fw,"	return length(position - ExpPosition) - Radius;")
WriteLine(fw,"}")
WriteLine(fw,"vec4 Shade(float distance)")
WriteLine(fw,"{")
WriteLine(fw,"	float c1 = saturate(distance*5.0 + 0.5);")
WriteLine(fw,"	float c2 = saturate(distance*5.0);")
WriteLine(fw,"	float c3 = saturate(distance*3.4 - 0.5);")
WriteLine(fw,"	vec4 a = mix(Color1,Color2, c1);")
WriteLine(fw,"	vec4 b = mix(a,     Color3, c2);")
WriteLine(fw,"	return 	 mix(b,     Color4, c3);")
WriteLine(fw,"}")
WriteLine(fw,"// Draws the scene")
WriteLine(fw,"float RenderScene(vec3 position, out float distance)")
WriteLine(fw,"{")
WriteLine(fw,"	float noise = Turbulence(position * NoiseFrequency + Animation*time, 0.1, 1.5, 0.03) * NoiseAmplitude;")
WriteLine(fw,"	noise = saturate(abs(noise));")
WriteLine(fw,"	distance = SphereDist(position) - noise;")
WriteLine(fw,"	return noise;")
WriteLine(fw,"}")
WriteLine(fw,"// Basic ray marching method.")
WriteLine(fw,"vec4 March(vec3 rayOrigin, vec3 rayStep)")
WriteLine(fw,"{")
WriteLine(fw,"	vec3 position = rayOrigin;")
WriteLine(fw,"	float distance;")
WriteLine(fw,"	float displacement;")
WriteLine(fw,"	for(int step = MarchSteps; step >=0  ; --step)")
WriteLine(fw,"	{")
WriteLine(fw,"		displacement = RenderScene(position, distance);")
WriteLine(fw,"		if(distance < 0.05) break;")
WriteLine(fw,"		position += rayStep * distance;")
WriteLine(fw,"	}")
WriteLine(fw,"  return mix(Shade(displacement), Background, float(distance >= 0.5));")
WriteLine(fw,"}")
WriteLine(fw,"bool IntersectSphere(vec3 ro, vec3 rd, vec3 pos, float radius, out vec3 intersectPoint)")
WriteLine(fw,"{")
WriteLine(fw,"	vec3 relDistance = (ro - pos);")
WriteLine(fw,"	float b = dot(relDistance, rd);")
WriteLine(fw,"	float c = dot(relDistance, relDistance) - radius*radius;")
WriteLine(fw,"	float d = b*b - c;")
WriteLine(fw,"	intersectPoint = ro + rd*(-b - sqrt(d));")
WriteLine(fw,"	return d >= 0.0;")
WriteLine(fw,"}")
WriteLine(fw,"void main(void)")
WriteLine(fw,"{")
WriteLine(fw,"	vec2 p = (gl_FragCoord.xy / resolution.xy) * 2.0 - 1.0;")
WriteLine(fw,"	p.x *= resolution.x/resolution.y;")
WriteLine(fw,"	float rotx = mouse.y * 4.0;")
WriteLine(fw,"	float roty = -mouse.x * 4.0;")
WriteLine(fw,"	float zoom = 5.0;")
WriteLine(fw,"	// camera")
WriteLine(fw,"	vec3 ro = zoom * normalize(vec3(cos(roty), cos(rotx), sin(roty)));")
WriteLine(fw,"	vec3 ww = normalize(vec3(0.0, 0.0, 0.0) - ro);")
WriteLine(fw,"	vec3 uu = normalize(cross( vec3(0.0, 1.0, 0.0), ww));")
WriteLine(fw,"	vec3 vv = normalize(cross(ww, uu));")
WriteLine(fw,"	vec3 rd = normalize(p.x*uu + p.y*vv + 1.5*ww);")
WriteLine(fw,"	vec4 col = Background;")
WriteLine(fw,"	vec3 origin;")
WriteLine(fw,"	if(IntersectSphere(ro, rd, ExpPosition, Radius + NoiseAmplitude*6.0, origin))")
WriteLine(fw,"	{")
WriteLine(fw,"		col = March(origin, rd);")
WriteLine(fw,"	}")
WriteLine(fw,"	gl_FragColor = col;")
WriteLine(fw,"}")

CloseFile(fw)
endfunction


2D Basic Fractal Shader
+ Code Snippet
// set window properties
SetWindowTitle( "basic fractal" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()
CreateSprite(1,0)
SetSpriteSize(1,1024,768)
LoadSpriteShader(1,"basicfractal.ps")
SetSpriteShader( 1,1 )

SetShaderConstantByName(1,"iResolution",1024,768 ,0,0)
do 
	SetShaderConstantByName(1,"iGlobalTime",timer(),0,0,0)
	//SetShaderConstantByName(1,"iMouse",GetPointerX(),getPointery(),0,0)
	
    sync()   
loop
function createShaderFile()

fw=OpenToWrite("basicfractal.ps")
WriteLine(fw,"//basic fractal")
WriteLine(fw,"uniform vec3      iResolution;     // viewport resolution (in pixels)")
WriteLine(fw,"uniform float     iGlobalTime;     // shader playback time (in seconds)")
WriteLine(fw,"uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click")
WriteLine(fw,"//uniform sampler2D iChannel0;")
WriteLine(fw,"const int maxIterations=6;//a nice value for fullscreen is 8")
WriteLine(fw,"float circleSize=1.0/(3.0*pow(2.0,float(maxIterations)));")
WriteLine(fw,"//generic rotation formula")
WriteLine(fw,"vec2 rot(vec2 uv,float a){")
WriteLine(fw,"	return vec2(uv.x*cos(a)-uv.y*sin(a),uv.y*cos(a)+uv.x*sin(a));")
WriteLine(fw,"}")
WriteLine(fw,"void main(void){")
WriteLine(fw,"	//normalize stuff")
WriteLine(fw,"	vec2 uv=iResolution.xy;uv=-.5*(uv-2.0*gl_FragCoord.xy)/uv.x;")
WriteLine(fw,"	//global rotation and zoom")
WriteLine(fw,"	uv=rot(uv,iGlobalTime);")
WriteLine(fw,"	uv*=sin(iGlobalTime)*0.5+1.5;")
WriteLine(fw,"	//mirror, rotate and scale 6 times...")
WriteLine(fw,"	float s=0.3;")
WriteLine(fw,"	for(int i=0;i<maxIterations;i++){")
WriteLine(fw,"		uv=abs(uv)-s;")
WriteLine(fw,"		uv=rot(uv,iGlobalTime);")
WriteLine(fw,"		s=s/2.1;")
WriteLine(fw,"	}")
WriteLine(fw,"	//draw a circle")
WriteLine(fw,"	float c=length(uv)>circleSize?0.0:1.0;	")
WriteLine(fw,"	gl_FragColor = vec4(c,c,c,1.0);")
WriteLine(fw,"}")
CloseFile(fw)
endfunction


2D Flame Shader
+ Code Snippet
// set window properties
SetWindowTitle( "flame" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()
CreateSprite(1,0)
SetSpriteSize(1,1024,768)
LoadSpriteShader(1,"flame.ps")
SetSpriteShader( 1,1 )

SetShaderConstantByName(1,"iResolution",1024,768 ,0,0)
do 
	SetShaderConstantByName(1,"iGlobalTime",timer(),0,0,0)
	//SetShaderConstantByName(1,"iMouse",GetPointerX(),getPointery(),0,0)
	
    sync()   
loop
function createShaderFile()

fw=OpenToWrite("flame.ps")
WriteLine(fw,"//flame")
WriteLine(fw,"uniform vec3      iResolution;     // viewport resolution (in pixels)")
WriteLine(fw,"uniform float     iGlobalTime;     // shader playback time (in seconds)")
WriteLine(fw,"uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click")
WriteLine(fw,"uniform sampler2D iChannel0;")
WriteLine(fw,"float noise(vec3 p) //Thx to Las^Mercury")
WriteLine(fw,"{")
WriteLine(fw,"	vec3 i = floor(p);")
WriteLine(fw,"	vec4 a = dot(i, vec3(1., 57., 21.)) + vec4(0., 57., 21., 78.);")
WriteLine(fw,"	vec3 f = cos((p-i)*acos(-1.))*(-.5)+.5;")
WriteLine(fw,"	a = mix(sin(cos(a)*a),sin(cos(1.+a)*(1.+a)), f.x);")
WriteLine(fw,"	a.xy = mix(a.xz, a.yw, f.y);")
WriteLine(fw,"	return mix(a.x, a.y, f.z);")
WriteLine(fw,"}")
WriteLine(fw,"// Scene/Objects")
WriteLine(fw,"float sphere(vec3 p, vec4 spr)")
WriteLine(fw,"{")
WriteLine(fw,"	return length(spr.xyz-p) - spr.w;")
WriteLine(fw,"}")
WriteLine(fw,"float fire(vec3 p)")
WriteLine(fw,"{")
WriteLine(fw,"	float d= sphere(p*vec3(1.,.5,1.), vec4(.0,-1.,.0,1.));")
WriteLine(fw,"	return d+(noise(p+vec3(.0,iGlobalTime*2.,.0))+noise(p*3.)*.5)*.25*(p.y) ;")
WriteLine(fw,"}")
WriteLine(fw,"// Raymarching tools")
WriteLine(fw,"float scene(vec3 p)")
WriteLine(fw,"{")
WriteLine(fw,"	return min(100.-length(p) , abs(fire(p)) );")
WriteLine(fw,"}")
WriteLine(fw,"vec4 Raymarche(vec3 org, vec3 dir)")
WriteLine(fw,"{")
WriteLine(fw,"	float d=0.0;")
WriteLine(fw,"	vec3  p=org;")
WriteLine(fw,"	float glow = 0.0;")
WriteLine(fw,"	float eps = 0.02;")
WriteLine(fw,"	bool glowed=false;")
WriteLine(fw,"	for(int i=0; i<64; i++)")
WriteLine(fw,"	{")
WriteLine(fw,"		d = scene(p) + eps;")
WriteLine(fw,"		p += d * dir;")
WriteLine(fw,"		if( d>eps )")
WriteLine(fw,"		{")
WriteLine(fw,"			if( fire(p) < .0)")
WriteLine(fw,"				glowed=true;")
WriteLine(fw,"			if(glowed)")
WriteLine(fw,"       		glow = float(i)/64.;")
WriteLine(fw,"		}")
WriteLine(fw,"	}")
WriteLine(fw,"	return vec4(p,glow);")
WriteLine(fw,"}")
WriteLine(fw,"// Main functions")
WriteLine(fw,"void main()")
WriteLine(fw,"{")
WriteLine(fw,"	vec2 v = -1.0 + 2.0 * gl_FragCoord.xy / iResolution.xy;")
WriteLine(fw,"	v.x *= iResolution.x/iResolution.y;")
WriteLine(fw,"	vec3 org = vec3(0.,-2.,4.);")
WriteLine(fw,"	vec3 dir   = normalize(vec3(v.x*1.6,-v.y,-1.5));")
WriteLine(fw,"	vec4 p = Raymarche(org,dir);")
WriteLine(fw,"	float glow = p.w;")
WriteLine(fw,"	gl_FragColor = mix(vec4(0.), mix(vec4(1.,.5,.1,1.),vec4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.));")
WriteLine(fw,"	//gl_FragColor = mix(vec4(1.), mix(vec4(1.,.5,.1,1.),vec4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.));")
WriteLine(fw,"}")
CloseFile(fw)
endfunction
Posted: 14th Aug 2018 7:52
Heres a variation on the 2D Basic Fractal that makes use of the texture images colors
+ Code Snippet
// set window properties
SetWindowTitle( "basic fractal" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()
CreateSprite(1,0)
SetSpriteImage(1,createRandomBgImage())
SetSpriteSize(1,1024,768)
LoadSpriteShader(1,"basicfractal.ps")
SetSpriteShader( 1,1 )

SetShaderConstantByName(1,"iResolution",1024,768 ,0,0)
do 
	SetShaderConstantByName(1,"iGlobalTime",timer(),0,0,0)
	//SetShaderConstantByName(1,"iMouse",GetPointerX(),getPointery(),0,0)
	
    sync()   
loop
function createShaderFile()

fw=OpenToWrite("basicfractal.ps")
WriteLine(fw,"//basic fractal")
WriteLine(fw,"uniform vec3      iResolution;     // viewport resolution (in pixels)")
WriteLine(fw,"uniform float     iGlobalTime;     // shader playback time (in seconds)")
WriteLine(fw,"uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"varying mediump vec2 uvVarying;")
WriteLine(fw,"const int maxIterations=6;//a nice value for fullscreen is 8")
WriteLine(fw,"float circleSize=1.0/(3.0*pow(2.0,float(maxIterations)));")
WriteLine(fw,"//generic rotation formula")
WriteLine(fw,"vec2 rot(vec2 uv,float a){")
WriteLine(fw,"	return vec2(uv.x*cos(a)-uv.y*sin(a),uv.y*cos(a)+uv.x*sin(a));")
WriteLine(fw,"}")
WriteLine(fw,"void main(void){")
WriteLine(fw,"	//normalize stuff")
WriteLine(fw,"	vec2 uv=iResolution.xy;uv=-.5*(uv-2.0*gl_FragCoord.xy)/uv.x;")
WriteLine(fw,"	//global rotation and zoom")
WriteLine(fw,"	uv=rot(uv,iGlobalTime);")
WriteLine(fw,"	uv*=sin(iGlobalTime)*0.5+1.5;")
WriteLine(fw,"	//mirror, rotate and scale 6 times...")
WriteLine(fw,"	float s=0.3;")
WriteLine(fw,"	for(int i=0;i<maxIterations;i++){")
WriteLine(fw,"		uv=abs(uv)-s;")
WriteLine(fw,"		uv=rot(uv,iGlobalTime);")
WriteLine(fw,"		s=s/2.1;")
WriteLine(fw,"	}")
WriteLine(fw,"	//draw a circle")
WriteLine(fw,"	//float c=length(uv)>circleSize?0.0:1.0;	")
WriteLine(fw,"	float r=length(uv)>circleSize?0.0:texture2D(texture0,uvVarying).r;	")
WriteLine(fw,"	float g=length(uv)>circleSize?0.0:texture2D(texture0,uvVarying).g;	")
WriteLine(fw,"	float b=length(uv)>circleSize?0.0:texture2D(texture0,uvVarying).b;	")
WriteLine(fw,"//	gl_FragColor = vec4(c,c,c,1.0);")
WriteLine(fw,"	gl_FragColor = vec4(r,g,b,1.0);")

WriteLine(fw,"}")
CloseFile(fw)
endfunction

function createRandomBgImage()
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    For num = 1 to 1000
		DrawEllipse(Random(1,1023),Random(1,787),random(10,30),random(10,30),makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),1)
    next num
    swap()
    img = getimage(0,0,1024,768)
    //SetImageTransparentColor(img,0,0,0)
endfunction img


2D Lightning Shader
+ Code Snippet
// Project: lightning
// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "lightning" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()

CreateSprite(1,0)
SetSpriteSize(1,1024,768)
LoadSpriteShader(2, "lightning.ps")
SetSpriteShader( 1,2 )
//changing the resolution x will effect where the lightning casts from
//so with a sprite 1024 wide resolution setting to 1024 will set it in 
//the middle of the sprite while setting to 2048 for example shifts it
//to the right 
SetShaderConstantByName(2,"resolution",1024,768,0,0)

do
	SetShaderConstantByName(2,"resolution",GetPointerX()*2,768,0,0)
	SetShaderConstantByName(2,"time",timer()*.25,0,0,0)
    Print( ScreenFPS() )
    Sync()

loop

function createShaderFile()

fw=OpenToWrite("lightning.ps")
WriteLine(fw,"precision lowp float;")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2  resolution;")
WriteLine(fw,"const float count = 2.0;")
WriteLine(fw,"float Hash( vec2 p, in float s ){")
WriteLine(fw,"    return fract(sin(dot(vec3(p.xy,15.0 * abs(sin(s))),vec3(27.1,61.7, 12.4)))*273758.5453123);")
WriteLine(fw,"}")
WriteLine(fw,"float noise(in vec2 p, in float s)")
WriteLine(fw,"{")
WriteLine(fw,"    vec2 i = floor(p);")
WriteLine(fw,"    vec2 f = fract(p);")
WriteLine(fw,"    f *= f * (3.0-2.0*f);")
WriteLine(fw,"    return mix(mix(Hash(i + vec2(0.,0.), s), Hash(i + vec2(1.,0.), s),f.x),mix(Hash(i + vec2(0.,1.), s), Hash(i + vec2(1.,1.), s),f.x),f.y) * s;")
WriteLine(fw,"}")
WriteLine(fw,"float fbm(vec2 p)")
WriteLine(fw,"{")
WriteLine(fw,"     float v = 0.0;")
WriteLine(fw,"     v += noise(p*6., 0.35);")
WriteLine(fw,"     v += noise(p*2., 0.25);")
WriteLine(fw,"     v += noise(p*4., 0.125);")
WriteLine(fw,"     v += noise(p*16., 0.0625);")
WriteLine(fw,"     return v;")
WriteLine(fw,"}")
WriteLine(fw,"void main( void ) ")
WriteLine(fw,"{")
WriteLine(fw,"	vec2 location= ( gl_FragCoord.xy / resolution.xy ) * 2.0 - 1.0;")
WriteLine(fw,"	location.x*= resolution.x/resolution.y;")
WriteLine(fw,"	vec3 finalColor = vec3( 0.0 );")
WriteLine(fw,"		float t = abs(1.0 / ((location.x + fbm( location + time * 5.0)) * (50.0)));")
WriteLine(fw,"		finalColor +=  t * vec3( 0.375 +0.1, 0.5, 2.0 );")
WriteLine(fw,"	gl_FragColor = vec4( finalColor, 3.0 );")
WriteLine(fw,"}")
CloseFile(fw)
endfunction
Posted: 18th Aug 2018 0:08
A 2D Checkerboard effect I have been working with that I believe would be good while you are creating your gameworld great for pixelated games or perhaps Minecraft
+ Code Snippet
SetErrorMode(2)

// set window properties
SetWindowTitle( "Color Checkerboard" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()
CreateSprite(1,0)
SetSpriteSize(1,1024,768)
LoadSpriteShader(2, "colorcheckerboard.ps")
SetSpriteShader( 1,2 )
SetShaderConstantByName(2,"resolution",1024,768,0,0)
SetSpriteTransparency(1,2)

CreateSprite(2,createBgImage())
//SetSpriteColor(2,255,255,0,255)
SetSpriteSize(2,1024,768)
SetSpriteDepth(2,20)
do
	SetShaderConstantByName(2,"time",timer(),0,0,0)
    Print( ScreenFPS() )
    Sync()

loop

function createShaderFile()

fw=OpenToWrite("colorcheckerboard.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"float random(in vec2 uv){")
WriteLine(fw,"	return fract(sin(dot(uv, vec2(12.9898,78.233))) * 43758.5453);")
WriteLine(fw,"}")
WriteLine(fw,"float randomTile(in vec2 uv) {")
WriteLine(fw,"	return random(floor(uv));")
WriteLine(fw,"}")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 uv = (gl_FragCoord.xy * 2.0 -  resolution.xy) / min(resolution.x, resolution.y);")
WriteLine(fw,"	uv *= 8.0;")
WriteLine(fw,"	vec3 color = vec3(0.0);")                //use this line if you dont want to use a texture
WriteLine(fw,"//  vec3 color = texture2D(texture0, uv).rgb;")  //use this line if you want to use a texture
WriteLine(fw,"	color.rgb += sin(randomTile(uv) * time * 5.0);")
WriteLine(fw,"	float alpha=random(vec2(0.0,1.0));")         //use this for spritetansparency mode 2
WriteLine(fw,"//	float alpha=random(vec2(0.0,1.0))*5.0;") //use this for spritetansparency mode 1
WriteLine(fw,"  color = clamp(color,0.0,1.0);")
WriteLine(fw,"	gl_FragColor = vec4(color,alpha);")
WriteLine(fw,"}")
CloseFile(fw)
endfunction

function createBgImage()
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    DrawBox(0,0,1024,768,makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),1)
    swap()
    img = getimage(0,0,1024,768)
    SetImageTransparentColor(img,0,0,0)
endfunction img

function createRandomBgImage()
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    For num = 1 to 500
		DrawEllipse(Random(1,1023),Random(1,787),random(10,30),random(10,30),makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),1)
    next num
    swap()
    img = getimage(0,0,1024,768)
    //SetImageTransparentColor(img,0,0,0)
endfunction img

There are setting that you may wish to play around with


Amiga plasma effect
+ Code Snippet
SetErrorMode(2)

// set window properties
SetWindowTitle( "amigaplasma" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()

CreateSprite(1,0)
SetSpriteSize(1,1024,768)
LoadSpriteShader(2, "amigaplasma.ps")
SetSpriteShader( 1,2 )
SetShaderConstantByName(2,"resolution",1024,768,0,0)

do
	//SetShaderConstantByName(2,"resolution",GetPointerX()*2,768,0,0)
	SetShaderConstantByName(2,"time",timer()*.25,0,0,0)
    Print( ScreenFPS() )
    Sync()

loop

function createShaderFile()

fw=OpenToWrite("amigaplasma.ps")
//random color checkerboard
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"#define r resolution")
WriteLine(fw,"#define t time")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 p=gl_FragCoord.xy/r;")	
WriteLine(fw,"	p= floor(p*32.)/32.;")
WriteLine(fw,"	vec3 a=vec3(0.5, 0.5, 0.5);")
WriteLine(fw,"	vec3 b=vec3(0.5, 0.5, 0.5);")
WriteLine(fw,"	vec3 c=vec3(t/4., t*0.4, t/2.);")
WriteLine(fw,"	vec3 d=vec3(0.0, 0.33, 0.67);")
WriteLine(fw,"	vec3 col = b+a*sin(8.0*(c+p.y+sin(p.x+p.x+t) ));")
WriteLine(fw,"	     col*= b+a*sin(10.0*(c+p.y+cos(p.y+p.y+t) ));")
WriteLine(fw,"	gl_FragColor=vec4(col.rgb, 1.0);")
WriteLine(fw,"}")
CloseFile(fw)
endfunction


Heated Flames with smoke and sparks try playing around with sprite 1 transparency and use a proper background image for sprite 2
+ Code Snippet
 
SetErrorMode(2)

// set window properties
SetWindowTitle( "heated flames" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

createShaderFile()
img=LoadImage("Australia.png")
CreateSprite(1,0)
SetSpriteSize(1,1024,768)
SetSpriteTransparency(1,2)
LoadSpriteShader(2, "heatedFlames.ps")
SetSpriteShader( 1,2 )
SetShaderConstantByName(2,"resolution",1024,768/3,0,0)

CreateSprite(2,0)  //sets a dark grey backgound behind the flame
SetSpriteColor(2,55,55,55,255)
SetSpriteSize(2,1024,768)
SetSpriteDepth(2,20)

do
	//SetShaderConstantByName(2,"resolution",GetPointerX()*2,768,0,0)
	SetShaderConstantByName(2,"time",timer(),0,0,0)
    Print( ScreenFPS() )
    Sync()

loop

function createShaderFile()

fw=OpenToWrite("heatedFlames.ps")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"//uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"vec3 mod289(vec3 x) {")
WriteLine(fw,"	return x - floor(x * (1.0 / 289.0)) * 289.0;")
WriteLine(fw,"}")
WriteLine(fw,"vec4 mod289(vec4 x) {")
WriteLine(fw,"	return x - floor(x * (1.0 / 289.0)) * 289.0;")
WriteLine(fw,"}")
WriteLine(fw,"vec4 permute(vec4 x) {")
WriteLine(fw,"		 return mod289(((x*34.0)+1.0)*x);")
WriteLine(fw,"}")
WriteLine(fw,"vec4 taylorInvSqrt(vec4 r)")
WriteLine(fw,"{")
WriteLine(fw,"	return 1.79284291400159 - 0.85373472095314 * r;")
WriteLine(fw,"}")
WriteLine(fw,"float snoise(vec3 v)")
WriteLine(fw,"	{ ")
WriteLine(fw,"	const vec2	C = vec2(1.0/6.0, 1.0/3.0) ;")
WriteLine(fw,"	const vec4	D = vec4(0.0, 0.5, 1.0, 2.0);")
WriteLine(fw,"// First corner")
WriteLine(fw,"	vec3 i	= floor(v + dot(v, C.yyy) );")
WriteLine(fw,"	vec3 x0 =	 v - i + dot(i, C.xxx) ;")
WriteLine(fw,"// Other corners")
WriteLine(fw,"	vec3 g = step(x0.yzx, x0.xyz);")
WriteLine(fw,"	vec3 l = 1.0 - g;")
WriteLine(fw,"	vec3 i1 = min( g.xyz, l.zxy );")
WriteLine(fw,"	vec3 i2 = max( g.xyz, l.zxy );")
WriteLine(fw,"	//	 x0 = x0 - 0.0 + 0.0 * C.xxx;")
WriteLine(fw,"	//	 x1 = x0 - i1	+ 1.0 * C.xxx;")
WriteLine(fw,"	//	 x2 = x0 - i2	+ 2.0 * C.xxx;")
WriteLine(fw,"	//	 x3 = x0 - 1.0 + 3.0 * C.xxx;")
WriteLine(fw,"	vec3 x1 = x0 - i1 + C.xxx;")
WriteLine(fw,"	vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y")
WriteLine(fw,"	vec3 x3 = x0 - D.yyy;			// -1.0+3.0*C.x = -0.5 = -D.y")
WriteLine(fw,"// Permutations")
WriteLine(fw,"	i = mod289(i); ")
WriteLine(fw,"	vec4 p = permute( permute( permute( ")
WriteLine(fw,"						 i.z + vec4(0.0, i1.z, i2.z, 1.0 ))")
WriteLine(fw,"					 + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) ")
WriteLine(fw,"					 + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));")
WriteLine(fw,"// Gradients: 7x7 points over a square, mapped onto an octahedron.")
WriteLine(fw,"// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)")
WriteLine(fw,"	float n_ = 0.142857142857; // 1.0/7.0")
WriteLine(fw,"	vec3	ns = n_ * D.wyz - D.xzx;")
WriteLine(fw,"	vec4 j = p - 49.0 * floor(p * ns.z * ns.z);	//	mod(p,7*7)")
WriteLine(fw,"	vec4 x_ = floor(j * ns.z);")
WriteLine(fw,"	vec4 y_ = floor(j - 7.0 * x_ );		// mod(j,N)")
WriteLine(fw,"	vec4 x = x_ *ns.x + ns.yyyy;")
WriteLine(fw,"	vec4 y = y_ *ns.x + ns.yyyy;")
WriteLine(fw,"	vec4 h = 1.0 - abs(x) - abs(y);")
WriteLine(fw,"	vec4 b0 = vec4( x.xy, y.xy );")
WriteLine(fw,"	vec4 b1 = vec4( x.zw, y.zw );")
WriteLine(fw,"	//vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;")
WriteLine(fw,"	//vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;")
WriteLine(fw,"	vec4 s0 = floor(b0)*2.0 + 1.0;")
WriteLine(fw,"	vec4 s1 = floor(b1)*2.0 + 1.0;")
WriteLine(fw,"	vec4 sh = -step(h, vec4(0.0));")
WriteLine(fw,"	vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;")
WriteLine(fw,"	vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;")
WriteLine(fw,"	vec3 p0 = vec3(a0.xy,h.x);")
WriteLine(fw,"	vec3 p1 = vec3(a0.zw,h.y);")
WriteLine(fw,"	vec3 p2 = vec3(a1.xy,h.z);")
WriteLine(fw,"	vec3 p3 = vec3(a1.zw,h.w);")
WriteLine(fw,"//Normalise gradients")
WriteLine(fw,"	//vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));")
WriteLine(fw,"	vec4 norm = inversesqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));")
WriteLine(fw,"	p0 *= norm.x;")
WriteLine(fw,"	p1 *= norm.y;")
WriteLine(fw,"	p2 *= norm.z;")
WriteLine(fw,"	p3 *= norm.w;")
WriteLine(fw,"// Mix final noise value")
WriteLine(fw,"	vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);")
WriteLine(fw,"	m = m * m;")
WriteLine(fw,"	return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), ")
WriteLine(fw,"																dot(p2,x2), dot(p3,x3) ) );")
WriteLine(fw,"	}")
WriteLine(fw,"// PRNG")
WriteLine(fw,"float prng(in vec2 seed) {")
WriteLine(fw,"	seed = fract (seed * vec2 (5.3983, 5.4427));")
WriteLine(fw,"	seed += dot (seed.yx, seed.xy + vec2 (21.5351, 14.3137));")
WriteLine(fw,"	return fract (seed.x * seed.y * 95.4337);")
WriteLine(fw,"}")
WriteLine(fw,"float PI = 3.1415926535897932384626433832795;")
WriteLine(fw,"float noiseStack(vec3 pos,int octaves,float falloff){")
WriteLine(fw,"	float noise = snoise(vec3(pos));")
WriteLine(fw,"	float off = 1.0;")
WriteLine(fw,"	if (octaves>1) {")
WriteLine(fw,"		pos *= 2.0;")
WriteLine(fw,"		off *= falloff;")
WriteLine(fw,"		noise = (1.0-off)*noise + off*snoise(vec3(pos));")
WriteLine(fw,"	}")
WriteLine(fw,"	if (octaves>2) {")
WriteLine(fw,"		pos *= 2.0;")
WriteLine(fw,"		off *= falloff;")
WriteLine(fw,"		noise = (1.0-off)*noise + off*snoise(vec3(pos));")
WriteLine(fw,"	}")
WriteLine(fw,"	if (octaves>3) {")
WriteLine(fw,"		pos *= 2.0;")
WriteLine(fw,"		off *= falloff;")
WriteLine(fw,"		noise = (1.0-off)*noise + off*snoise(vec3(pos));")
WriteLine(fw,"	}")
WriteLine(fw,"	return (1.0+noise)/2.0;")
WriteLine(fw,"}")
WriteLine(fw,"vec2 noiseStackUV(vec3 pos,int octaves,float falloff,float diff){")
WriteLine(fw,"	float displaceA = noiseStack(pos,octaves,falloff);")
WriteLine(fw,"	float displaceB = noiseStack(pos+vec3(3984.293,423.21,5235.19),octaves,falloff);")
WriteLine(fw,"	return vec2(displaceA,displaceB);")
WriteLine(fw,"}")
WriteLine(fw,"void main(  ) {")
WriteLine(fw,"	vec2 drag = vec2(0.0, 0.0); //mouse.xy;")
WriteLine(fw,"	vec2 offset = vec2(0.0, 0.0); //mouse.xy;")
WriteLine(fw,"	float xpart = gl_FragCoord.x/resolution.x;")
WriteLine(fw,"	float ypart = gl_FragCoord.y/resolution.y;")
WriteLine(fw,"	//")
WriteLine(fw,"	float clip = 210.0;")
WriteLine(fw,"	float ypartClip = gl_FragCoord.y/clip;")
WriteLine(fw,"	float ypartClippedFalloff = clamp(2.0-ypartClip,0.0,1.0);")
WriteLine(fw,"	float ypartClipped = min(ypartClip,1.0);")
WriteLine(fw,"	float ypartClippedn = 1.0-ypartClipped;")
WriteLine(fw,"	float xfuel = 1.0-abs(2.0*xpart-1.0);//pow(1.0-abs(2.0*xpart-1.0),0.5);")
WriteLine(fw,"	float timeSpeed = 0.5;")
WriteLine(fw,"	float realTime = timeSpeed*time;")
WriteLine(fw,"	vec2 coordScaled = 0.01*gl_FragCoord.xy - 0.02*vec2(offset.x,0.0);")
WriteLine(fw,"	vec3 position = vec3(coordScaled,0.0) + vec3(1223.0,6434.0,8425.0);")
WriteLine(fw,"	vec3 flow = vec3(4.1*(0.5-xpart)*pow(ypartClippedn,4.0),-2.0*xfuel*pow(ypartClippedn,64.0),0.0);")
WriteLine(fw,"	vec3 timing = realTime*vec3(0.0,-1.7,1.1) + flow;")
WriteLine(fw,"	vec3 displacePos = vec3(1.0,0.5,1.0)*2.4*position+realTime*vec3(0.01,-0.7,1.3);")
WriteLine(fw,"	vec3 displace3 = vec3(noiseStackUV(displacePos,2,0.4,0.1),0.0);")
WriteLine(fw,"	vec3 noiseCoord = (vec3(2.0,1.0,1.0)*position+timing+0.4*displace3)/1.0;")
WriteLine(fw,"	float noise = noiseStack(noiseCoord,3,0.4);")
WriteLine(fw,"	float flames = pow(ypartClipped,0.3*xfuel)*pow(noise,xfuel);")
WriteLine(fw,"	float f = ypartClippedFalloff*pow(1.0-flames*flames*flames,8.0);")
WriteLine(fw,"	float fff = f*f*f;")
WriteLine(fw,"	vec3 fire = 1.5*vec3(f, fff, fff*fff);")
WriteLine(fw,"	// smoke")
WriteLine(fw,"	float smokeNoise = 0.5+snoise(0.4*position+timing*vec3(1.0,1.0,0.2))/2.0;")
WriteLine(fw,"	vec3 smoke = vec3(0.3*pow(xfuel,3.0)*pow(ypart,2.0)*(smokeNoise+0.4*(1.0-noise)));")
WriteLine(fw,"	// sparks")
WriteLine(fw,"	float sparkGridSize = 30.0;")
WriteLine(fw,"	vec2 sparkCoord = gl_FragCoord.xy - vec2(2.0*offset.x,190.0*realTime);")
WriteLine(fw,"	sparkCoord -= 30.0*noiseStackUV(0.01*vec3(sparkCoord,30.0*time),1,0.4,0.1);")
WriteLine(fw,"	sparkCoord += 100.0*flow.xy;")
WriteLine(fw,"	if (mod(sparkCoord.y/sparkGridSize,2.0)<1.0) sparkCoord.x += 0.5*sparkGridSize;")
WriteLine(fw,"	vec2 sparkGridIndex = vec2(floor(sparkCoord/sparkGridSize));")
WriteLine(fw,"	float sparkRandom = prng(sparkGridIndex);")
WriteLine(fw,"	float sparkLife = min(10.0*(1.0-min((sparkGridIndex.y+(190.0*realTime/sparkGridSize))/(24.0-20.0*sparkRandom),1.0)),1.0);")
WriteLine(fw,"	vec3 sparks = vec3(0.0);")
WriteLine(fw,"	if (sparkLife>0.0) {")
WriteLine(fw,"		float sparkSize = xfuel*xfuel*sparkRandom*0.08;")
WriteLine(fw,"		float sparkRadians = 999.0*sparkRandom*2.0*PI + 2.0*time;")
WriteLine(fw,"		vec2 sparkCircular = vec2(sin(sparkRadians),cos(sparkRadians));")
WriteLine(fw,"		vec2 sparkOffset = (0.5-sparkSize)*sparkGridSize*sparkCircular;")
WriteLine(fw,"		vec2 sparkModulus = mod(sparkCoord+sparkOffset,sparkGridSize) - 0.5*vec2(sparkGridSize);")
WriteLine(fw,"		float sparkLength = length(sparkModulus);")
WriteLine(fw,"		float sparksGray = max(0.0, 1.0 - sparkLength/(sparkSize*sparkGridSize));")
WriteLine(fw,"		sparks = sparkLife*sparksGray*vec3(1.0,0.3,0.0);")
WriteLine(fw,"	}")
WriteLine(fw,"	vec4 color = vec4(max(fire,sparks)+smoke,1.0);")
WriteLine(fw,"  color.a=(fire.r+fire.g+fire.b)+(sparks.r+sparks.g+sparks.b)+(smoke.r+smoke.g+smoke.b);")
WriteLine(fw,"	gl_FragColor = vec4(color);")
WriteLine(fw,"}")
CloseFile(fw)
endfunction
Posted: 22nd Aug 2018 22:03
11 Different Shaders all in one program press space to change (no media required)
2 types of spirals both shown with and without textures, one paralax scrolling one, 2 types of static, one with and one without texture
and a kaleidoscope effects one with texture and one without and easily changed by uncommenting lines in the shader
+ Code Snippet
SetErrorMode(2)
#constant KEY_SPACE   = 32  //the space bar
// set window properties
SetWindowTitle( "Shaders" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
img=createRandomBgImage() //used for the second type of static
createShaderFile()
CreateSprite(1,img)
SetSpriteSize(1,1024,768)
//SetSpriteTransparency(1,2)
LoadSpriteShader(1, "spiral.ps")
LoadSpriteShader(2, "spiral2.ps")
LoadSpriteShader(3, "spiral3.ps")
LoadSpriteShader(4, "spiral4.ps")
LoadSpriteShader(5, "paralaxbuildings.ps")
LoadSpriteShader(6, "static.ps")
LoadSpriteShader(7, "static2.ps")
LoadSpriteShader(8, "amigaplasma.ps")
LoadSpriteShader(9, "amigaplasma2.ps")
LoadSpriteShader(10,"kalieffect.ps")
LoadSpriteShader(11,"kalieffect2.ps")


SetSpriteShader( 1,1 )
SetShaderConstantByName(1,"resolution",1024,768,0,0)

num=1:myShader$="Spiral Selected without texture"
do
	print("press space to switch shaders")
	print(myShader$)
    If GetRawKeyPressed(KEY_SPACE)
        if num = 1
            num=2:myShader$="Spiral Selected with texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)
        elseif num = 2
            num=3:myShader$="Spiral2 Selected without texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)
        elseif num = 3
            num=4:myShader$="Spiral2 Selected with texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)
        elseif num =4
            num=5:myShader$="paralaxbuildings Selected":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)
        elseif num=5
            num=6:myShader$="static Selected without texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)     
        elseif num=6
            num=7:myShader$="static2 Selected with texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)     
        elseif num=7
            num=8:myShader$="amiga plasma Selected without texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)      
        elseif num=8
            num=9:myShader$="amiga plasma Selected with texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)      
        elseif num=9
            num=10:myShader$="Kali effect Selected without texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)      
        elseif num=10
            num=11:myShader$="Kali effect Selected with texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)      
        elseif num=11
            num=1:myShader$="Spiral Selected without texture":SetSpriteShader(1,num):SetShaderConstantByName(num,"resolution",1024,768,0,0)      
        endif
 
 
    endif  
    SetShaderConstantByName(num,"time",timer(),0,0,0)
    Print( ScreenFPS() )
    Sync()

loop

function createShaderFile()

fw=OpenToWrite("spiral.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y);")
WriteLine(fw,"	float l = length(p);")
WriteLine(fw,"	float c = step(0.1,l);")
WriteLine(fw,"	float a = atan(p.y,p.x) * 2.0;")
WriteLine(fw,"	gl_FragColor = vec4(sin(a * 10. + floor(l * 20.) * time));")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("spiral2.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"varying mediump vec2 uvVarying;")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y);")
WriteLine(fw,"	float l = length(p);")
WriteLine(fw,"	//float c = step(0.1,l);")
WriteLine(fw,"	float a = atan(p.y,p.x) * 2.0;")
WriteLine(fw,"	vec4 myCoord = vec4(sin(a * 10. + floor(l * 20.) * time));")
WriteLine(fw,"	vec4 color = texture2D(texture0,myCoord.xy).rgba*texture2D(texture0,uvVarying).rgba;")
WriteLine(fw,"	gl_FragColor = color;")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("spiral3.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"//--------------------")
WriteLine(fw,"// Archimedean_Spiral ")
WriteLine(fw,"//--------------------")
WriteLine(fw,"#define PI 3.14159265")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"float angle(vec2 v)  { return atan(v.y,v.x); }")
WriteLine(fw,"void main()")
WriteLine(fw,"{")
WriteLine(fw,"    vec2 center = resolution.xy / 2.0;")
WriteLine(fw,"    vec2 dist = center - gl_FragCoord.xy;")
WriteLine(fw,"    float time1 = time + gl_FragCoord.x*8.*mouse.x;")
WriteLine(fw,"    float theta = angle(dist) / (2.0*PI) + time*0.6;")
WriteLine(fw,"    float d = 40.0 + 2.*sin(time1*3.0);")
WriteLine(fw,"    float r = length(dist) - d*theta;")
WriteLine(fw,"    float color1 = abs(r/d - (floor(r/d)) -0.5);")
WriteLine(fw,"    float color2 = abs(fract(r/d - theta) -0.5);")
WriteLine(fw,"    gl_FragColor = vec4( smoothstep(0.1, 0.5, color1)); // simple spiral")
WriteLine(fw,"    //gl_FragColor = vec4( smoothstep(0.1, 0.5, color2)); // double spiral")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("spiral4.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"//--------------------")
WriteLine(fw,"// Archimedean_Spiral ")
WriteLine(fw,"//--------------------")
WriteLine(fw,"#define PI 3.14159265")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"varying mediump vec2 uvVarying;")
WriteLine(fw,"float angle(vec2 v)  { return atan(v.y,v.x); }")
WriteLine(fw,"void main()")
WriteLine(fw,"{")
WriteLine(fw,"    vec2 center = resolution.xy / 2.0;")
WriteLine(fw,"    vec2 dist = center - gl_FragCoord.xy;")
WriteLine(fw,"    float time1 = time + gl_FragCoord.x*8.*mouse.x;")
WriteLine(fw,"    float theta = angle(dist) / (2.0*PI) + time*0.6;")
WriteLine(fw,"    float d = 40.0 + 2.*sin(time1*3.0);")
WriteLine(fw,"    float r = length(dist) - d*theta;")
WriteLine(fw,"    float color1 = abs(r/d - (floor(r/d)) -0.5);")
WriteLine(fw,"    float color2 = abs(fract(r/d - theta) -0.5);")
WriteLine(fw,"    gl_FragColor = vec4( smoothstep(0.1, 0.5, color2))*texture2D(texture0,uvVarying).rgba; // simple spiral")
WriteLine(fw,"    //gl_FragColor = vec4( smoothstep(0.1, 0.5, color2)); // double spiral")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("paralaxbuildings.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"float noise2d(vec2 p) {")
WriteLine(fw,"	return fract(sin(dot(p.xy ,vec2(1.,1.))));")
WriteLine(fw,"}")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 p = ( gl_FragCoord.xy / resolution.xy );")
WriteLine(fw,"	float a = 0.0;")
WriteLine(fw,"	for (int i = 1; i < 20; i++) {")
WriteLine(fw,"		float fi = float(i);")
WriteLine(fw,"		float s = floor(250.0*(p.x)/fi + 50.0*fi + time);")
WriteLine(fw,"		if (p.y < noise2d(vec2(s))*fi/35.0 - fi*.05 + 1.0) {")
WriteLine(fw,"			a = float(i)/20.;")
WriteLine(fw,"		}")
WriteLine(fw,"	}")
WriteLine(fw,"	gl_FragColor = vec4(vec3(a), 1.0 );")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("static.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"float rand(vec2 co){")
WriteLine(fw,"    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);")
WriteLine(fw,"}")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 position = ( gl_FragCoord.xy / resolution.xy ) + mouse / 4.0;")
WriteLine(fw,"	float r = rand(gl_FragCoord.xy * time);")
WriteLine(fw,"	vec3 color = vec3(r);")
WriteLine(fw,"	gl_FragColor = vec4(color, 1.0);")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("static2.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"varying mediump vec2 uvVarying;")
WriteLine(fw,"float rand(vec2 co){")
WriteLine(fw,"    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);")
WriteLine(fw,"}")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 position = ( gl_FragCoord.xy / resolution.xy ) + mouse / 4.0;")
WriteLine(fw,"	float r = rand(gl_FragCoord.xy * time);")
WriteLine(fw,"	vec3 color = vec3(r)+texture2D(texture0,uvVarying).rgb;")
WriteLine(fw,"	gl_FragColor = vec4(color, 1.0);")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("amigaplasma.ps")
//random color checkerboard
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"#define r resolution")
WriteLine(fw,"#define t time")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"  vec2 p=gl_FragCoord.xy/r;") 
WriteLine(fw,"  p= floor(p*32.)/32.;")
WriteLine(fw,"  vec3 a=vec3(0.5, 0.5, 0.5);")
WriteLine(fw,"  vec3 b=vec3(0.5, 0.5, 0.5);")
WriteLine(fw,"  vec3 c=vec3(t/4., t*0.4, t/2.);")
WriteLine(fw,"  vec3 d=vec3(0.0, 0.33, 0.67);")
WriteLine(fw,"  vec3 col = b+a*sin(8.0*(c+p.y+sin(p.x+p.x+t) ));")
WriteLine(fw,"       col*= b+a*sin(10.0*(c+p.y+cos(p.y+p.y+t) ));")
WriteLine(fw,"  gl_FragColor=vec4(col.rgb, 1.0);")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("amigaplasma2.ps")
//random color checkerboard
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"varying mediump vec2 uvVarying;")
WriteLine(fw,"#define r resolution")
WriteLine(fw,"#define t time")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 p=gl_FragCoord.xy/r;")	
WriteLine(fw,"	p= floor(p*32.)/32.;")
WriteLine(fw,"	vec3 a=vec3(0.5, 0.5, 0.5);")
WriteLine(fw,"	vec3 b=vec3(0.5, 0.5, 0.5);")
WriteLine(fw,"	vec3 c=vec3(t/4., t*0.4, t/2.);")
WriteLine(fw,"	vec3 d=vec3(0.0, 0.33, 0.67);")
WriteLine(fw,"	vec3 col = b+a*sin(8.0*(c+p.y+sin(p.x+p.x+t) ));")
WriteLine(fw,"	     col*= b+a*sin(10.0*(c+p.y+cos(p.y+p.y+t) ));")
WriteLine(fw,"	gl_FragColor=vec4(col.rgb, 1.0)*texture2D(texture0,uvVarying).rgba;")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("kalieffect.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 p = abs((gl_FragCoord.xy*2.0-resolution.xy)/resolution.x);")
WriteLine(fw,"	p.x+=sin(time*0.317)*.23;")
WriteLine(fw,"	p.y+=cos(time*0.081)*.07;")
WriteLine(fw,"	float t1 = time*0.2;")
WriteLine(fw,"	mat2 rot = mat2(cos(t1),sin(t1),-sin(t1),cos(t1));")
WriteLine(fw,"	p *= 6.3;")
WriteLine(fw,"	float r = length(p);")
WriteLine(fw,"	p*=rot;")
WriteLine(fw,"	p*=0.6*cos(p.yx*1.5)*sin(p*1.3)-r*0.;")
WriteLine(fw,"  //float a =atan(p.y,p.x)*11.;")
WriteLine(fw,"	//r = a+length(p)*sin(time)*0.3;")
WriteLine(fw,"	//r = length(p)*sin(time)*0.3;")
WriteLine(fw,"	float s = sin(r*2.3+p.x*2.3-time*0.5)+sin(p.y*2.9+2.7*sin(r*0.+time*1.5));")
WriteLine(fw,"	float t = sin(r*0.+p.x*2.7+time*3.2)+sin(p.y*1.1-s+2.3*sin(r*3.3+time*0.9));")
WriteLine(fw,"	float f = (s+t);")
WriteLine(fw,"	gl_FragColor = vec4(f,f-t,t-f,1)/2.0;")
WriteLine(fw,"	//gl_FragColor = vec4(t,f,s,1)/2.0;")
WriteLine(fw,"	//gl_FragColor = vec4(f,t,s,1)/2.0;")
WriteLine(fw,"}")
CloseFile(fw)

fw=OpenToWrite("kalieffect2.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"varying mediump vec2 uvVarying;")
WriteLine(fw,"void main( void ) {")
WriteLine(fw,"	vec2 p = abs((gl_FragCoord.xy*2.0-resolution.xy)/resolution.x);")
WriteLine(fw,"	p.x+=sin(time*0.317)*.23;")
WriteLine(fw,"	p.y+=cos(time*0.081)*.07;")
WriteLine(fw,"	float t1 = time*0.2;")
WriteLine(fw,"	mat2 rot = mat2(cos(t1),sin(t1),-sin(t1),cos(t1));")
WriteLine(fw,"	p *= 6.3;")
WriteLine(fw,"	float r = length(p);")
WriteLine(fw,"	p*=rot;")
WriteLine(fw,"	p*=0.6*cos(p.yx*1.5)*sin(p*1.3)-r*0.;")
WriteLine(fw,"  //float a =atan(p.y,p.x)*11.;")
WriteLine(fw,"	//r = a+length(p)*sin(time)*0.3;")
WriteLine(fw,"	//r = length(p)*sin(time)*0.3;")
WriteLine(fw,"	float s = sin(r*2.3+p.x*2.3-time*0.5)+sin(p.y*2.9+2.7*sin(r*0.+time*1.5));")
WriteLine(fw,"	float t = sin(r*0.+p.x*2.7+time*3.2)+sin(p.y*1.1-s+2.3*sin(r*3.3+time*0.9));")
WriteLine(fw,"	float f = (s+t);")
WriteLine(fw,"	gl_FragColor = vec4(f,f-t,t-f,1)/2.0*texture2D(texture0,uvVarying).rgba;")
WriteLine(fw,"	//gl_FragColor = vec4(t,f,s,1)/2.0*texture2D(texture0,uvVarying).rgba;")
WriteLine(fw,"	//gl_FragColor = vec4(f,t,s,1)/2.0*texture2D(texture0,uvVarying).rgba;")
WriteLine(fw,"}")
CloseFile(fw)



endfunction


function createRandomBgImage()
    SetClearColor(0,0,0)
    ClearScreen()
    Render()
    For num = 1 to 1000
		DrawEllipse(Random(1,1023),Random(1,787),random(10,30),random(10,30),makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),1)
    next num
    swap()
    img = getimage(0,0,1024,768)
    //SetImageTransparentColor(img,0,0,0)
endfunction img



A globe that has towers that shoot at the plane you fly in orbit around a planet (I use the media available in the AppGameKit 3D media pack
+ Code Snippet
// Project: Towerdefense 
// Created: 2018-08-22

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Tower defence" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#constant KEY_LEFT    = 37  //the left arrow key scancode
#constant KEY_UP      = 38  //the up arrow key scancode
#constant KEY_RIGHT   = 39  //the right arrow key scancode
#constant KEY_DOWN    = 40  //the down arrow key scancode
#constant KEY_SPACE	  = 32  //the space bar
#constant bulletLife   = 1.5
#constant Depth#=10

type _boxes
	id
	x#
	y#
	z#
	fired
endtype

// the type used for bullets  
type bullet
    ID as integer
    time as float // a time used because bullets die over time
    towerNum as integer
endtype

global boxes as _boxes[]
global empty as _boxes
global myBullet as bullet[0]
global bulletCount=0 

box=CreateObjectBox(.1,.1,.8)
SetObjectVisible(box,0)
r#=8
create3DPhysicsWorld()
boxnumber=0
	for i#=-180 to 180 step 40 // change these for effect
		for j#=-90 to 90 step 40 // change these for effect
			x# = r# * sin(i#) * cos(j#)
			y# = r# * sin(i#) * sin(j#)
			z# = r# * cos(i#)
			if objectraycast(0,x#-.1,y#-.1,z#-.4,x#+.1,y#+.1,z#+.4) =0
				empty.id = InstanceObject(box)
				empty.x#=x#
				empty.y#=y#
				empty.z#=z#
				empty.fired=0
				boxes.insert(empty)
				SetObjectVisible(boxes[boxnumber].id,1)
				SetObjectPosition(boxes[boxnumber].id,boxes[boxnumber].x#,boxes[boxnumber].y#,boxes[boxnumber].z#)
				SetObjectLookAt( boxes[boxnumber].id, 0, 0, 0, 0 ) 
				SetObjectColor(boxes[boxnumber].id,random(0,255),random(0,255),random(0,255),255)
				FixObjectToObject(boxes[boxnumber].id,box)
				inc boxnumber
			endif
		next
	next

shipBlock=LoadObject("greenrocket.x")
shipTexture=LoadImage("greenrocket_D.png")
SetObjectImage(shipBlock,shipTexture,0)
SetObjectScale(shipblock,.1,.1,.1)
SetObjectRotation(shipblock,-45,0,0)

SetObjectCollisionMode(shipBlock,1)
//Create3DPhysicsKinematicBody(shipBlock)
world=loadObject("sphere.obj")
SetObjectScale(world,1.60,1.60,1.60)
//SetObjectVisible(world,0)
SetObjectCollisionMode(world,1)
FixObjectToObject(world,box)
texture=LoadImage("world.png")

global missileObject,missileImage
missileObject=LoadObject("missile.x")
missileImage=loadImage("missile_D.png")
SetObjectImage(missileObject,missileImage,0) 
SetObjectScalePermanent(missileObject,.04,.04,.04) 
SetObjectImage(world,texture,0)

explosionImage = LoadImage ("explosion.png")
explosionSpr=CreateSprite(explosionImage)
SetSpriteImage(explosionSpr,explosionImage)
SetSpriteAnimation(explosionSpr,256,256,25)
SetSpriteSize(explosionSpr,256,256)
SetSpritePositionByOffset(explosionSpr,512,275)
SetSpriteVisible(explosionSpr,0)			

smokeImage = LoadImage ("smoke.png")

lives=5:bulletcount=0:state=0


Set3DPhysicsGravity( 0, 0, 0 ) 
//SetObjectColor(world,0,255,0,255)
SetObjectPosition(shipBlock,0,5,-10)
do 
	
	if GetRawKeyState(KEY_UP)
		moveWorld(box,-2,0,0)
	endif
	if GetRawKeyState(KEY_DOWN)
		moveWorld(box,2,0,0)
	endif
	if GetRawKeyState(KEY_LEFT)
		moveWorld(box,0,0,-1)
	endif
	if GetRawKeyState(KEY_RIGHT)
		moveWorld(box,0,0,1)
	endif
	if GetrawkeyPressed(KEY_SPACE)
	endif
	
	for num =0 to boxnumber-1
		//shoot at plane if in range
		towerNum=num
		if boxes[towerNum].fired=0 and getDistance(boxes[towerNum].id,shipBlock)<6 
			boxes[towerNum].fired=1
			shootBullet( boxes[towerNum].id,shipBlock,towerNum, 20.0, 10.0)
		endif
	next num
	
	bulletNum=bulletCount
	for num=bulletNum to 1 step -1
		if state=0 and objectraycast(shipBlock,getObjectX(myBullet[num].ID)-0.15,getObjectY(myBullet[num].ID)-0.15,getObjectZ(myBullet[num].ID)-.15,getObjectX(myBullet[num].ID)+.15,getObjectY(shipBlock)+.15,getObjectZ(shipBlock)) 
			dec lives:state=1
		endif
		//remove old bullets
		if (myBullet[num].time)+bulletLife<timer() 
			DeleteObject(myBullet[num].ID)
			towerNum=myBullet[num].towerNum
			boxes[towerNum].fired=0
			myBullet.remove(num)
			dec bulletCount	
		endif
	next num
	
	if state=1
		partID=Create3DParticles( getObjectX(shipBlock),getObjectY(shipBlock),getObjectZ(shipBlock) ) 
		Set3DParticlesDirection( partID, 0,2, 0, 0 ) 
		Set3DParticlesDirectionRange( partID,275,45  ) 
		Set3DParticlesFrequency( partID, 100 )
		Set3DParticlesImage(partID,smokeImage)
		Set3DParticlesSize(partID,1)
		Set3DParticlesLife(partID,.25)
		Set3DParticlesVelocityRange(partID,1,10)
		Set3DParticlesMax(partID,150)
		state=2
	endif	
	
	if state=2 
		if getObjectZ(shipBlock)<-5
			SetObjectPosition(shipBlock,getObjectX(shipBlock),getObjectY(shipBlock),getObjectZ(shipBlock)+.1)
		else
			Delete3DParticles(partID) 
			SetSpriteVisible(explosionSpr,1)
			playSprite(explosionSpr,10,0)
			state=3
		endif
	endif
	
	if state=3 and GetSpritePlaying(explosionSpr)=0
		SetSpriteVisible(explosionSpr,0)
		SetObjectPosition(shipBlock,0,5,-10)
		state=0
	endif
	
	
    Print("Move using arrow keys they will aim at you")
    Print("and will shoot if your close")
    Print (lives)
    Step3DPhysicsWorld()
    print(state) 
    Print( ScreenFPS() )
    Sync()
loop

function moveWorld(objID as integer,ax#,ay#,az#)
	RotateObjectGlobalX(objID,ax#)
	RotateObjectGlobalY(objID,ay#)
	RotateObjectGlobalZ(objID,az#)	
endfunction


function shootBullet(objectId as integer,objectID2 as integer,towerNum as integer,initialSpeed as float, mass as float)
	//To move dynamic physics bodies we need to apply velocity to the physics body.
	gunPositionVec= CreateVector3(GetObjectWorldX(objectId),GetObjectWorldY(objectId),GetObjectWorldZ(objectId)) //im using the camera position as the gun position 
    //Create a tempory projectile block to calculate movement vectors of bullets
    projectileDirBox as integer
    projectileDirBox = CreateObjectBox( 1.0, 1.0, 1.0 )
    SetObjectPosition( projectileDirBox, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
     
    //setobjectrotation(projectiledirbox,GetObjectWorldAngleX(objectId),GetObjectWorldAngleY(objectId),GetObjectWorldAngleZ(objectId))
    SetObjectLookAt( projectileDirBox, GetObjectWorldX(objectID2),GetObjectWorldY(objectID2),GetObjectWorldZ(objectID2), 0 ) 
        
    MoveObjectLocalZ( projectileDirBox, -1.0 )
    projectileDirVec = CreateVector3( GetobjectWorldX( projectileDirBox )-GetVector3X( gunPositionVec ), GetobjectWorldY( projectileDirBox )-GetVector3Y( gunPositionVec ), GetobjectWorldZ( projectileDirBox )-GetVector3Z( gunPositionVec ) )
    //DeleteObject( projectileDirBox )
    bullet as integer    
    //bullet = CreateObjectSphere(.45,.45,.45 )
    bullet=InstanceObject(missileObject) 
    SetObjectImage(bullet,missileImage,0) 

    //SetObjectColor( bullet, 255, 0,0,255 )
    SetObjectPosition( bullet, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
    SetObjectRotation(bullet,GetObjectAngleX(projectileDirBox),GetObjectAngleY(projectileDirBox),GetObjectAngleZ(projectileDirBox))
    DeleteObject( projectileDirBox )
    //3D Physics code
    Create3DPhysicsDynamicBody( bullet )
    //SetObjectShapeSphere( bullet )
    SetObject3DPhysicsMass( bullet, mass )
    SetObject3DPhysicsLinearVelocity( bullet, projectileDirVec, initialSpeed )
    
    myItem as bullet
    myItem.ID = bullet //the object id of the bullet
	myItem.time = timer()  //timer is used to set there life time as bullets will die off after so long
	myItem.towerNum=towerNum
	myBullet.insert(myItem) //update bullet arrow as there is unlimeted bullets 
	inc bulletCount //used for a bullet counter to check if theyve timed out or not 
    deletevector3(projectileDirVec)
    deletevector3(gunPositionVec)
endfunction

function getDistance(objectID as integer,objectID2 as integer)
	distance as float
	vec1=CreateVector3(GetObjectWorldX(objectID),GetObjectWorldY(objectID),GetObjectWorldZ(objectID))
	vec2=CreateVector3(GetObjectWorldX(objectID2),GetObjectWorldY(objectID2),GetObjectWorldZ(objectID2))
	distance=GetVector3Distance(vec1,vec2 ) 
	DeleteVector3(vec1)
	DeleteVector3(vec2)
endfunction distance

Here is its thread where there is a video showing it working https://forum.thegamecreators.com/thread/222833