Thursday, March 11, 2010

TIBasic: an alternative to the "solve(" command

The "solve(" command is a pretty efficient way to find the root of an unknown equation. Unfortunately, it only works if you have a good guess; otherwise, you'll be plagued by "Bad guess" errors which may cause your program to crash.

To guarantee that your user doesn't encounter such an error, create a routine that uses Newton's method to perform the same function as the "solve(" command, except with safeguards for bad guesses.

Here's a routine that, given an equation (in terms of X) stored to Y1, and a guess stored to "G", will solve for "X" when the equation in Y1 = 0. Essentially, it does the same thing as "solve(Y1,X,G"

:DelVar R
:G
:Repeat Ans=X and R
:Ans→X
:R+1→R
:nDeriv(Y1,X,X
:If Ans
:X-Y1/Ans
:If R>50
:X
:End
:Ans→X
:If not(Y1
:X


download

Monday, March 8, 2010

Bump Update #1

Bump (xLib) 1Bump (xLib) 2

I started to rewrite an older game of mine called Bump using xLib. This code so far has little more than basic collision detection...

Basically the premise of the game is that you're the little ball, and you need to get to the hole. Whenever you press an arrow key, you keep rolling until you hit something else. In addition, you have an enemy that rolls in the same direction as you, which complicates things...


download

3D Rendering: ShowCase

So today I started tinkering with creating 3D wireframes using xLib, and got some pretty impressive results. Basically, I used the real(9, etc) function to create 10~24 frames of the model, and then one final routine that flips through the images according to the user's keypress, giving a pretty convincing feeling of a rotating 3d model. Plus, I drew all of the frames in such a way that while the images are loading, the user doesn't really see anything other than a loading screen...


download



Link