Patricjs - Manual - Program Flow



Repetition

The loop command starts the loop and is followed by the number of repetitions. This is the only argument. Similarly, to JavaScript the line has to be terminated with a semi colon (;).

The next command follows the statments within the loop and sets the end of the series of statements that repeat themselves. You are allowed to have nested loops, with no realistic limit to the number of nests. As each loop is run you can use #rep_count[1] to find the current rep on the lowest level program loop. #rep_count[2] to find the repcount on a nested loop i.e. a loop witin a loop. You can also use if multiple statement to check if is is on an odd or even repetition see example 3.

Example 1;

loop 20;

      hexagon 30;

      move 0,0;

      star 10;

next;

 

Example 2;

loop 10;

      #fill_r=rand(10);

      loop 10;

            C_ARRAY.CREATE 1000,ca2,200,200+#rep_count[1]*100,30+#rep_count[2]*60,30,50;

      next;

next;

Selection

The if statement is used in patricjs for selection. The statement is in the format if condition then it will do the following lines until an end if command line is encountered. Each of these lines has to be terminated by a semi colon (;).

The else statement can be used within a loop. The format is if condition do something else (otherwise) do something else end if.

Example;

 

loop 50;
     if multiple 2;
          fill_colour teal;
     else;
     fill_colour orange;

   end if;
     dodecagon 50;
     move 0,0;
     fill_colour random;
     hexagon 30;
     move 0,0;
     fill_colour yellow;
     star 15;
next;

 



Copyright © 2016 · All Rights Reserved · patric.co.uk