AKTIVE

checkers.tcl at trunk
Login

checkers.tcl at trunk

File etc/generator/virtual/pattern/checkers.tcl artifact 883f28b9f0 on branch trunk


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
   100
   101
   102
   103
   104
   105
   106
   107
   108
   109
   110
   111
   112
   113
   114
   115
   116
   117
   118
   119
   120
   121
   122
   123
   124
   125
   126
   127
   128
   129
   130
   131
   132
   133
   134
   135
   136
   137
   138
   139
   140
   141
   142
   143
   144
   145
   146
   147
   148
   149
   150
   151
   152
   153
   154
   155
   156
   157
   158
   159
   160
   161
   162
   163
   164
   165
   166
   167
   168
   169
   170
   171
   172
   173
   174
   175
   176
   177
   178
   179
   180
   181
   182
   183
   184
   185
   186
   187
   188
   189
## -*- mode: tcl ; fill-column: 90 -*-
# # ## ### ##### ######## ############# #####################
## Generators -- Virtual Image - Variations on stripe, grid, and checker board patterns

operator image::grid {
    section generator virtual

    note Returns image containing an axis-aligned black/white grid with configurable stripes

    example {width 128 height 128}
    example {width 128 height 128 black 16 white 32}
    example {width 128 height 128 black 16 white 32 offset 8}

    uint   width   Width of the returned image
    uint   height  Height of the returned image

    uint? 0 offset     Pattern offset
    uint? 8 black      Width of the black stripe
    uint? 8 white      Width of the white stripe

    body {
	set sv [stripes width $width height $height black $black white $white offset $offset]
	set sh [aktive op rotate cw $sv]

	aktive op math min $sv $sh
    }
}

operator image::dgrid {
    section generator virtual

    note Returns image containing a diagonal black/white grid with configurable stripes

    example {width 128 height 128}
    example {width 128 height 128 black 16 white 32}
    example {width 128 height 128 black 16 white 32 offset 8}

    uint   width   Width of the returned image
    uint   height  Height of the returned image

    uint? 0 offset     Pattern offset
    uint? 8 black      Width of the black stripe
    uint? 8 white      Width of the white stripe

    body {
	set sv [dstripes width $width height $height black $black white $white offset $offset]
	set sh [aktive op rotate cw $sv]

	aktive op math min $sv $sh
    }
}

operator image::stripes {
    section generator virtual

    note Returns image containing a series of vertical black/white stripes.

    example {width 128 height 128}
    example {width 128 height 128 black 16 white 32}
    example {width 128 height 128 black 16 white 32 offset 8}

    uint   width   Width of the returned image
    uint   height  Height of the returned image

    uint? 0 offset     Pattern offset
    uint? 8 black      Width of the black stripe
    uint? 8 white      Width of the white stripe

    state -fields {
	aktive_uint total; // Total width of black and white stripes. Pattern distance.
    } -setup {
	aktive_geometry_set (domain, 0, 0, param->width, param->height, 1);

	// save pattern distance
	state->total = param->black + param->white;
    }

    blit stripes {
	{AH {y AY 1 up} {y SY 1 up}}
	{AW {x AX 1 up} {x SX 1 up}}
	{DD {z 0  1 up} {z 0  1 up}}
    } {point {
	BW (x)
    }}

    pixels {
	#define BW(x) (((((x) + param->offset) % istate->total) >= param->black) ? 1 : 0)
	#define SD (idomain->depth)
	#define SH (idomain->height)
	#define SW (idomain->width)
	#define SX (request->x)
	#define SY (request->y)
	@@stripes@@
	#undef BW
    }
}

operator image::dstripes {
    section generator virtual

    note Returns image containing a series of diagonal black/white stripes.

    example {width 128 height 128}
    example {width 128 height 128 black 16 white 32}
    example {width 128 height 128 black 16 white 32 offset 8}

    uint   width   Width of the returned image
    uint   height  Height of the returned image

    uint? 0 offset     Pattern offset
    uint? 8 black      Width of the black stripe
    uint? 8 white      Width of the white stripe

    state -fields {
	aktive_uint total; // Total width of black and white area. Pattern distance.
    } -setup {
	aktive_geometry_set (domain, 0, 0, param->width, param->height, 1);

	// save pattern distance
	state->total = param->black + param->white;
    }

    blit dstripes {
	{AH {y AY 1 up} {y SY 1 up}}
	{AW {x AX 1 up} {x SX 1 up}}
	{DD {z 0  1 up} {z 0  1 up}}
    } {point {
	BW (x-y)
    }}

    pixels {
	#define BW(x) (((((x) + param->offset) % istate->total) >= param->black) ? 1 : 0)
	#define SD (idomain->depth)
	#define SH (idomain->height)
	#define SW (idomain->width)
	#define SX (request->x)
	#define SY (request->y)
	@@dstripes@@
	#undef BW
    }
}

operator image::checkers {
    section generator virtual

    note Returns image containing a black/white checker board.

    example {width 128 height 128}
    example {width 128 height 128 black 16 white 32}
    example {width 128 height 128 black 16 white 32 offset 8}

    uint   width   Width of the returned image
    uint   height  Height of the returned image

    uint? 0 offset     Pattern offset
    uint? 8 black      Width of the black area
    uint? 8 white      Width of the white area

    state -fields {
	aktive_uint total; // Total width of black and white area. Pattern distance.
    } -setup {
	aktive_geometry_set (domain, 0, 0, param->width, param->height, 1);
	// save pattern distance
	state->total = param->black + param->white;
    }

    blit checkers {
	{AH {y AY 1 up} {y SY 1 up}}
	{AW {x AX 1 up} {x SX 1 up}}
	{DD {z 0  1 up} {z 0  1 up}}
    } {point {
	BW (x) ^ BW (y)
    }}

    pixels {
	#define BW(x) (((((x) + param->offset) % istate->total) >= param->black) ? 1 : 0)
	#define SD (idomain->depth)
	#define SH (idomain->height)
	#define SW (idomain->width)
	#define SX (request->x)
	#define SY (request->y)
	@@checkers@@
	#undef BW
    }
}

##
# # ## ### ##### ######## ############# #####################
::return