Calico Jigsaw

From IPRE Wiki
Revision as of 15:59, 13 May 2013 by Myro-user (Talk | contribs) (<div id="Jigsaw.CStatement">Statement-block</div>)

Jump to: navigation, search

Calico Jigsaw

Calico Jigsaw is a graphical direct-manipulation block-oriented language that follows the lead of Scratch. Jigsaw is a full member of the Calico family of programming languages and can seamlessly interoperate with all languages and programming contexts integrated into Calico. For example, a program written in Jigsaw can directly call functions written in any other Calico language.

Calico Jigsaw can use any of the number of modules written for Calico, include Myro (with robots, text-to-speech, images), Processing (art), and Graphics (objects, physics simulation, and more).

Getting Started

Before beginning, you need to make sure Jigsaw has been activated:

  1. go to menu -> Calico -> Languages
  2. make sure that Jigsaw has a check next to it
  3. if it doesn't select it

You only need to activate Jigsaw once. Calico will remember that, and will load it on start-up.

You can start editing a Jigsaw script in one of three ways:

  • Create a new Jigsaw Script from scratch (menu -> File -> New)
  • Open an existing example (menu -> File -> Examples -> Jigsaw)
  • Open one of your previously-created scripts (menu -> File -> Open)

Calico-jigsaw-start.gif

In general, you pick a tab, then a block from the tab, and drag it onto the workspace.

NOTE: it is often very useful to use the Find function (menu -> Edit -> Find...) to find blocks. Just enter the text you are looking for in the Find box, and press ENTER, or control+f, control+g.

Double-clicking a block will run it (and all the following connected blocks).

When you click on a block in the workspace, a Property table will appear next to the Output tab. From the Property tab, you can edit properties, including arguments, variable names, etc.

Like-minded blocks are color-coded to match each other. Each tab has its own color and blocks on that tab will match.

On a block, items with blue text on a white background indicate an item that you can change. Select the block (with the mouse) and the items that you can change appear in the Property tab (next to the Output tab).

NOTE: control+c will copy the selected block or stack of blocks from the workspace. control+v will paste the copied block(s) onto the workspace.

Jigsaw uses Python to evaluate expressions. That is, any general expression (such as "1 + 1", "a or b" or "int('45')") uses Python to figure out the meaning.

Jigsaw spans two models: the Jigsaw block processing model, and the Python model. For example, when you define a Procedure, it is both a Jigsaw procedure, but also a Python procedure.

NOTE: if you right-click on a block in the workspace, and select Help, you will be taken to the appropriate section on this page, given that you have an internet connection.

Blocks

The following sections describe all of the default blocks in Jigsaw. You can also add more blocks by menu -> Edit -> Use a Module... and selecting a module.

The best-supported modules for Jigsaw are:

Control Tab

The Control Tab contains blocks that pertain to program control.

When script starts

Start-block.gif


This is the main block that starts off any Jigsaw program. You can have more than one of these blocks, which will run in parallel.

If-block

If-block.gif


The If-block allows you to execute a block stack only when a condition is True. The conditional expression must be a boolean value (evaluates to True or False).

If-else-block

If-else-block.gif


The If-else-block allows you to execute a block when a condition is True, or otherwise execute a second block. The two area for blocks represent alternate choices. The conditional expression must be a boolean value (evaluates to True or False).

While-block

While-block.gif


The While-block allows you to execute a block while a condition is True. The conditional expression must be a boolean value (evaluates to True or False).

Repeat-block

Repeat-block.gif


The Repeat-block allows you to execute a block a given number of times.

For-each-block

For-each-block.gif


The For-each-block allows you to execute a block a given number of times, where each time the item variable receives the next item from the sequence.

Exit-block

Exit-block.gif


The Exit-block allows you to exit from a control block.

End-block

End-block.gif


The End-block allows you to end the program immediately.

Statements Tab

The Statements tab contains blocks that pertain to single statements.

Assignment-block

Assignment-block.gif


The Assignment-block allows you to assign a value to a variable.

Statement-block

Statement-block.gif


The Statement-block allows you to execute a statement. By default the statement is just "pass", which means "don't do anything". You can type any valid statement into the statement area.

Random-block

Random-block.gif


The Random-block allows you to get a random number between a minimum and maximum, and save it in a variable.

Comment-block

Comment-block.gif


The Comment-block allows you to insert a comment into a stack of blocks.

Freestyle-Comment-block

Freestyle-comment-block.gif


The Freestyle-comment-block allows you to put a comment anywhere on the workspace.

Input/Output Tab

The Input/Output Tab contains blocks for getting information, and sending information.

Print-block

Print-block.gif


The Print-block allows you to display information in the Output Tab.

Ask-block

Ask-block.gif


The Ask-block allows you to ask the user for some information. The information is always returned as a "string". To convert a string to another type, you can use the int() or float() functions, like shown here:

result = Ask('Question:')
result = int(result)

or

result = Ask('Question:')
result = float(result)

Also, you can always turn a number into a string by using the str() function.

Tell-block

Tell-block.gif


The tell-block allows you to give a message to the user in a dialog window.

Beep-block

Beep-block.gif


The Beep-block allows you to make your computer beep.

Procedures Tab

The Procedures Tab contains blocks that pertain to making and calling Procedures.

Define-Procedure-block

Define-procedure-block.gif


The Define-Procedure-block allows you to define a new procedure, with parameters, if you wish.

Return-block

Return-block.gif


The Return-block allows you to return a value from a procedure.

Call-Procedure-block

Call-procedure-block.gif


The Call-Procedure-block allows you to call a procedure, with arguments, if you defined it as such.

Procedure Examples

Add two numbers

To create a new procedure that adds two numbers together, do this:

  1. Open a New Jigsaw Script
  2. Drag a Define-Procedure Block onto the workspace
    1. Click the Define-Procedure Block
    2. Change the Procedure Name from in Properties from MyProc to Add
    3. Change the Param1 name from blank to num1
    4. Change the Param2 name from blank to num2
  3. Drag a Return Block into the Define-Procedure Block
    1. Change the Expression in Properties to num1 + num2
  4. Drag a Call-Procedure Block to the "when script start" block
    1. Change Procedure Name to Add
    2. Change Arg1 to 23
    3. Change Arg2 to 47
  5. Drag a Tell Block to "when script starts"
    1. Change 'message' to 'The answer is ' + str(result)

Procedure-example.gif

Procedure with test

To create a new procedure that performs a test, do this:

  1. Open a New Jigsaw Script
  2. Drag a Define-Procedure Block onto the workspace
    1. Click the Define-Procedure Block
    2. Change the Procedure Name from in Properties from MyProc to foo
    3. Change the Param1 name from blank to bar
  3. Drag an If-Else Block from the Control Tab to the Define-Procedure Block
  4. Drag an Assignment Block to the If section of the If-Else Block
  5. Drag an Assignment Block to the Else section of the If-Else Block
  6. Drag a Return Block into the Define-Procedure Block
    1. Change the Expression in Properties to result
  7. Drag an Ask Block from the Input/Output Tab to the workspace in the when script starts block
  8. Drag a Call-Procedure Block under the Ask block
    1. Change Procedure Name to foo
    2. Change Arg1 to int(result)
  9. Drag a Print Block from the Input/Output Tab under the Procedure Call Block

Jigsaw-proc-test.gif

Event Handling Example

You can handle events in Jigsaw, using the basic Procedure block. For example, here is a Graphics mouse movement handler:

Calico-jigsaw-handler.gif

Additional Module Tabs

Additional module tab will appear when you menu -> Edit -> Use a Module. This tab contains blocks that pertain to a particular module, such as Calico Jigsaw: Myro.

Module-block

This is a block from an additional module.

Advanced

This section describes advanced capabilities of Jigsaw.

calico object

There is a pre-defined variable named calico which allows interaction with the Calico environment. This included accessing other programs (including Spreadsheets) and other languages. You can see more information on these functions be reading about Calico: calico object.

Data Structures

You can create Data Structures (or other unconstrained expressions) by using the Assignment-block and the Statement-block. Use the Assignment-block for generic assignments, and the Statement-block for generic statement expressions.

For example, if you would like to create a Dictionary (AKA hash table, association list, etc) use:

myDict = dict()

or a list:

myList = list()

The Statement block can be used to do something, such as call a method on an item in a list:

myList[0].move(1, 1)