Hello,
I have updated
Jammy Mandelbrot program, now you can move around a little more easier. Here is the code:
// Project: Another Pixel Shader turorial
// Created: 2015-01-05 by JammySoft
// Using a very slightly modified version of the GLSL Shader available at
// http://rosettacode.org/wiki/Mandelbrot_set#GLSL
#constant KEY_ESCAPE 27
#constant KEY_SPACE 32
#constant KEY_C 67
// get the time
StartTime#=Timer()
// screen resolution
resx = 1920
resy = 1200
screencenter = (resx/15)*(resx/15) + (resy/15)*(resy/15)
// set window properties
SetWindowTitle( "Mandelbrot_set" )
SetWindowSize( resx, resy, 1 )
SetVirtualResolution( resx, resy )
SetSyncRate(60,0) ` this is unlimited frames per second
SetPrintSize(18)
zoom#=5.5
SetRawMousePosition( resx/2,resy/2 )
newmousex=resx/2
newmousey=resy/2
x#=0
y#=0
green#=0
incrament#=0.001
` load a shader
` as we are using a sprite to display the shader we can work with pixel shaders and ignore vertex shaders at the moment.
Shader = LoadSpriteShader( "Mandelbrot.ps" )
` create a full screen sprite to apply the shader
CreateImageColor( 1, 255,0, 0,255 ) `this just creates an image of 1 pixel and colours it.
Sprite=CreateSprite(1) `make a sprite and call it sprite
SetSpritePosition(Sprite,0,0)
`assign the shader to the sprite.
SetSpriteShader( Sprite, Shader )
SetSpriteSize(Sprite,resx,resy) ` make the sprite full screen
SetShaderConstantByName( Shader,"iResolution",resx,resy,0,0 ) ` tell the shader the screen resolution
SetShaderConstantByName( Shader,"zoom",zoom#,0,0,0 )
SetShaderConstantByName( Shader,"xmove",x#,0,0,0 )
SetShaderConstantByName( Shader,"ymove",y#,0,0,0 )
SetShaderConstantByName( Shader,"green",0,0,0,0 )
do
if green#>1.0 or green#<0.0 then incrament# = - incrament#
green#=green#+incrament#
SetShaderConstantByName( Shader,"green",green#,0,0,0 )
if GetRawMouseLeftState()=1
zoom# = zoom# * 0.99
SetShaderConstantByName( Shader,"zoom",zoom#,0,0,0 )
Endif
if GetRawMouseRightState()=1 and zoom#<30
zoom# = zoom# * 1.02
SetShaderConstantByName( Shader,"zoom",zoom#,0,0,0 )
Endif
if GetRawKeyReleased(KEY_C)=1
SetRawMousePosition( resx/2,resy/2 )
else
tx# = GetRawMouseX() - resx/2
ty# = GetRawMouseY() - resy/2
if tx# * tx# + ty# * ty# > screencenter
rem mouse is outside center of screen, let's move
movementx# = tx# * zoom# / resx / 100
x# = x# - movementx#
SetShaderConstantByName( Shader,"xmove",x#,0,0,0 )
movementy# = ty# * zoom# / resy / 100
y# = y# - movementy#
SetShaderConstantByName( Shader,"ymove",y#,0,0,0 )
endif
endif
if toggle=0
Print("Use mouse to move about")
Print("mouse buttons to zoom in and out")
Print("space-bar to Toggle Info")
print("c to center mouse")
Print("ESC TO EXIT")
endif
if GetRawKeyReleased(KEY_SPACE) = 1
SetRawMouseVisible(toggle)
toggle = 1 - toggle
endif
sync()
if GetRawLastKey() = KEY_ESCAPE then exit
loop