infused (owner)

Revisions

gist: 115632 Download_button fork
public
Public Clone URL: git://gist.github.com/115632.git
Pretty lights
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
// Creating multibit register display code
 
// Class Register8 is a class to store and display an 8-bit register
 
Register8 myRegister;
int j; // Standard issue i
 
void setup() {
  size(256,200);
  background(0,164,64);
  myRegister = new Register8();
  myRegister.xpos = 0;
  myRegister.ypos = 0;
// myRegister.value = 15;
// myRegister.display();
}
 
void draw() {
// myRegister.value = j;
// println("myRegister.value = " + myRegister.value);
  myRegister.display(mouseX);
}
 
void mousePressed() {
  redraw();
}
 
class Register8 {
   float xpos; // Upper left X position of register
   float ypos; // Upper left Y position of register
   color oncolor; // Color of lit bit indicator
   color offcolor; // Color of unlit bit indicator
   color outline; // Color of rectangle and indicator outlines
   color bgcolor; // Color of rectangle background
   color bitcolor; // Color selected for this bit
   float bitxpos; // Xpos of particular bit
   int value; // Value of this 8-bit register
   int i; //Local i
 
  Register8() { // Register 8 Constructor [DEPRECATED] I like using the class.vars
   xpos = 0;
   ypos = 0;
   oncolor = color(0,255,0);
   offcolor = color(64,92,64);
   outline = color(0,0,0);
   bgcolor = color(64,64,64);
   bitcolor = 0;
   bitxpos = 0;
   value = 0;
   i = 0;
  }
 
   void display( int t_value ) {
     value = t_value;
     stroke(outline);
     fill(bgcolor);
     rect(xpos,ypos,160,20);
     ellipseMode(CORNER);
     for ( i = 0; i < 8; i++ ) {
       if ( (value & (1 << i)) != 0 ) {
// println (" value != 0");
         bitcolor = oncolor;
       } else {
// println (" value = 0");
         bitcolor = offcolor;
       }
       fill(bitcolor);
       bitxpos = (xpos + 160) - ((i+1) * 20);
       ellipse(bitxpos, ypos, 20, 20);
     }
   }
}