User:Deathgleaner/ProgramArc

From Wikipedia, the free encyclopedia

Contents

[edit] TI-83 Plus Examples

[edit] Input

PROGRAM:INPUT
:ClrHome
:Input "TYPE A NUMBER:  ",A
:ClrHome
:Disp A
:Pause

________________
|TYPE A NUMBER: |
|1              |
|               |
|               |
|               |
|               |
|               |
|               |
-----------------
________________
|1              |
|               |
|               |
|               |
|               |
|               |
|               |
|               |
-----------------

[edit] Output(

PROGRAM:OUTPUT
:ClrHome
:Output(1,1,"TYP
E A NUMBER: "
:Input A
:ClrHome
:Disp A
:Pause

________________
|TYPE A NUMBER: |
|1              |
|               |
|               |
|               |
|               |
|               |
|               |
-----------------
________________
|1              |
|               |
|               |
|               |
|               |
|               |
|               |
|               |
-----------------


[edit] Disp

PROGRAM:DISP
:ClrHome
:Disp "HELLO, MY
 NAME","IS SAM!"
,""
:Pause

________________
|HELLO, MY NAME |
|IS SAM!        |
|               |
|               |
|               |
|               |
|               |
|               |
-----------------

[edit] Examples

These examples are slightly TI-83-series-biased. For example, "ClrHome" would be "ClLCD" on the TI-85 and TI-86.

An entirely different command is required to clear the screen in the TI-89. Since output is generally displayed on the ProgramIO screen, the "ClrIO" command is required to clear the output screen. There exists a "ClrHome" command on the TI-89, and it performs its function - namely, clearing the Home screen. For the purpose of programs, however, this command is essentially useless (yet it is invaluable in the programming of functions).

[edit] Hello world

The following program, when run, will clear the standard output and print the phrase "HELLO WORLD!":

Z80 Series

PROGRAM:HELLOWLD
:ClrHome
:Disp "HELLO, WORLD!"

68000 Series

hellowld()
:Prgm
:ClrIO
:Disp "Hello, World!"
:EndPrgm

[edit] Add integers and display sum

PROGRAM:COUNT
:ClrHome
:Input "Int.=",I
:Input "Start=",S
:ClrHome
:Output(1,1,S)
:While 1
:I+S→S
:Output(1,1,S)
:End

[edit] EnterCounter

This program will count how many times you press enter.

PROGRAM:COUNTER
:FnOff :PlotsOff
:1→A
:ClrDraw:AxesOff
:Text(6,12,"Counter v1.1")
:Text(46,94/2,"Press [ENTER]")
:Pause:ClrDraw
:ClrHome:Disp
:Output(5,6,"Times")
:While 1
:1+A→A
:Output(4,7,A)
:Pause:End

[edit] Await keypress, display keycode

This program will loop indefinitely, waiting for a key to be pressed and informing the user of its keycode. Note that the "On" key will stop execution of a TI-BASIC program, and therefore does not have a keycode. (Some assembly subroutines can be called from a TI-BASIC program to clear this interrupt.)

PROGRAM:KEYCODE
:Repeat Ans
:getKey
:End
:Disp Ans

[edit] Bouncing 'X'

This code will simply make an 'X' bounce around the screen. You can find 'less than', 'greater than' and ' or ' under 2nd→Test

PROGRAM:BOUNCE
:ClrHome
:1→X:1→Y
:1→S:1→T
:Lbl A
:While 1
:ClrHome
:Output(Y,X,"X
:X+S→X
:Y+T→Y
:If X<2 or X>15
:-S→S
:If Y<2 or Y>7
:-T→T
:For(I,1,50
:End
:Goto A

[edit] Bouncing 'X' 2

This is another form of the same program. NOTE that the bouncing letter, symbol, or number does not NEED to be an X. It may be anything. Input "",Str1 lets you put in ANY letter, number or symbol. Str1 is found in VARS, String..., choose any string. Lbl (Labels) are found in PRGM as 9, and Goto is 0.

PROGRAM:BOUNCE (version 2)
:ClrHome
:Input"",Str1
:ClrHome
:1→A
:1→B
:8→C
:8→D
:Randint(1,2)→E
:Randint(1,2)→F
:Lbl A
:ClrHome
:Output(C,D," "
:Output(A,B,Str1
:A→C
:B→D
:If A=1
:1→E
:If A=8
:2→E
:If B=1
:1→F
:If B=16
:2→F
:If E=1
:A+1→A
:If E=2
:A-1→A
:If F=1
:B+1→B
:If F=2
:B-1→B
:Goto A

If you want, you may make the bouncing onject more than one letter, number, or symbol long. But, then you will need 2 spaces in ':Output(C,D," "', and 16 woul be substituted with another number in ':If B=16  :2→F' a=number of letters in word/whatever / b=number to sub with 16, 17 - a = b. (17 - 1 = 16.)

[edit] Number guessing game

This program is a simple number guessing game.

PROGRAM:GUESSNUM
:ClrHome
:DelVar T
:randInt(1,50→Y
:Disp "START GUESSING!
:Lbl 0
:Prompt X
:If X!=Y
:Then
:T+1→T
:If X>Y
:Then
:Disp "TOO LARGE!
:Goto 0
:Else
:Disp "TOO SMALL!
:Goto 0
:End
:Else
:ClrHome
:Disp "CORRECT!","TRIES:
:Output(2,8,T
:End

[edit] Another Simple Number Guessing Game

This program picks a number between 1 and 10, and makes you guess it.

PROGRAM:PICKNUMB
:ClrHome
:randInt(1,10)→A
:Disp   "PICK A NUMBER"
:Input  "BETWEEN 1 AND 10",B
:If B=A
:Then
:Disp   "YOU WIN!"
:Else   
:Disp   "HAHA! YOU LOSE!
:Disp   "NUMBER WAS",A

[edit] CASINO83

This game simulates random probability and is extremely addicting. (Updated 2-09-2007 4:50 PST)

PROGRAM:CASINO83
::"TI-83+ Virtual Casino
:Menu("Difficulty","Easy",A,"Normal",B,"Casino",C)
:Lbl A
:11→D
:Goto Θ
:Lbl B
:10->D
:Goto Θ
:Lbl C
:9->D
:Lbl Θ
:Menu("Continue?","Continue",3,"New game",7)
:Lbl 7
:{0,2000}->LC83
:Lbl 3
:ClrHome
:LC83(2)-200->LC83(2)
:LC83(1)+200->LC83(1)
:Output(1,1,"You have")
:Output(2,1,LC83(1))
:Output(3,1,"dollars on hand+")
:Output(4,1,LC83(2))
:Output(5,1,"in your bank")sfghjkl;
:Input "Number:",N
:ClrHome:0->Y
:For(A,1,T)
:randInt(0,10)->X
:If X=N
:Then:DB+LC83(1)->LC83(1)
:Else:-1B+LC83(1)->LC83(1)
:End:End:ClrHome
:Output(1,1,"You have")
:Output(2,1,LC83(1))
:Output(3,1,"dollars on hand+")
:Output(4,1,LC83(2))
:Output(5,1,"in your bank")
:Output(8,1,"Press enter")
:Pause
:If LC83< or =0
:Then
:LC83(2)-200->LC83(2)
:200->LC83(1)
:If LC83< or =0 and LC83(2)< or =0:Goto BR
:End
:Menu("Continue?","Yes:,2,"Cash out:,5)
:Lbl 5
:LC83(1)+LC83(2)->LC83(2)
:0->LC83(1)
:ClrHome:Stop
:Lbl BR
:ClrHome
:Disp "Bankrupt!"

[edit] Move dot using arrow keys

A common feature of TI-BASIC game programming is programming the arrow buttons to move an object on the screen. This program will draw a dot on the screen that will move according to which arrow buttons pressed. The lines up to While 1 set up the graph mode screen for use with pixel-by-pixel movement.

PROGRAM:MOVEDOT
:ClrDraw
:-47→Xmin
:47→Xmax
:-31→Ymin
:31→Ymax
:0→X:0→Y
:While 1
:Pt-Off(X,Y)
:getKey→C
:If C=24:X-1→X
:If C=25:Y+1→Y
:If C=26:X+1→X
:If C=34:Y-1→Y
:Pt-On(X,Y)
:End

However, this code is both large and slow. Attempts have been made to optimize TI-Basic. The program below does the same thing as the program above, yet is far smaller, and somewhat faster. Note that the end parentheses for commands such as "Pt-On" (point-on) are not needed; often ending quotes, parentheses, brackets, and braces can be eliminated to save space.

PROGRAM:MOVEDOT
:ZStandard
:ZInteger
:0→X:0→Y
:While 1
:If K>0: Pt-Off(X,Y
:getKey→K
:X+(Ans=26)-(Ans=24→X
:Y+(K=25)-(K=34→Y
:Pt-On(X,Y
:End

One thing might occur; if you hold down one of the arrow keys for a long time, it will skip the shading of a few pixels. Someone's gotta fix this. Matt, ARE YOU HERE?

[edit] Advanced Menu, Using GetKey

A more advanced example of a menu that can be used instead of the "Menu(" button (As in the 68K Calculators).

PROGRAM:MENU
:ClrHome
:Output(1,1,"==== MENU ====
:Output(2,1,"CHOICE 1   
:Output(3,1,"CHOICE 2   
:Output(4,1,"CHOICE 3   
:Output(5,1,"CHOICE 4   
:Output(6,1,"CHOICE 5   
:Output(7,1,"QUIT       
:Output(8,1,"==== MENU ====
:2→Y
:Output(Y,4,"[
:Output(Y,13,"]
:Lbl GK
:DelVar K
:Repeat K=25 or K=34 or K=45 or K=105
:getKey→K
:End
:If K=105:Goto DC
:If K=45:Then
:7->Y
:Goto DC
:End
:Output(Y,4," "
:Output(Y,13," "
:Y+(K=34)-(K=25->Y
:If Y>7:2->Y
:If Y<2:7->Y
:Output(Y,4,"[
:Output(Y,13,"]
:Goto GK
:Lbl DC
:ClrHome
:If Y=6:Then
:Lbl QT
:ClrHome
:DelVar YDelVar K
:Return
:End
:Disp "YOU PICKED","CHOICE
:Pause Y
:Goto QT

[edit] Exec: calling OS routines

In addition, some of the more advanced TI graphing calculators have something called "Exec", which gives the user some control of the 68k Motorola microprocessor by calling built-in subroutines in the calculator's operating system. However, because this gives the user full control of the microprocessing unit, a minor mistake could lead to crashes and loss of data.

Example on 68k Series Calculators: scrnoff()

:Prgm
:Exec "4E444E754E750000"
:EndPrgm

This is a simple (somewhat pointless) program that turns the calculator off from the home screen.

[edit] Checking Battery Power and Memory through a program

Note: This program only works on Omnicalc calculators. To get Omnicalc, you must have a TI-GRAPH LINK cable or TI Connect. You can go to Detached Solutions for the download.

PROGRAM:BATTMEM
::"Battery Status & Memory Usage
:FnOff :ClrDraw
:AxesOff:PlotsOff 
:ZStandard
:real(33,"EFBF41EFB3502803EFD14A")
:X→B
:real(33,"EFE542EF9247EF5641EFD14A")
:X→R
:real(33,"EF4045C9")
:Line(-5,2,5,2)
:Line(-5,2,-5,-2)
:Line(-5,-2,5,-2)
:Line(5,-2,5,-1)
:Line(5,2,5,1)
:Line(5,1,5.5,1)
:Line(5.5,1,5.5,-1)
:Line(-3,2.5,-3,3)
:Text(15,28,"Bad")
:Line(4.75,2.5,4.75,3)
:Text(15,62,"Good")
:If B=0
:Then:4.75→W
:Else:3→W
:End
:For(X,-4.5,W,0.1)
:Line(X,-1.25,X,1.25)
:End 
:-5+(R/24261*10)→W
:Line(-5,-5,-5,-9)
:Line(-5,-9,5,-9)
:Line(-5,-5,5,-5)
:Line(5,-5,5,-9)
:For(X,-4.75,4.75,.4255319149)
:Line(X,-5,X,-4.25)
:Line(X,9,X,-9.75)
:End
:Text(50,10,"RAM")
:Text(50,75,"24K")
:For(X,-5,X,-9)
:Line(X,-5,X,-9)
:End
:real(33,"EF6F4CF578EF8C47EF6742EF6742F1EF8F47F7EFD14A")
:X→O
:Text(4,2,"OS v",O
:real(33,"EFBA80EF8C47EFD14A")
:X→H
:Line(-1.75,6,-1.75,9.5)
:Line(-1.75,6,9,6)
:Line(-1.75,9.5,9,9.5)
:Line(9,9.5,9,6)
:For(X,-1,75,9,.4255319149)
:Line(X,9.5,X,10)
:Line(X,6,X,5.5)
:End
:Text(4,42,"Hardware v"),H
:Pause

[edit] Dialog boxes

Here's another example that shows the 68k Calculators' capability of "dialog" boxes:

:dist2d()
:Prgm
:Local xc1,yc1,xc2,yc2,distance,midxc,midyc
:
:Dialog
:Request "X for first point",xc1
:Request "Y for first point",yc1
:Request "X for second point",xc2
:Request "Y for second point",yc2
:EndDlog
:expr(xc1)→xc1
:expr(yc1)→yc1
:expr(xc2)→xc2
:expr(yc2)→yc2
:
:√((xc2-xc1)^2+(yc2-yc1)^2)→distance
:(xc1+xc2)/2→midxc
:(yc1+yc2)/2→midyc
:
:Dialog
:Title "ANSWERS"
:Text "Distance is "&string(distance)&"."
:Text "Midpoint is ("&string(midxc)&","&string(midyc)&")."
:EndDlog
:EndPrgm

This program makes a "dialog box" much like a Windows popup box. It asks for the x and y coordinates for two points, and gives the distance and midpoint.

[edit] Mathematical Finance

It is possible to use the symbolic computations capabilities of TI-calculators to implement Mathematical Finance Programming in TI-Basic.

[edit] Screensavers

Following are some neat screensaver programs

[edit] Pixelate

This program pixelates the screen, which makes it look like it has a virus, but dont worry :).

PROGRAM:PIXELATE
::"Screen Pixelation
:AxesOff:FnOff
:ClrDraw
:While 1
:randInt(0,62)→X
:randInt(0,94)→Y
:Pxl-Change(X,Y)
:End

Amazingly, it can do much things and it takes up less than 100 bytes of mem. If you get rid of the line that says ::"Screen Pixelation, it will take evel less bytes. The line is there so you can access it from MirageOS.

[edit] Program:Crosshatch

PROGRAM:CHATCH
:FnOff :ClrDraw
:AxesOff
:While 1
:For(C,1,50)
:randInt(-10,10)→X
:randInt(-15,15)→Y
:Horizontal X
:Vertical Y
:End
:ClrDraw
:End

[edit] Another great screensaver...

It's SEISMOMETER TIME! This program monitors the shock waves generated by a few factors... not.

PROGRAM:QUAKESIM
:Simul:AxesOff
:FnOff :ClrDraw
:While 1
:FnON 1,2
:"randInt(-10,10)sin(randInt(-10,10)X)"→Y1
:"0"→Y2
:DispGraph
:End

C'mon! Try it.

[edit] Shootemup

I saw a comment of someone wanting a game, so here is a simple one I made. You have to shoot the alien spacecraft before he shoots you.



PROGRAM:SHOOTIT
:ClrHome
:8→A
:1→F
:1→G
:-1→F
:8→E
:Lbl C
:If A=E:Output(4,6,"HIT!"
:For(D,15,250)
:End
:1→Z
:8→C
:0→D
:Lbl A
:E+F→E
:randInt(1,3)→X
:If E=1:F*-1→F
:If E=1:2→E
:If E=15:F*-1→F
:If E=16:15→E
:If A=0:1→A
:If A=17:16→A
:ClrHome
:Output(1,E,"M"
:Output(8,A,"W"
:getKey→B
:If B=24:A-1→A
:If B=26:A+1→A
:If B=21:Goto B
:If E=A:Goto X
:Goto A
:Lbl B
:C-1→C
:If C=0:Goto C
:Output(8,A,"W"
:For(D,1,12)
:Output(C,A,"+"
:End
:Output(C,A," "
:Goto B
:Lbl X
:Z+1→Z
:If Z=9:Goto C
:Output(1,E,"M"
:Output(8,A,"W"
:For(D,1,12)
:Output(Z,E,"+"
:End
:Output(Z,E," "
:Goto X

This program could most likely be made better in many ways, but I didn't spend much time on making it.