zebra

Prev Next

Function Names

zebra

Description

This function converts a number (typically referred to a row or column number) to a Boolean true or false in form of zebra patterns. If no further parameters are specified, then the width of the zebra lines is 1, beginning with false followed by true, and is comparable to the function odd(). You can increase the width of the zebra patterns to larger values.

Following rules apply:

  • All values provided to this function are converted to integers first, and negative numbers are increased to 0.
  • If the parameter 'width 1' is 0, then 'false' is returned all values. Further checks listed below are stopped.
  • If the parameter 'width 2' is 0, then 'true' is returned for all values.



This function is useful in combination with formatting and styling tables, allowing to apply zebra color patterns in a convenient way.

Vectorization: This function supports vectorization in the 1st function parameter. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

1

Parameters

No.TypeDescription
1
input
numeral
set
Row or column number

Hint: For row numbers, subtract the row number by the number of header rows in order to avoid zebra patterns to begin in an odd way.

Opt. 2
input
numeral Width 1

This value rules the number of adjacent 'true' values to return along with increasing row or column numbers

Default value: 1
Opt. 3
input
numeral Width 2

This value rules the number of adjacent 'false' values to return along with increasing row or column numbers

Default value: Same value as specified in 2nd parameter. If not specified, then 1 is assumed.

Return value

TypeDescription
boolean
set
Zebra pattern

If this function is called for a sequence of increasing row or column numbers, this function outputs 'true' and 'false' patterns as specified. A set of Booleans is provided if the 1st function parameter is vectorized.

Examples


       table initialize( t, {{ "zebra(..,)", "zebra(..,2)", "zebra(..,3)", "zebra(..,3,1)", "zebra(..,1,3)", "zebra(..,0,2)", "zebra(..,2,0)" }} );
       for (row[] = 1, row[] <= 15, row[]++)
           with table( t, row[] )
           {
               [0] = zebra(row[]-1);  // Subtracted 1 to avoid odd pattern starts with header row
               [1] = zebra(row[]-1, 2);
               [2] = zebra(row[]-1, 3);
               [3] = zebra(row[]-1, 3,1);
               [4] = zebra(row[]-1, 1,3);
               [5] = zebra(row[]-1, 0,2);
               [6] = zebra(row[]-1, 2,0);
               }

       table list(t);
       echo( "Example with vectorization: ", zebra({1..10},2) );

Output

    0 : zebra(..,) | zebra(..,2) | zebra(..,3) | zebra(..,3,1) | zebra(..,1,3) | zebra(..,0,2) | zebra(..,2,0)
    1 : false      | false       | false       | false         | false         | false         | true         
    2 : true       | false       | false       | false         | true          | false         | true         
    3 : false      | true        | false       | false         | true          | false         | true         
    4 : true       | true        | true        | true          | true          | false         | true         
    5 : false      | false       | true        | false         | false         | false         | true         
    6 : true       | false       | true        | false         | true          | false         | true         
    7 : false      | true        | false       | false         | true          | false         | true         
    8 : true       | true        | false       | true          | true          | false         | true         
    9 : false      | false       | false       | false         | false         | false         | true         
   10 : true       | false       | true        | false         | true          | false         | true         
   11 : false      | true        | true        | false         | true          | false         | true         
   12 : true       | true        | true        | true          | true          | false         | true         
   13 : false      | false       | false       | false         | false         | false         | true         
   14 : true       | false       | false       | false         | true          | false         | true         
   15 : false      | true        | false       | false         | true          | false         | true         

Example with vectorization: {false,true,true,false,false,true,true,false,false,true}
Try it yourself: Open LIB_Function_zebra.b4p in B4P_Examples.zip. Decompress before use.