release: RAD Module

BlitzMax Forums/BlitzMax Programming/release: RAD Module

jondecker76(Posted 2010) [#1]
Here is a small module that I made which I use in pretty much everything I do. I used 3DRAD many many many years ago, and remember some of my favorite old functions. Here is my implementation of the following functions that I used to use in 3DRAD

interpolate
oscillate
limit
between
wrap
rebound

A few of these also have Float versions implemented.

Download it here:
http://code.google.com/p/jmd-blitzmax-modules/downloads/list

To install, just unzip into your mod folder, and build modules

Here are a couple of samples from the documentation:

Bouncing ball example using Rebound()
Import jmd.rad

Global velY:Float = 0
Global gravityForce:Float = -0.5
Global posY:Float = 0
Global posX:Float
Global velX:Float
Global ballDiameter:Int = 50

Graphics 640,480
SeedRnd MilliSecs()
init()
While Not KeyDown(KEY_ESCAPE)
	
	
	If velY<>0
	'calculate gravity forces
	velY:- gravityForce
	EndIf
	'air friction
	velX:* 0.99 'hack-ish friction
	
	'add acceleration to postion
	posY:+ velY
	posX:+ velX

	'Rebound!
	If posY>GraphicsHeight()-ballDiameter
		posY=GraphicsHeight()-ballDiameter
		velY=Rebound(velY,0.75,0.1)
	EndIf
	If PosX<0
		posX=0
		velX=Rebound(velX,0.75,0.1)
	EndIf
	If posX>GraphicsWidth()-ballDiameter
		posX=GraphicsWidth()-ballDiameter
		velX=Rebound(velX,0.75,0.1)
	EndIf
	
	'Reset?
	If KeyHit(KEY_R)
		Init()
	EndIf
	
	'Draw it
	Cls
	DrawText "Press R to reset",10,10
	DrawOval posX,posY,ballDiameter,ballDiameter
	Flip

Wend

Function init()
	PosX=GraphicsWidth()/2
	velX=Rnd(-15,15)
	posY=0
	velY=0.001
End Function


Snake-like waving balls using Oscillate()
Import jmd.rad

Graphics 640,480

While Not KeyDown(KEY_ESCAPE)
	Cls
	Local numSpheres:Int=30
	For Local i:Int = 0 To numSpheres
	SetColor(i*8,128-i*7,255-i*7)
	DrawOval Oscillate(0,600,4000,i*(360/numSpheres)),i*20,20,20
	DrawOval Oscillate(600,0,4000,i*(360/numSpheres)),i*20,20,20
	SetColor(255-i*7,i*8,128-i*7)
	DrawOval Oscillate(100,500,2000,i*(360/numSpheres)),i*20,20,20
	DrawOval Oscillate(500,100,2000,i*(360/numSpheres)),i*20,20,20
	SetColor(128-i*7,255-i*7,i*8)
	DrawOval Oscillate(200,400,4000,i*(360/numSpheres)),i*20,20,20
	DrawOval Oscillate(400,200,4000,i*(360/numSpheres)),i*20,20,20
	
	Next
	Flip

Wend



Brucey(Posted 2010) [#2]
It's also possible to create a set of modules and host them in the same place - like this.
Which may be more easy to manage?


jondecker76(Posted 2010) [#3]
thanks for the advice, I'll definitely look into doing something similar!


Kryzon(Posted 2010) [#4]
Looks nice :)
Although, you could short the Between function to this:
Function between:Int(value:Int,vMin:Int,vMax:Int)
	If value < vMin Return False
	If value > vMax Return False
	Return True
End Function
There's no need for those Else's because Return breaks the function at that point. If the condition is not true, it just goes forth.

After a bit of testing, the wrap function seems to be wrong.


jondecker76(Posted 2010) [#5]
I'll take a peek at the wrap function, but I don't have 3DRAD (or windows for that matter) anymore, so I couldn't compare the output


jondecker76(Posted 2010) [#6]
Ok, I fixed the Wrap() functions and they work as they should now. There is a new version 1.3 for download at http://code.google.com/p/jmd-blitzmax-modules/downloads/list#

I also added a wrap example in the documentation that makes it easy to verify it works:

SuperStrict
Import jmd.rad

Local value:Int=1

Graphics 640,480
While Not KeyDown(KEY_ESCAPE)
	If KeyHit(KEY_UP)
		value=value+1
	EndIf
	If KeyHit(KEY_DOWN)
		value=value-1
	EndIf

	Cls
	DrawText "Use the Up and Down arrows to change value",10,10
	DrawText "Value: " + value,10,50
	DrawText "wrapped between 9 and 14: " + wrap(value,9,14),10,70
	Flip
Wend
End


I also expanded on the Oscillate() and Rebound() function examples