{
  "format": "tokbit",
  "version": 1,
  "name": "Aquarium with seven fish",
  "main": [
    {
      "id": "u38",
      "kind": "call",
      "call": "draw_tank()"
    },
    {
      "id": "u39",
      "kind": "call",
      "call": "draw_bubbles()"
    },
    {
      "id": "u40",
      "kind": "declare",
      "name": "right",
      "type": "list[str]",
      "init": "[\"................\", \"................\", \"................\", \"........###.....\", \"......######....\", \"#...#########...\", \"##.###########..\", \"###########.###.\", \"###############.\", \"##.###########..\", \"#...#########...\", \"......######....\", \"........###.....\", \"................\", \"................\", \"................\"]"
    },
    {
      "id": "u41",
      "kind": "declare",
      "name": "left",
      "type": "list[str]",
      "init": "[\"................\", \"................\", \"................\", \".....###........\", \"....######......\", \"...#########...#\", \"..###########.##\", \".###.###########\", \".###############\", \"..###########.##\", \"...#########...#\", \"....######......\", \".....###........\", \"................\", \"................\", \"................\"]"
    },
    {
      "id": "u42",
      "kind": "declare",
      "name": "x",
      "type": "list[int]",
      "init": "[20, 80, 150, 220, 40, 260, 120]"
    },
    {
      "id": "u43",
      "kind": "declare",
      "name": "y",
      "type": "list[int]",
      "init": "[30, 60, 90, 120, 140, 50, 100]"
    },
    {
      "id": "u44",
      "kind": "declare",
      "name": "dx",
      "type": "list[int]",
      "init": "[2, -3, 1, -2, 3, -1, 2]"
    },
    {
      "id": "u45",
      "kind": "declare",
      "name": "dy",
      "type": "list[int]",
      "init": "[1, -1, 2, 1, -2, 1, -1]"
    },
    {
      "id": "u46",
      "kind": "declare",
      "name": "colors",
      "type": "list[int]",
      "init": "[ORANGE, YELLOW, LIGHT_RED, LIGHT_GREEN, WHITE, PURPLE, CYAN]"
    },
    {
      "id": "u47",
      "kind": "for",
      "variable": "i",
      "range": "7",
      "body": [
        {
          "id": "u48",
          "kind": "call",
          "call": "turn(i, dx[i], right, left)"
        },
        {
          "id": "u49",
          "kind": "call",
          "call": "sprite_color(i, colors[i])"
        },
        {
          "id": "u50",
          "kind": "call",
          "call": "sprite_at(i, x[i], y[i])"
        }
      ]
    },
    {
      "id": "u51",
      "kind": "while",
      "condition": "True",
      "body": [
        {
          "id": "u52",
          "kind": "for",
          "variable": "i",
          "range": "7",
          "body": [
            {
              "id": "u53",
              "kind": "call",
              "call": "swim(i, x, y, dx, dy, right, left)"
            }
          ]
        },
        {
          "id": "u54",
          "kind": "call",
          "call": "sleep(30)"
        }
      ],
      "comment": "Every frame moves all six fish by their step."
    }
  ],
  "functions": [
    {
      "name": "draw_tank",
      "params": [],
      "returnType": null,
      "blocks": [
        {
          "id": "u1",
          "kind": "call",
          "call": "background(BLUE)"
        },
        {
          "id": "u2",
          "kind": "call",
          "call": "border(BLUE)"
        },
        {
          "id": "u3",
          "kind": "call",
          "call": "cls()"
        },
        {
          "id": "u4",
          "kind": "call",
          "call": "color(WHITE)"
        },
        {
          "id": "u5",
          "kind": "call",
          "call": "at(1, 0)"
        },
        {
          "id": "u6",
          "kind": "output",
          "values": "\"Aquarium: press Stop to end\"",
          "newline": false
        },
        {
          "id": "u7",
          "kind": "call",
          "call": "color(YELLOW)"
        },
        {
          "id": "u8",
          "kind": "call",
          "call": "at(0, 23)"
        },
        {
          "id": "u9",
          "kind": "output",
          "values": "\".\" * 40",
          "newline": false
        },
        {
          "id": "u10",
          "kind": "call",
          "call": "at(0, 24)"
        },
        {
          "id": "u11",
          "kind": "output",
          "values": "\":\" * 39",
          "newline": false
        }
      ],
      "comment": "Blue water, the title at the top and sand at the bottom."
    },
    {
      "name": "draw_bubbles",
      "params": [],
      "returnType": null,
      "blocks": [
        {
          "id": "u12",
          "kind": "call",
          "call": "color(LIGHT_BLUE)"
        },
        {
          "id": "u13",
          "kind": "call",
          "call": "at(5, 18)"
        },
        {
          "id": "u14",
          "kind": "output",
          "values": "\"o\"",
          "newline": false
        },
        {
          "id": "u15",
          "kind": "call",
          "call": "at(6, 15)"
        },
        {
          "id": "u16",
          "kind": "output",
          "values": "\"o\"",
          "newline": false
        },
        {
          "id": "u17",
          "kind": "call",
          "call": "at(5, 12)"
        },
        {
          "id": "u18",
          "kind": "output",
          "values": "\"o\"",
          "newline": false
        },
        {
          "id": "u19",
          "kind": "call",
          "call": "at(30, 20)"
        },
        {
          "id": "u20",
          "kind": "output",
          "values": "\"o\"",
          "newline": false
        },
        {
          "id": "u21",
          "kind": "call",
          "call": "at(31, 16)"
        },
        {
          "id": "u22",
          "kind": "output",
          "values": "\"o\"",
          "newline": false
        },
        {
          "id": "u23",
          "kind": "call",
          "call": "at(12, 21)"
        },
        {
          "id": "u24",
          "kind": "output",
          "values": "\"o\"",
          "newline": false
        },
        {
          "id": "u25",
          "kind": "call",
          "call": "at(24, 9)"
        },
        {
          "id": "u26",
          "kind": "output",
          "values": "\"o\"",
          "newline": false
        }
      ],
      "comment": "Bubbles at fixed places in the water."
    },
    {
      "name": "turn",
      "params": [
        {
          "name": "i",
          "type": "int"
        },
        {
          "name": "direction",
          "type": "int"
        },
        {
          "name": "right",
          "type": "list[str]"
        },
        {
          "name": "left",
          "type": "list[str]"
        }
      ],
      "returnType": null,
      "blocks": [
        {
          "id": "u27",
          "kind": "if",
          "condition": "direction > 0",
          "then": [
            {
              "id": "u28",
              "kind": "call",
              "call": "sprite_shape(i, right)"
            }
          ],
          "else": [
            {
              "id": "u29",
              "kind": "call",
              "call": "sprite_shape(i, left)"
            }
          ]
        }
      ],
      "comment": "Gives fish i its shape: facing right when it swims right (direction > 0), otherwise left."
    },
    {
      "name": "swim",
      "params": [
        {
          "name": "i",
          "type": "int"
        },
        {
          "name": "x",
          "type": "list[int]"
        },
        {
          "name": "y",
          "type": "list[int]"
        },
        {
          "name": "dx",
          "type": "list[int]"
        },
        {
          "name": "dy",
          "type": "list[int]"
        },
        {
          "name": "right",
          "type": "list[str]"
        },
        {
          "name": "left",
          "type": "list[str]"
        }
      ],
      "returnType": null,
      "blocks": [
        {
          "id": "u30",
          "kind": "assign",
          "target": "x[i]",
          "value": "x[i] + dx[i]"
        },
        {
          "id": "u31",
          "kind": "assign",
          "target": "y[i]",
          "value": "y[i] + dy[i]"
        },
        {
          "id": "u32",
          "kind": "if",
          "condition": "x[i] <= 0 or x[i] >= 304",
          "then": [
            {
              "id": "u33",
              "kind": "assign",
              "target": "dx[i]",
              "value": "-dx[i]"
            },
            {
              "id": "u34",
              "kind": "call",
              "call": "turn(i, dx[i], right, left)"
            }
          ],
          "else": [],
          "comment": "At the edge a fish turns: both direction and shape flip."
        },
        {
          "id": "u35",
          "kind": "if",
          "condition": "y[i] <= 16 or y[i] >= 160",
          "then": [
            {
              "id": "u36",
              "kind": "assign",
              "target": "dy[i]",
              "value": "-dy[i]"
            }
          ],
          "else": []
        },
        {
          "id": "u37",
          "kind": "call",
          "call": "sprite_at(i, x[i], y[i])"
        }
      ],
      "comment": "One step of fish i: move, turn round at the edge (shape too) and the new sprite position."
    }
  ],
  "comment": "Solution to the task “A seventh fish”: Add a seventh fish to the aquarium. Which lists must get longer and what else must change?"
}
