Graphics Extension
This is Graphics Extension Command Reference v1.6
Graphics Extension (Hand BASIC v1.4 or later) is available via In-App Purchase.
To open purchase screen:
- Type PURCHASE
- Or, type ACTION then select Purchase
- Or, run a program that uses Graphics
NOTE: To toggle title bar (hide/show) in Screen1 make double touch (two fingers at same time)
Some sample programs (included in App):
(for more programs see CBM Hand BASIC Blog)
SCREEN – Set Screen Mode
SCREEN I
I = Screen Index
0 for text screen (default)
1 for graphic screen.
Portrait Dimension
320 x 460 pixels for iPhone/iPod Touch.
768 x 1004 pixels for iPad
Landscape Dimension
480 x 300 pixels for iPhone/iPod Touch.
1024 x 748 pixels for iPad
2 graphics screen for retina display (useful only for retina display devices)
Portrait Dimension
640 x 920 pixels for iPhone/iPod Touch.
1536 x 2008 pixels for iPad
Landscape Dimension
960 x 600 pixels for iPhone/iPod Touch.
2048 x 1496 pixels for iPad
Coordinate system: x axis goes from left to right, y axis goes from top to bottom
HINT: you usually design the screen to be either Portrait or Landscape but not both
Example:
10 SCREEN 1 : CLS
20 CIRCLE 160, 200, 100, 1, 1
30 GOTO 30
CLS – Clear Screen
Clears current selected Screen. Current Screen is set by SCREEN command
Example:
10 SCREEN 1 : CLS
20 CIRCLE 160, 200, 100, 1, 1
30 GOTO 30
TITLE – Set graphics screen title
TITLE N
N = string value for screen title
Example:
10 SCREEN 1 : CLS
20 TITLE "My Title!"
30 CIRCLE 160, 200, 100, 1, 1
40 GOTO 40
SLEEP – Wait for the specified time. Puts CPU into sleep
Waits the specified time before continuing the program. Saves CPU cycles which in turn saves the battery
SLEEP T
T = Sleep time in milliseconds (1 second = 1000 millisecond).
Example:
10 SCREEN 1 : CLS
20 CIRCLE 160, 200, 100, 1, 1
30 SLEEP 5000
ANTIALIAS – Enable/Disable antialiasing
ANTIALIAS f
f = 0 / 1 (default is enabled f = 1)
Example:
10 SCREEN 1 : CLS
20 ANTIALIAS 0
30 LINE 160, 200, 260, 300, 2
40 GOTO 40
PSET – Draw Pixel (Pixel Set)
PSET X, Y, C
X = x-value of the coordinate for pixel
Y = y-value of the coordinate for pixel
C = Color 0 – 15 or index of user defined color
Example:
10 SCREEN 1 : CLS
20 PSET 160, 200, 1
30 GOTO 30
LINE – Draw Line
LINE X1, Y1, X2, Y2, C
X1, Y1 = line start coordinate
X2, Y2 = line end coordinate
C = line color 0 – 15 or index of user defined color
Example:
10 SCREEN 1 : CLS
20 LINE 160, 200, 260, 300, 2
30 GOTO 30
MOVETO – Move current point to coordinate
moves current point without drawing
MOVETO X, Y
X, Y = new current point coordinate
Example:
10 SCREEN 1 : CLS
20 MOVETO 160, 200
30 LINETO 260, 300, 1
40 GOTO 40
LINETO – Draw line from current point to coordinate
LINETO X, Y, C
X, Y = line end coordinate
C = line color 0 – 15 or index of user defined color
Example:
10 SCREEN 1 : CLS
20 MOVETO 160, 200
30 LINETO 260, 300, 1
40 GOTO 40
RECT – Draw Filled Rectangle
RECT X1, Y1, X2, Y2, C
X1, Y1 = rectangle upper left position
X2, Y2 = rectangle bottom right position
C = rectangle color 0 – 15 or index of user defined color
Example:
10 SCREEN 1 : CLS
20 RECT 160, 200, 260, 300, 1
30 GOTO 30
FRAME – Draw Frame (None filled Rectangle)
FRAME X1, Y1, X2, Y2, C
X1, Y1 = frame upper left position
X2, Y2 = frame bottom right position
C = frame color 0 – 15 or index of user defined color
Example:
10 SCREEN 1 : CLS
20 FRAME 160, 200, 260, 300, 1
30 GOTO 30
CIRCLE – Draw Circle
CIRCLE X, Y, R, C, F
X, Y = center of circle coordinate
R = circle radius
C = circle color 0-15 or index of user defined color
F = circle is filled flag (0/1)
Example:
10 SCREEN 1 : CLS
20 CIRCLE 160, 200, 100, 1, 1
30 GOTO 30
ARC – Draw Arc
ARC X, Y, R, S, E, C, F
X, Y = center of arc coordinate
R = arc radius
S = start angle of arc in degrees
E = end angle of arc in degrees
C = arc color 0-15 or index of user defined color
F = arc is filled flag (0/1)
Example:
10 SCREEN 1 : CLS
20 ARC 160, 200, 100, 0, 45, 1, 1
30 GOTO 30
ELLIPSE – Draw Ellipse
Draw Ellipse inside given rectangle coordinates
ELLIPSE X1, Y1, X2, Y2, C, F
X1, Y1, X2, Y2 = rectangle to draw ellipse inside
C = ellipse color 0-15 or index of user defined color
F = ellipse is filled flag (0/1)
Example:
10 SCREEN 1 : CLS
20 ELLIPSE 160, 200, 300, 300, 3, 1
30 GOTO 30
GPRINT – Draw Text
GPRINT T, X, Y, C
T = string value of the text to draw
X, Y = lower left position of the text
C = text color 0-15 or index of user defined color
Example:
10 SCREEN 1 : CLS
20 GPRINT "Hello World!", 160, 200, 2
30 GOTO 30
Commodore Colors
CSET - Define new color
CSET I, R, G, B, A
I = index of color I > 15. this index can be used in drawing commands
R = red component of color 0-255
G = green component of color 0-255
B = blue component of color 0-255
A = alpha channel (transparency) of color 0-255
Example:
10 SCREEN 1 : CLS
20 CSET 100, 255, 0, 0, 128
30 CIRCLE 160, 200, 100, 1, 100
40 GOTO 40
LSET - set Line style
affects all drawing commands except GPRINT
LSET W, C
W = line width in pixels. default is 1
C = line cap 0 - 2
0 squared-off end (default)
1 rounded (extended)
2 extended squared-off end
Example:
10 SCREEN 1 : CLS
20 LSET 4, 1
30 LINE 160, 200, 260, 300, 2
40 GOTO 40
this sets drawn line style to be 4 pixels wide and line end is rounded and extends beyond givin coordinates
FSET - Set current Font for GPRINT
FSET T, S
T = string of full font name
S = point size of font
to see the list of available font names use direct command FONTS.
to filter fonts use FONTS "filter"
Please note: not all fonts are compatible with Hand BASIC.
Example:
10 SCREEN 1 : CLS
20 FSET "Courier", 16
30 GPRINT "Hello World!", 160, 200, 2
40 GOTO 40
DRAW - Draw using Graphics Macro Language (GML)
Draw T
T = string having list of parameters
Parameters:
CI = set color to I = color index
draw line from current point (last reached point) by moving:
RV = moving to right V pixels (V is an integer value)
LV = moving to left V pixels
UV = moving to up V pixels
DV = moving to down V pixels
EV = moving up and right V pixels
FV = moving down and right V pixels
GV = moving down and left V pixels
HV = moving up and left V pixels
MX,Y = move to point (X,Y)
if you add +/- to X or Y the movement is relative to last point
Modifiers:
B move but does not draw. affects the next command only
N draws and returns to the starting point
you can add spaces if you like to make string readable!
Example:
10 SCREEN 1 : CLS
20 DRAW "BM100,100C1R20U20L20D20"
30 GOTO 30
TRIANGLE - Draw any kind of triangle
drawing triangles almost allow to draw anything
TRIANGLE X1, Y1, X2, Y2, X3, Y3, C, F
X1, Y1 = first corner coordinate
X2, Y2 = second corner coordinate
X3, Y3 = third corner coordinate
C = index of color
F = fill triangle flag 0/1
POLYGON - Draw any kind of polygon
POLYGON XC, YC, R, S, T, C, F
XC, YC = center of polygon
R = radius of polygon
S = number of polygon sides (3-20)
T = polygon rotation angle in degrees (0-360) usually set to zero
C = index of polygon color
F = fill polygon flag 0/1
Example:
10 SCREEN 1 : CLS
20 POLYGON 160,230, 100, 5, 0, 1,0
30 SLEEP 200: GOTO 30
This draws red outlined polygon with five sides
STAR - Draw any kind of star
STAR XC, YC, OR, IR, V, R, C, F
XC, YC = center of star
OR = outer radius of star
IR = inner radius of star (usually IR < OR)
V = number of vertexes of star (3-20)
R = star rotation angle in degrees (0-360) usually set to zero
C = index of star color
F = fill star flag 0/1
Example:
10 SCREEN 1 : CLS
20 STAR 160, 230, 120,40, 5, 0, 6,1
30 GOTO 30
This draws a yellow filled star with five vertexes
BEGINFRAME - Begin drawing into frame
Used to make animations. All drawings are buffered until ENDFRAME
ENDFRAME - End drawing into frame
Used to make animations. All buffered drawings are flushed to screen
See samples: BOUNCE.BAS, RECTS.BAS, FSTARS.BAS
HINT: use TI to control timing (TI returns time: 1 = 1/60 second)
BeginFrame/EndFrame are also useful for minimizing heavy drawing time (since screen refreshing is prevented until finish)
Reading User Taps:
This subroutine shows how to read taps into (X, Y)
3000 REM [SUB READ USER TAP]
3010 DEF FN PK(A)=PEEK(A)+PEEK(A+1)*256
3020 XT=1030
3030 YT=1032
3040 POKE 1024,0
3050 IF PEEK(1024) = 0 THEN GOTO 3050
3060 X = FN PK(XT) : Y = FN PK(YT)
3070 RETURN
FN PK(A) reads 16bit integer from memory address A
Address 1024 has tap event type
Address 1030 has X coordinate of user tap
Address 1032 has Y coordinate of user tap
See QUIZ.BAS sample program