-
Notifications
You must be signed in to change notification settings - Fork 1
A tutorial
require('space',sp)
sp.init(600,450)
function main()
while(true)
//drawing
sp.rect(0,0,50,50)
//refresh screen
sp.refresh()
//other
sp.get(_)
main()
First, init initializes the library with a 600x450 window.
It's good practice to make a main function in which to encase the loop for our game (or simulation, UI, etc).
In main, we use sp.rect(0,0,50,50)
to draw a rectangle and then refresh the screen. We'll get to sp.get
later.
See: what is a relation?
function main()
init x=0
while(true)
//drawing
clear()
sp.setRGB(0,0,0)
sp.rect(x,0,50,50)
sp.refresh()
//get events
sp.get(_)
sp.delay(50)
//update
next x=x+1
Now, we set the rectangle to move by 1 pixel each time. It's important to clear
the area to be drawn and then refresh
to get the result in the screen. We also set the RGB value of the rectangle.
For good measure, we use delay
to give some time between each loop.
Our framework is unique in that it uses logic programming and temporal logic.
As a logic programming framework, actions have to be described.
function main()
init x=0
while(true)
...
next x=x+1
Hence, we state that our rectangle's x coordinate starts at 0 and that the number increases by 1 each time. This is easily done with the init
and next
keywords.
Cosmos and Space is open-source. Anyone can contribute to the project. It's given without any warranty.