File: color4.cc

package info (click to toggle)
atom4 4.1-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 908 kB
  • sloc: cpp: 4,451; makefile: 25; perl: 6
file content (50 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (7)
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
/*
 * Atom-4 triboard celltype wrapper
 * Implementation file
 *
 * $Id$
 */

#include "color4.h"


int color4::colortype() {
  if (val=='a' || val=='h') return 0;
  if (val=='b' || val=='c' || val=='e')
    return 1;				// additive
  if (val=='d' || val=='f' || val=='g')
    return 2;				// subtractive

  return -1;				// invalid color
}

color4 color4::propagator(int type) {
  switch(type) {
  case 1:	return color4('h');
  case 2:	return color4('a');
  default:	return BAD_CELL;
  }
}

color4 color4::mix(color4 c) {
  if (c.colortype() < 0) return c;	// c cannot be affected

  switch(colortype()) {
  case 1:				// additive
    return color4(((c.val-'a') | (val-'a')) + 'a');
  case 2:
    return color4(((c.val-'a') & (val-'a')) + 'a');
  default:
    return c;
  }
}

color4 color4::rotl() {
  int rawval = val-'a';
  return color4(( ((rawval<<1)&7) | ((rawval>>2)&1) ) + 'a' );
}

color4 color4::rotr() {
  int rawval = val-'a';
  return color4(( (rawval>>1) | ((rawval&1)<<2) ) + 'a');
}