spade-0.1.0.1: docs/graphics-and-animation.md
### Graphics and Animation
Use the #link: graphics# or #link: graphicswindow# functions to open a
graphics window and start drawing things on screen.
The origin is located at the top, left corner.
Objects are drawn in the currently draw color. Use #link: setcolor# function
to change the draw color.
Color is represented by its red, green and blue components. Each can range from
0 to 255.
##### Accelerated mode
If acceleration is enabled, output of the drawing commands are not rendered
until #link: drawscreen# is called.
##### Clearing screen
Use #link: clearscreen# function to fill the screen with the current draw color.
##### Working with screens of different resolutions
Since displays vary widely in their sizes and resolutions, dimensions that
look good on one display might look too small, or too large in a different
display resolution.
To fix this, use #link: setlogicalsize# function to correctly scale rendered
objects to look similar in different displays.
##### Keyboard input handling
The #link: getkeypresses# function can be used to get all the keys that have been pressed
since that last call of this function. This function returns a list that contains
the keycode of the keys. The keycodes can be compared using the values in #link: keycodes#
dictionary.
Example:
```
graphicswindow(500, 500)
wait(5)
-- Wait while user presses some keys
let keyspressed = getkeypresses()
if contains(keyspressed, keycodes.b) then
-- If user pressed 'b' then set color to red
setcolor(255, 0, 0)
else
-- or else set color to green
setcolor(0, 255, 0)
endif
circle(100, 100, 50)
drawscreen()
waitforkey()
```
This method is not very good to detect simultaneous key presses. For that, use
#link: getkeystate# function to capture keyboard state at a point. Then use
#link: inkeystate# function to check if a certain key was pressed at the point
of capture.
Example:
```
graphics()
loop
let ks = getkeystate()
-- Capture keyboard state at this point.
-- Check if both up and left arrows are pressed in the captured state
if (inkeystate(ks, scancodes.up) and inkeystate(ks, scancodes.left)) then
break
endif
endloop
```