BTC Request Last updated: 2023-08-30

The following example showcases a simple interface where a request is made to the Coindesk API to fetch the current value of Bitcoin. The user can select the desired currency using a combo box. This information is updated every 10 seconds.

Coindesk's Bitcoin API:

https://api.coindesk.com/v1/bpi/currentprice.json

Note

coindesk.com is property of CoinDesk Inc. and it is not affiliated in any way with Sistemas Enres S.A. de C.V. nor with the ExMachina platform. The use of their API is only for demo purposes.

Graphical Interface Sample

The window displays a black area where the text presents the data from the API link, including the selected currency, the value of Bitcoin, and the corresponding timestamp.

The window also contains a combo box where the user can select the desired currency. The default value is USD.

Structure

This section describes the structure of the main and only internal machine of the project.

1. Root

This is the main board responsible for identifying the type of event and taking the appropriate action. The image describes what happens in each case.

2. init

The init event is automatically generated when the program starts. It prompts the declaration of the graphical interface elements seen at the beginning, the initialization of the timer, and temporary storage values.

3. timerCompleted

In this board, the request to the Coindesk API is prepared and executed. You can observe how the HTTP request is prepared and sent.

4. httpRequestResponse

The httpRequestResponse event is generated when a response to the GET request is received. In this board the response, which is in JSON format, is read and the relevant information is extracted. If the parsing of the response fails, the generated exception will be caught by the CatchAll Terminal.

This is a typical response from the API:

INSERT GITHUB GIST HERE

4.1 exception

If an exception is thrown in the previous board, then this board will be accessed. The response will be displayed as is in the graphical interface, allowing the user to be aware of the error.

4.2 else

If the response is as expected and no exception is thrown while parsing it, then the current exchange rate between Bitcoin and the selected currency is displayed in the graphical interface.

Used Blocks

5. listenedWindow

In this particular program, this event can only be generated by the user pressing the close button of the window. When the button is pressed, the program terminates.

Used Blocks

6. listenedSelection

In this particular program, this event can only be generated if the button is pressed.

6.1 boton

If the button was pressed, the files in the path are requested.

6.2 else

No message is pushed.

Used Blocks

7. filesInPath

When the program obtains the files in the path, check if the file 'btcPrice.xlsx' already exists. If the file doesn't exists, it creates it.

7.1 if

If the file alredy exists, it is read.

7.2 else

If the file doesn't exists, it creates it.

8. readSuccessful

If the file doesn't exists, it updates it.

9. failure

If an error occurs in any of the connectors (in this program the only connectors used are the GUI connector and the HTTP connector) a failure event will be generated. In this case, the error information is printed to the console, and the program is terminated.

10. else

If any event other than the ones listed on the previous cases is generated, the program ignores it.

Used Blocks

getPath

Gets the path where the xlsx file is going to be saved

Hello Goodbye Last updated: 2024-05-07

Asks the user to write an integer between 0 and 30 in the console. If the input is invalid, the user is asked to try again. If the input is valid, 'Hello...n' is printed into the console (n ist he number witten by the user) and every second '...n-t', is printed into the console(t is the number of seconds that have passed since 'Hello...n' was printed). When t=n, 'Goodbye' is printed and the program terminates.

Execution Sample

When the program is executed the user should double click exdemos%systdemos%helloGoodbye_n in the 'Active Processes' list in the 'Executables' tab. Once the platform confirms that it is now sending to exdemos%systdemos%helloGoodbye_n please, the user would write an integer between 0 and 30 in the console

helloGoodbye

This section describes the structure of the main internal machine of the project.

1. Root

This is the main board responsible for identifying the type of event and taking the appropriate action.

2. init

Prints the instructions on how to send a message from the console to the actor in the console.

Used Blocks

2. init

Prints the instructions on how to send a message from the console to the actor in the console.

Used Blocks

3. fromSI

Reads the value received from the console. If the value from the console is not a number, an exception will be thrown and the CatchAll block will catch it.

3.1 Exception Board

The exception occurs when the value submitted was not an integer. The user is informed and asked to try again.

Used Blocks

3.2 Else

If the recieved value is a number, it is still necessary to check that it is between 0 and 30.

Used Blocks

3.2.1 If

If the number entered is not between the range 0 and 30, the user is informed that the input was invalid and is aske to try again.

Used Blocks

3.2.2 Else

If the input is valid, 'Hello...n' is printed into the console and every second '...n-t', is printed into the console.

4. timerCompleted

Reads the current value of the timer and if it greater than 0.

4.1 If

If the value of the timer (val) is still greater than 0, then 'val...' is printed into the console and val-1 is stored as the new value of 'val' in the TS

4.1 Else

If the timer is completed, then 'Goodbye' is printed into the console and the program is terminated.

Used Blocks

5. Else

No message is pushed.

Used Blocks

Digit Evaluator Last updated: 2024-02-28

The user can draw a digit (0-9) in the black box with the mouse and then press the 'Identify' button, and the program will attempt to identify the drawn digit. A likeness score will be assigned to every digit, with the most likely digit getting a score of 1.

Graphical Interface Sample

The window displays a blackboard where the user can draw the digit to evaluate. It also includes the 'Identify' button to start the program.

digitEvaluator

This section describes the structure of the main internal machine of the project.

1. Root

This is the main board responsible for identifying the type of event and taking the appropriate action.

2. init

The init event is automatically generated when the program starts. It prompts the declaration of the graphical interface elements seen at the beginning and temporary storage values.

3. listenedMouse

Gets which mouse button was pressed.

3.1 leftPressed

Gets the cell selected by the mouse and updates its status. It changes the color of the corresponding pixel and its four neighboring cells to white. In this way, each time a cell is selected, a cross is marked on the board.

3.2 leftReleased

Once the left mouse button is released it stops detecting if the cursor enters a cell.

3.3 mouseEntered

Reads whether 'arrastrando' is true or false. This lets the program know whether the left mouse button is pressed or not.

3.3.1 if

Gets the cell selected by the mouse and updates its status. It changes the color of the corresponding button and its four neighboring cells to white. In this way, each time a cell is selected, a cross is marked on the board.

3.3.1 else

No message is pushed.

Used Blocks

3.4 else

No message is pushed.

Used Blocks

4. listenedWindow

Reads the close button on the window.

4.1 closing

This event can only be generated by the user pressing the close button of the window. When the button is pressed, the program terminates.

Used Blocks

4.2 else

No message is pushed.

Used Blocks

5. listenedSelection

Reads whether the 'Evaluar' button or the 'Clear' button was pressed.

5.1 botonEvaluar

Gets the pixels of the board, and compares it to the samples of the representative digits. A likeness score will be assigned to every digit, with the most likely digit getting a score of 1.

5.2 botonBorrar

Restarts the program, clearing the selection and resetting the cells to black.

5.3 else

No message is pushed.

Used Blocks

6. txtReadSuccessful

Reads the content of the file with sample digits and saves them in temporary storage.

7. failure

If an error occurs in any of the connectors a failure event will be generated. In this case, the error information is printed to the console, and the program is terminated.

8. else

If any event other than the ones listed on the previous cases is generated, the program ignores it.

Used Blocks

centerImage

Centers the digit drawn in the board.

shiftLR

Inverts the image on the x-axis.

Used Blocks

1. if

If positive, it divides the pixels in each column and swap them, passing from the right to the left and vice versa.

2. else

If negative, it adds the total number of columns to get a positive number and divides the rows to swap them.

shiftUD

Inverts the image on the y-axis.

Used Blocks

1. if

If positive, it divides the pixels in each row and swaps them, passing from the right to the left and vice versa.

2. else

If negative, it adds the total number of rows to get a positive number and divides the rows to swaps them.

cstBlack

Creates the black color.

Used Blocks

cstNUMCOL

Establish the number of columns and rows.

Used Blocks

cstRED

Creates the red color.

Used Blocks

cstWHITE

Creates the white color.

Used Blocks

distance

Gets the distance between each axis pixel by pixel.

filePath

Return the file 'centroids' where the samples of each digit are stored.

Game Of Life Last updated: 2023-08-30

A graphical illustration of Conway's Game of Life. The user can draw to the initial state of the game with the mouse, and then let the game evolve from that state.

Graphical Interface Sample

The window displays a blackboard where the user can draw the initial condition of the game. It also includes the run button of the program.

gameOfLife

This section describes the structure of the main internal machine of the project.

1. Root

This is the main board responsible for identifying the type of event and taking the appropriate action.

2. init

The init event is automatically generated when the program starts. It prompts the declaration of the graphical interface elements seen at the beginning and temporary storage values.

3. listenedMouse

Listens to the mouse events.

3.1 leftPressed

Gets the cell selected by the mouse and updates its status. In case they are selected, it deselects them; and vice versa.

3.2 leftReleased

Once the left mouse button is released it stops detecting if the cursor enters a cell.

Used Blocks

3.3 mouseEntered

Reads whether 'arrastrando' is true or false. This lets the program know whether the left mouse button is pressed or not.

3.3.1 if

The state of the entered cell is inverted.

3.3.1 else

No message is pushed.

Used Blocks

3.4 else

No message is pushed.

Used Blocks

4. timerCompleted

Everytime the timer is completed, the state of the game is updated.

5. listenedWindow

Reads the close button on the window.

5.1 closing

This event can only be generated by the user pressing the close button of the window. When the button is pressed, the program terminates.

Used Blocks

5.2 else

No message is pushed.

Used Blocks

6. listenedSelection

Receives an event indicating if the button was pressed.

6.1 if

Halts the game.

6.2 else

The game is restarted.

7. failure

If an error occurs in any of the connectors a failure event will be generated. In this case, the error information is printed to the console and the program is terminated.

8. else

If any event other than the ones listed on the previous cases is generated, the program ignores it.

Used Blocks

createCOLORALIVE

The internal machine createCOLORALIVE establishes the white color used to color the living cells.

Used Blocks

cstCOLORDEAD

The internal machine createCOLORALIVE establish the black color used to color the dead cells.

Used Blocks

cstNUMCOL

The internal machine cstNUMCOL establish the number of columns of the board.

Used Blocks

cstPERIOD

The internal machine cstNUMCOL establish the time used for the timer

Used Blocks

selectColor

The internal machine selectColor selects the color of the cell according to the state.

Used Blocks

if

If true, the cstCOLORALIVE is called.

Used Blocks

else

If true, the cstCOLORALIVE is called.

Used Blocks

updateGameOfLife

For each cell in the grid count the number of living neighboring cells and according to the rules determine the state of the cell in the next generation. Forces neighbors to converge on the position of each cell to obtain each neighbor's state.

updateTablero

Updates the dashboard by comparing the old data with the new data, changing the color of each cell depending on its new value.

Sierpinsky Triangle Last updated: 2024-02-19

Draws a Sierpinsky triangle using the Chaos Game algorithm. The user can relocate the corners of the triangle by left-clicking the new desired position in the black area.

Graphical Interface Sample

The window displays a blackboard where the corners of the triangle are displayed, including the start button of the program.

sierpinskyTriangle

This section describes the structure of the main and the internal machines of the project.

1. Root

This is the main board responsible for identifying the type of event and taking the appropriate action.

2. init

The init event is automatically generated when the program starts. It prompts the declaration of the graphical interface elements seen at the beginning and temporary storage values.

3. listenedMouse

When a mouse click is detected, the corner that is closest to the click, gets moved to the location of the click.

4. listenedSelection

The program has two states defined in the runsp component, one where it is paused and the other where it is executed.

4.1 if

Stops the program and restores the initial settings.

4.2 else

Draw the Sierpinsky triangle. reads the corners and places them as an initial small rectangle. It starts a timer that runs every 100 milliseconds. Then draw the rectangles on the window, continuously updating the position of the pivot point (spb) by randomly selecting and moving it to half the distance between the current corner and the pivot. This process is repeated iteratively.

5. timerCompleted

Reads the number of drawn circles.

5.1 if

If the number of circles drawn is less than 30000, it continues drawing.

5.2 else

If the number of circles drawn is more than 30000, the program stops.

6. listenedWindow

Reads the close button on the window.

6.1 closing

This event can only be generated by the user pressing the close button of the window. When the button is pressed, the program terminates.

Used Blocks

6.2 else

No message is pushed.

Used Blocks

cstINITCOR

The internal machine cstINITCOR the initial coordinates for the vertices of the triangle

Used Blocks

Snake Game Last updated: 2023-08-30

An implementation of the classic Snake game. The direction in which the snake moves can be changed with the arrow keys.

Graphical Interface Sample

The window displays a blackboard where the corners of the triangle are displayed, including the start button of the program.

snakeGame

This section describes the structure of the main and the internal machines of the project.

1. Root

This is the main board responsible for identifying the type of event and taking the appropriate action.

2. init

The init event is automatically generated when the program starts. It prompts the declaration of the graphical interface elements seen at the beginning and temporary storage values.

3. timerCompleted

Each time the cycle is completed, the snake moves forward.

Used Blocks

4. listenedKeyPressed

Reads the arrow keys pressed and assign an int value depending on which key is pressed.

Used Blocks

4.1 37

Reads the left arrow and sets the address to 1.

Used Blocks

4.2 40

Reads the down arrow and sets the address to 2.

Used Blocks

4.3 39

Reads the right arrow and sets the address to 3.

Used Blocks

4.4 38

Reads the up arrow and sets the address to 4.

Used Blocks

4.5 else

No message is pushed. Occurs when the user presses any other key.

Used Blocks

5. listenedWindow

Reads the close button on the window.

5.1 closing

This event can only be generated by the user pressing the close button of the window. When the button is pressed, the program terminates.

Used Blocks

5.2 else

No message is pushed.

Used Blocks

6. failure

If an error occurs in any of the connectors a failure event will be generated. In this case, the error information is printed to the console and the program is terminated.

7. else

If any event other than the ones listed on the previous cases is generated, the program ignores it.

Used Blocks

clear

Resets the game to its original settings.

cstNUMCOL

Sets the number of columns on the board.

Used Blocks

cstPERIOD

Sets the number of milliseconds for the timer.

Used Blocks

randomFoodPosition

Gets a random position for the food and check if the snake is on it.

1. if

If true, recall the randomFoodPosition function.

2. else

Returns the coordinates for the new food position.

redraw

Redraw the snake.

Update

Reads the direction from temporary storage and updates the position of the snake.

1. Case 1

This event occurs when the left key is pressed. Read the coordinates of the snake's body and check if the new coordinates are equal to the coordinates of the food.

1.1 if

If the new position coincides with the position of the food, increase the length of the tail and update the position.

1.2 else

Check if the new head has the same position as a body part.

1.2.1 if

If not, redraw the snake in the new coordinates. .

1.2.1 else

Else, the game ends .

2. Case 2

This event occurs when the down key is pressed. Read the coordinates of the snake's body and check if the new coordinates are equal to the coordinates of the food.

2.1 if

If the new position coincides with the position of the food, increase the length of the tail and update the position.

2.2 else

Check if the new head has the same position as a body part.

2.2.1 if

If not, redraw the snake in the new coordinates. .

2.2.1 else

Else, the game ends .

3. Case 3

This event occurs when the right key is pressed. Read the coordinates of the snake's body and check if the new coordinates are equal to the coordinates of the food.

3.1 if

If the new position coincides with the position of the food, increase the length of the tail and update the position.

3.2 else

Check if the new head has the same position as a body part.

3.2.1 if

If not, redraw the snake in the new coordinates.

3.2.1 else

Else, the game ends .

4. Case 4

This event occurs when the up key is pressed. Read the coordinates of the snake's body and checks if the new coordinates are equal to the coordinates of the food.

4.1 if

If the new position coincides with the position of the food, increase the length of the tail and update the position.

4.2 else

Check if the new head has the same position as a body part.

4.2.1 if

If not, redraw the snake in the new coordinates. .

4.2.1 else

Else, the game ends .

Complex Arithmetic Last updated: 2024-02-29

This project shows how user-defined classes work by creating tokens of a class (Cpl) that represents complex numbers (it contains a num field labeled r, which is used to store the real part of the complex number, and a num field labeled i, which is used to store the imaginary part of the complex number), and using them to perform complex arithmetic operations.

complexArithmetic

This is the main board responsible for identifying the type of event and taking the appropriate action.

complexSum

Adds two complex numbers.

createComplex

Creates a token of a class that represents a complex number, composed by its real and imaginary part.

complexMultiplication

Multiplies two complex numbers.

readComplex

Extracts the real and the imaginary part of the complex number.

Keyboard Test Last updated: 2024-02-29

Displays a square that can be moved with the arrow keys.

Graphical Interface Sample

The window displays a black area where a white square can be moved with the arrow keys.

keyboardTest

This section describes the structure of the main and only internal machine of the project.

1. Root

This is the main board responsible for identifying the type of event and taking the appropriate action.

2. init

The init event is automatically generated when the program starts. It prompts the declaration of the graphical interface elements seen at the beginning and temporary storage values.

3. listenedKeyPressed

Reads which key is pressed.

3.1 37

Updates the coordinates of the 'block' to move to the left. Since the movement is only in the X axis, there is no value to 'updateY'.

3.2 40

Updates the coordinates of the 'block' to move down. Since the movement is only on the Y axis, there is no value to 'updateX'.

3.3 39

Updates the coordinates of the 'block' to move to the left. Since the movement is only in the X axis, there is no value to 'updateY'.

3.4 38

Updates the coordinates of the 'block' to move up. Since the movement is only on the Y axis, there is no value to 'updateX'.

3.5 else

No message is pushed.

Used Blocks

4. listenedWindow

Reads the close button on the window.

4.1 closing

This event can only be generated by the user pressing the close button of the window. When the button is pressed, the program terminates.

Used Blocks

4.2 else

No message is pushed.

Used Blocks

5. failure

If an error occurs in any of the connectors a failure event will be generated. In this case, the error information is printed to the console and the program is terminated.

6. else

If any event other than the ones listed on the previous cases is generated, the program ignores it.

Used Blocks

update

Updates the coordinates of the 'block' to move according the key pressed.

Generic Mat Mult Last updated: 2024-02-29

Generic matrix multiplication. The structure of the matrix multiplication algorithm is defined without establishing which functions will be used as sum and product. Instead, when the 'matMult' function is called, the appropriate functions are passed as abstract references. That way, the abstract function can be used with any data type for which a sum function and a product function can be defined.

genericMatMult

This is the main board responsible of identifying the type of event and taking the appropriate action.

matMult

Generic types are placeholders that indicate that an input or output can be of any type (as long as its rank is equal or higher than the generic's rank). They are written as 'T%%genericID' where genericID is an arbitrary label.

If an output of a function is generic, then at least one input of the function must be generic and have the same genericID (but not necessarily the same rank).

operation

Evaluates the reference sent.