To get started drawing
We’ve seen a few actions already, scríobh
was an action, as well as codladh
.
Actions are special values that represent an action the computer can take. In the case of scríobh
that action was writing text on the console, and in the case of codladh
that action was waiting for some time. In the future we’ll see how to make our own actions, but for now we’ll look at how to use them.
When we use an action, we say we are scríobh
action?
When the Setanta interpreter reads “scríobh("Write me on the console")
” it knows to call the scríobh
action, and to pass it the text "Write me on the console"
.
The text in the brackets is called an "Write me on the console"
is the argument to scríobh
.
In the following code we saw before, 2000
is the argument to codladh
:
When this code is run, the computer passes 2000
to the codladh
action and then calls it, causing the program to sleep for 2 seconds.
Some actions in Setanta can take more than 1 argument. When we pass in more than 1 argument we use a ,
”) to separate them.
For example: The scríobh
action can take as many arguments as we want, and it will write them all out with a
Not all actions can take as many arguments as you want. The codladh
action needs exactly 1 argument, no more, no less.
Some actions can also take 0 arguments
Let’s test our
Here is some code that uses scríobh
to write “Setanta is fun!”.
Some actions in Setanta return a value after they are called. We call this value the
To see what I mean, here’s a quick example. Setanta has an action called “uas
So what does uas
do? uas
is an action that takes 2 numbers as arguments and returns the maximum.
E.g. The result of uas(3, 2)
is 3.
We can assign variables to the result of actions like
In this case, the value of biggest
will be 3. Try it out here:
Try out different values, for example what would the code write if you put uas(100, 200)
in instead of uas(3, 2)
.
Note that we could also write scríobh(uas(3, 2))
, using the result of uas
as the argument for scríobh
directly
In our first intro to Setanta we saw this code:
Now we know enough to see what’s going on here!
ceist
action to print “Cad is ainm duit?” on the console.ceist
and stored in the ainm
variable.scríobh
action to write “Dia duit” and the value of the ainm
variable.Try it out again to see this all in action!
Try expanding this program to ask the user for their age too
Now that we’ve learned all about actions, we can finally take to the stage.
We use actions to draw shapes and manipulate the stage. There are a lot of actions at our disposal.
Let’s take at our first stage action “ciorcal
We’ll see why we have to add the “@stáitse
” part
Try this code out:
Remember that you can use the tabs to switch between the console and the stage.
You should see that this code drew a
To understand what the arguments “(200, 200, 50)
” mean, we’ll take a look at
Coordinates are a
The first number in the pair tells you how far to the
E.g. The point (10, 20) can be found by starting in the top-left, moving 10 units to the right, and 20 units down.
We call the horizontal
When we call the ciorcal
action, we pass in three arguments. The first is the “x” coordinate of the ciorcal@stáitse(200, 200, 50)
we were asking the Setanta interpreter to draw a circle on the stage, with the center at (200, 200) and radius 50.
But what are these units? How wide is “200 units”? Unfortunately that’s not a simple question, it totally depends on the size of your screen. However, you can get the width of the screen with fad_x@stáitse
and the height of the screen with fad_y@stáitse
.
For example, this program writes the width and height of the stage, and it writes the point in the middle of the stage. Then it uses that point to draw a big circle in the middle of the stage.
What if want to use different
The “dath
ciorcal
action we call it with dath@stáitse
. The dath
action takes 1 argument, the colour you want to change to.
By changing our earlier code to first change the colour to
The dath
action accepts colours in Irish and English, but also HTML colour codes
You’re not just limited to drawing circles! Setanta has a host of other actions to allow you to draw other shapes. We’ll see more of them throughout the tutorial, but if you’d like to see the