Omnimaga > BatLib

BatLib/ReCode Examples

(1/7) > >>

Munchor:
Most of what I know about programming, I learnt it by looking at sample codes and examples, so I thought that I could make some BatLib samples and explain them.

Here's my first code sample, draw a rectangle around the screen and wait for pressing [CLEAR] to close.


--- Code: ---dim(1,40                 ; Disables Indicator (dim(1)) and Turns Basic ReCode on ((dim(40)). In BatLib, we can have multiple commands in a single dim(
Fill(0                   ; AxesOff, ClrDraw, basically, it cleans the screen in a Recode Block
While getKey≠15          ; waits till a [CLEAR] press
Line(0,96,0,64,6         ; Draws a rectangle, X=0, WIDTH=96,Y=0;HEIGHT=64;TYPE=6. Type 6 is borders only
DispGraph                ; Displays the graphscreen
End                      ; End of loop
Stop                     ; Disables ReCode and goes back to BASIC
AxesOn                   ; Turns Axes on
--- End code ---

First of all, I need to clear that you should read the readme and recode readme first.

Then, this code is very simple and here's how it looks when ran:



Hope you enjoyed this example, more to come.

Attached is the 8xp file.

EDIT: fixed up spacing and added ≠ with Scout's approval

Munchor:
Here it comes, the second sample. It's going to do exactly what we did in the first sample, but in a much faster and smaller way!


--- Code: ---dim(1,40                 ; Disables Indicator (dim(1)) and Turns Basic ReCode on ((dim(40)). In BatLib, we can have multiple commands in a single dim(
Fill(0                   ; AxesOff, ClrDraw, basically, it cleans the screen in a Recode Block
While getKey≠15          ; waits till a [CLEAR] press
Line(0,96,0,64,6         ; Draws a rectangle, X=0, WIDTH=96,Y=0;HEIGHT=64;TYPE=6. Type 6 is borders only
DispGraph                ; Displays the graphscreen
End                      ; End of loop
Stop                     ; Disables ReCode and goes back to BASIC
AxesOn                   ; Turns Axes on
--- End code ---

This was last sample, here's the new sample, it doesn't use ReCode, only TI-Basic and BatLib:


--- Code: ---While getKey!=45  ; "!=" is the difference symbol
dim(1,29,0,96,0,64,6,99
End
ClrDraw:ClrHome

--- End code ---

Let's take a look at the meat of the program: dim(1,29,0,96,0,64,6,99, which can be broken to:


--- Code: ---dim(1 ;Disables Indicator
dim(29,0,96,0,64,6 ;Creates a rectangle of type (6) borders only at (0,0)
dim(99 ;DispGraph

--- End code ---

Hope you liked it ;)

Xeda112358:
Yes, that is exactly the technique that I love about BatLib, personally. So here is another common example I use...
First, you want to draw a sprite or a rectangle using the XOR (or invert) option and you display the graph. Then, you can use dim(10,x to filter key presses (like waiting for arrows and the column of keys containing enter to be pressed) If there are two or more groups of keys, you can use dim(43 as another getkey. After that, you can use the first thing you did again without updating the screen.

TL;DR
Pretty much, this will display a rectangle, wait for a key press, and restore the screen:

--- Code: ---dim(29,B,8,C,8,2
dim(99               ;Displays the inverted rectangle
dim(10,3             ;waits until Arrows or the column with enter to be pressed
dim(43→A             ;returns the key in Ans and is stored to A
dim(29,B,8,C,8,2     ;This reinverts the rectangle, but it isn't shown yet. Great for smooth graphics.

--- End code ---
However, this can be all put together into one long sequence of commands by combining the inputs:
dim(29,B,8,C,8,2,99,10,3,43,29,B,8,C,8,2→A

ztrumpet:
I still don't understand how the chaining works; my brain doesn't comprehend the awesome. ;D
What if you leave arguments out of a command?  How does it know to go on to the next command?

Xeda112358:
That is the downside to chaining commands... you cannot leave out arguments unless they are at the end. However, if you want to you can leave out arguments before a string argument, even if you are chaining.

Navigation

[0] Message Index

[#] Next page

Go to full version