• TI-BASIC: Storing lists/data in pixels (My Program)
    1 replies, posted
I was bored in study hall today. What happens when dag10 is bored in study hall? He creates a series of TI-BASIC programs on his TI-84 of course! Today I came up with something awesome: A way to store any floating-point number as pixels in a drawing. You can use this to create a "hard-drive" for storing large amounts of data out of the way. It also looks pretty. The first program is called WRITE. It's very simple, and is the raw data writer. Usage: *Store the location of the image you want to write to in B. *Store the length of the data (in bits) that you want to write in A. *Store the actual data that you want to write in X. [QUOTE=WRITE] "A: DATASIZE "X: DATA "B: INDEX 0->Y While Aù0 While Bù95 B-95->B Y+1->Y End If Xù(2^A) Then Pxl-On(Y,B X-(2^A)->X Else Pxl-Off(Y,B End A-1->A B+1->B End While Y B+95->B Y-1->Y End [/QUOTE] Now this next program is the final, nice program that takes ANY single number on the TI-84 and encodes all the data that the calculator stores about the number into the drawing as pixels (binary data). This program uses the WRITE program to keep it cleaner. Usage: *Store the location (offset) in the drawing you want to write the 43-bit number to in B *Store the number in A. (The number can be negative or positive, and it can be between 10^(-10) and 10^10 (The calculator only allows numbers between there anyway lol) and it can store 10 specific non-zero digits (As can only the calculator as well, so basically an number that the calculator can store can be written in full). [quote=WFLOAT] 0->D While Xøint(X D-1->D 10X->X End While X>9999999999 D+1->D X/10->X End X->N If N<0:Then 1->X Else 0->X End 1->A prgmWRITE N->X 34->A prgmWRITE If D<0:Then 1->X Else 0->X End 1->A prgmWRITE 7->A D->X prgmWRITE [/quote] Now, this next program is READ. It is the counterpart of WRITE: It simply reads the raw data of length (in bits) A, from offset B, and stores it in X. [quote=READ] "A: DATASIZE "X: DATA "B: INDEX 0->X:0->Y While Aù0 While Bù95 B-95->B Y+1->Y End If pxl-Test(Y,B):Then X+(2^A)->X End A-1->A B+1->B End While Y Y-1->Y B+95->B End [/quote] Finally, this next program is RFLOAT, the counterpart of WFLOAT: It simply reads the 43-bit floating-point number written by WFLOAT at location B, and stores it in X. Like with WFLOAT, you don't have to bother with length (A). [quote=RFLOAT] 1->A prgmREAD X->D 34->A prgmREAD X->N If D:Then N*ú1->N End 1->A prgmREAD X->S 7->A prgmREAD X->D If S:Then D*ú1->D End N(10^D)->X [/quote] So now here's an example usage: Say you want to encode a really small, negative number (-0.001125100000000). Just save that in X. Now set B to 0 to write it at the beginning of the drawing, and run the program WFLOAT. Now, let's save another really large number after that in the drawing (8259172510000000000000000000000000000). Save that to X and call WFLOAT again. You don't have to set B, since the previous WFLOAT left the next offset in B for us, to make writing and reading consecutive data easier (as I'll show you in a moment). You'll notice that there are a bunch of little dots in your graph. That's the data. [quote=WRITING_TWO_NUMBERS_USAGE] -0.001125100000000->X 0->B prgmWFLOAT 8259172510000000000000000000000000000->X prgmWFLOAT [/quote] Now that you wrote the two numbers, let's read them back! :D Just store 0 in B to start reading from the start. Run RFLOAT, and the first number will be in X. Call it again and the second number will be in X. [quote=READING_FIRST_NUMBER_BACK] 0->B prgmRFLOAT X [/quote] [quote=READING_SECOND_NUMBER_BACK] prgrmRFLOAT X [/quote] Pretty nice, eh? Now for the fun part: Let's save and load lists to/from our drawings! :D Here's a really small program to write L1 to the drawing, starting from the offset that's set in B before the program is run. This program is WLIST. Usage: *Offset to store list is in B *List read from is L1 by default (change it if you want in the code) [quote=WLIST] 16->A dim(L)->X prgmWRITE For(I,1,dim(L L(I)->X prgmWFLOAT End [/quote] Now, the list can be of variable length, and each number will be fully preserved in the data. If you had a large list with lots of specific numbers, you'll see a big jumble of pixels in the graph. Now let's make a program to read the list back. This is called RLIST. Usage: *Offset to read list from is in B *Saves list to L1 [quote=RLIST] 16->A prgmREAD X->J For(I,1,J prgmRFLOAT X->L(I End [/quote] Now, just to prove it all works, clear out L1. Now save 0 to B and run RLIST to reload your list from the pixels in the drawing, in full detail. The original L1 should now be re-populated just like how it was. Neat-o! :D You can save/edit these programs with a porgram called TI-CODER (google it), and use TI-CONNECT with a usb link cable to transfer them to/from your calculator (TI-84/TI-84). [b]Important: [/b]If you copy/paste these to TI-CODER, before you save use a program (notepad) with CONTROL-H (find&replace) to replace the characters "->" with "ü". This is because the "ü" character is actually the (->) character in TI-CODER. Also, the "ù" character which I left in is the TI "negative charactar", not the minus charactor. Keep that in mind if copying these by hand or into another program. If you copy this into TI-CODER they'll work fine. Well that's my pointless TI-BASIC program(s). What do you think? lol
Oh, the good old days. I learned the basics of programming on a TI-83. I even made a simple Tron Light-Cycle game on there.
Sorry, you need to Log In to post a reply to this thread.