blitzmax demo

Miscellaneous Forums/Blitz Showcase/blitzmax demo

Blitzmax is awesome... this demo shows how fast it is at drawing pixels and the cool effects of changing colors without cls

collision=1
frequenzacol=4
frequenza=50
lines=1


vecchiotempo=0
cycles=0
r=20

raggiofalso=r*3

numballs=70

iteraz=10

g#=0.0'3


Global angle#[numballs+1]
Global rv# [numballs+1]
Global x# [numballs+1]
Global y# [numballs+1]
Global z# [numballs+1]
Global xv#[numballs+1]
Global yv#[numballs+1]
Global oldx# [numballs+1]
Global oldy#[numballs+1]
Global yspeed#[numballs+1]
Global xspeed#[numballs+1]
Global unicol[3+1]
Global col[numballs+1,3+1]
Global adder[3+1]


Global forzax1#[numballs+1]
Global forzay1#[numballs+1]
Global forzax0#[numballs+1]
Global forzay0#[numballs+1]

Global dist#[numballs+1]

Global m#[numballs+1]



For i=1 To 3
adder(i)=1
Next

For i=1To numballs

x(i)=i


For j=1 To 3
col(i,j)=Rnd(255)

Next
Next

grabbed=0
grabx#=0
graby#=0

x(1)=400
y(1)=300



xwin=640'1024
ywin=480'768


xwin=1024
ywin=768

Graphics xwin, ywin,0,160





Repeat

'Cls

For i=1 To numballs
oldx(i)=x(i)
oldy(i)=y(i)
Next 




If  MouseDown(1)<>1

grabbed=0
End If

If (grabbed=0) & (MouseDown(1)=1)

For i=1 To numballs

If ((MouseX()>x(i)) & (MouseX()<x(i)+2*raggiofalso)  & (MouseY()>y(i)) & (MouseY()<y(i)+2*raggiofalso)) Then
grabbed=i

grabx=MouseX()-x(i)
graby=MouseY()-y(i)


End If

Next

End If

grabbed=1


For i=1To numballs

m(i)=1
Next

'm(numballs)=10

'm(1)=10



If (grabbed>0)

m(grabbed)=1000000000


x(grabbed)=MouseX()-grabx
y(grabbed)=-graby+MouseY()
xv(grabbed)=0
yv(grabbed)=0
End If





'applica le forze alla velocita' vecchia



For i=1 To numballs


yv(i)=yv(i)+g

x(i)=x(i)+xv(i)
y(i)=y(i)+yv(i)





Next



For l=1 To iteraz'!!!!!

For i=2 To numballs



dist(i)=Sqr((x(i)-x(i-1))*(x(i)-x(i-1))+(y(i)-y(i-1))*(y(i)-y(i-1)))-2*r

If (1=2)
angle(i)=ATan2(-y(i)+y(i-1),x(i)-x(i-1))
forzax1(i-1)=dist(i)/(1+m(i-1)/m(i))*Cos(angle(i))
forzay1(i-1)=-dist(i)/(1+m(i-1)/m(i))*Sin(angle(i))


forzax0(i)=-dist(i)/(1+m(i)/m(i-1))*Cos(angle(i))
forzay0(i)=dist(i)/(1+m(i)/m(i-1))*Sin(angle(i))
End If

If (1=1)
If ( dist(i)+2*r )<>0

forzax1(i-1)=dist(i)/(1+m(i-1)/m(i))* ( (x(i)-x(i-1) )/ ( dist(i)+2*r ) )

forzay1(i-1)=dist(i)/(1+m(i-1)/m(i))*( (y(i)-y(i-1) )/ ( dist(i)+2*r ) )


forzax0(i)=-dist(i)/(1+m(i)/m(i-1))*( (x(i)-x(i-1) )/ ( dist(i)+2*r ) )
forzay0(i)=-dist(i)/(1+m(i)/m(i-1))*( (y(i)-y(i-1) )/ ( dist(i)+2*r ) )
End If
End If

Next


For i=1 To numballs

x(i)=x(i)+forzax0(i)+forzax1(i)
y(i)=y(i)+forzay0(i)+forzay1(i)

Next

Next



For i=1 To numballs




xv(i)=x(i)-oldx(i)
yv(i)=y(i)-oldy(i)

If collision
If (x(i)>xwin -2*r)
x(i)=xwin-2*r
xv(i)=-xv(i)
End If
If (x(i)<0) 
x(i)=0
xv(i)=-xv(i)
End If
If (y(i)>ywin-2*r) 
y(i)=ywin-2*r
yv(i)=-yv(i)
xv(i)=0.96*xv(i)
End If
If (y(i)<0) 
y(i)=0
yv(i)=-yv(i)
End If
End if

Next


If cycles=Floor(cycles/frequenzacol)*frequenzacol



For i=1 To 3
If (Rnd(0,1000)>990)
adder(i)=-adder(i)
End If
If (unicol(i)>254) Then adder(i)=-1
If (unicol(i)<1) Then adder(i)=1
unicol(i)=unicol(i)+adder(i)


Next

End if


If (lines=0)
For i=1 To numballs

SetColor unicol(1),unicol(2),unicol(3)

'Color col(i,1),col(i,2),col(i,3)

DrawOval x(i),y(i),2*raggiofalso,2*raggiofalso
Next

End If

If (lines=1)
For i=1 To numballs-1

SetColor unicol(1),unicol(2),unicol(3)

'Color col(i,1),col(i,2),col(i,3)

DrawLine x(i),y(i),x(i+1),y(i+1)
Next
End If

	DrawText fps+"   "+grabbed+"   "+MouseDown(1), 20, 40


FlushMem

If cycles=Floor(cycles/frequenza)*frequenza

	Flip
	End If
	
cycles=cycles+1
If (MilliSecs()-vecchiotempo>1000)
vecchiotempo=MilliSecs()
fps=cycles
cycles=0
End If
	
		
Until KeyDown (KEY_ESCAPE)
	
End


nice :)

I get ~6600fps btw.

Cool. Make this in to a screensaver if you can.

:)

Very cool effect!

thx everyone!

actually it executes the code 50 times every frame, so it can draw without gaps (but if you move the mouse really fast you can see the gaps! i.e. it draws lines, not surfaces)

I dont know how to make it a screensaver :-( (although almost everything I do are screensavers :-P)

Darn...I wish I had BlitzMAX. Or even the Windows beta. Is there a Windows beta yet?

yes there is the windows beta you can get it if you buy the mac version. It works pretty well although there might be some minor problems

I dont know how to make it a screensaver :-(

Stick this at the top for a windows screensaver, then just rename the .exe to .scr:
If Len(appargs)>1 Then
	?Win32
		Select appargs[1]
			Case "/p" 'preview mode, next argument should be the window handle
				End
			Case "/c" 'do config mode
				End
			Case "/s" 'screensaver mode
				
			Default
		End Select
	?
EndIf

The preview mode gives the handle of the small preview window in the screensaver properties dialogue

*EDIT*
obviously, making it full screen would be a good idea also.

Thx

I cant make it fullscr because of the bug that flickers fullscreen when you dont call Cls.

And I didnt manage to change the extension!!! .exe is not displayed on the screen, and I dont seem to have access to it.... (Im a new windows user, I had a Mac before)

in the folder where the executable is, click tools->folder options->View and untick 'hide extensions for know file types'

GREAT!!!!

It works!!!!!

finally I can say goodbye to the sucky windowz screensavers...

But I didnt really get what the code does nor how to display something in the small preview window, nor how to avoid the "console" to appear... Is there some simple template?

Thx again

Not sure how to get rid of the console window (yet).
the preview thing is a little tricky and might require me to be more awake to do it.

When you do /p it will pass the handle of the little preview box to the screensaver, you then need to draw on top of it (not quite so easy).
A preview however is not really necessary.

ok, thx anyway, its enough for now

But I didnt really get what the code does

The code doesn't actually make it a screensaver, all a screensaver is, is a standard windows executable renamed.

However, windows passes commandline arguments (passed by BMax into the AppArgs[] Array) which you can then used to respond appropriately.

If you were to type at the command prompt (assuming myScreenSaver.scr was in c:\scrn\):
c:\scrn\myScreenSaver.scr /s
this would launch the executable put /s as the SECOND element in the appargs[] array (the first being the full path to the program).

Running the app in the preview is impossible under Blitz as far as I can tell but you can cheat. I have a wee VB stub that is the screensaver (i.e is called .scr), it handles the config and preview window (runs animation of Blitz program to look like its running in the preview window) and then calls the Blitz app. If you wanna take a look at it click here http://www.boiledsweets.com/vorboils/index.php

[Sorry if I'm seem to be hijacking this thread -- that is not my intention I just have been working on getting a Blitz program to run as a FULL screensaver for the last 6 months and getting close now]

There are some other issues too as a screen saver is not JUST a renamed exe you also have to handle...

Set the registry setting that tells Windows that a screensaver is running.

Disable Ctl-Alt-Delete and Alt-Tab task switching.
So users cannot switch to another application or kill the screen saver if it is password protected.

Make your screen saver always on top.
Set your main form to be always on top.

Hide the cursor.
Using the ShowCursor API so when the screen saver is displayed you do not see it.

Plus you gotta be able to handle the password on resume option.

Also to ensure that the screensaver remains in the screensaver list you have to install it to c:\windows\system32 or c:\windows. Obviously if you do install it there you really ought to...

a) have an uninstaller
b) pack data resources into the exe

And then you gotta handle configuration stuff, i.e. allow the screensaver to run in the desktop resolution. To do this you need to make Windows32 API calls within the Blitz program to determine the desktop depth etc...

Good luck.

Running the app in the preview is impossible under Blitz as far as I can tell


You do know this is a BMax program not a B3D one yes?

If you get the handle to the preview window, you can get a DC handle for it with GetDC Windows API function. Then you can draw directly into that hDC.

I don't know BlitzMax, so I have no idea if you can blit a BlitzMax surface into a hDC. If you can't, you still could use Windows GDI Api functions to draw ovals and lines on the preview window.

I have heard it can be done but never seen anyone able to do it.