// Project P1 for CS1050: Truth table plotter // Written by Prof. Jarek Rossignac // Completed on December 15. 2005 // Declaration and initialization of global variables PFont fontUsed; // name of font used for writing numbers on the graphic screen int W=8, H=32; // width (number of colums) and height (number of rows) of the table int T[][] = new int[H][W]; // two dimensional table (array). Will containintegers boolean TF[][] = new boolean[H][W]; // two dimensional table (array). Will contain booleans color myRed = color(250,100,100); color myGreen = color(100,250,100); // my colors (R,G,B) in [0,255] int cw, ch; // cell witdh and height //*************** //*** SETUP *** //*************** void setup() { // executed only once as initialization size(500, 750); // opens graphic window of 600x600 pixels. X axis goes right, Y axis goes DOWN cw=int(0.9*width/W); // computes cell sizes leaving a margin, Cast to integer ch=int(0.9*height/H); // (height and width of window are keywords) fontUsed = loadFont("Times-Roman-25.vlw"); // this font must be loaded (MENU-BAR > TOOLS > CREATE FONTS) textFont(fontUsed, 12); // selects font and assigns size }; // end of setup //*************** //*** DRAW *** //*************** void draw() { // will be executed continuously to refresh the window many frames per second background(200); // erases the screen and set up a light grey background (0 is black, 255 is white) strokeWeight(2); // lines will be drawn thicker translate(width*0.05,height*0.05); // move the origin to leave a margin ShowTruthTable(); // Defined below: does all the work noLoop(); // stop refreshing window }; // end of draw //********************************** //*** RESPOND TO CONTROL WITH KEYS //********************************** void keyPressed() { // executed when a key is pressed if (key=='i') { saveFrame("squares-####.tif");}; // saves a tif image of the window in the folder of this file }; //********************************** //*** COMPUTE AND DRAW TRUTH TABLE //********************************** void ShowTruthTable() { color cellColor = myGreen; // set cellColor to default green int v=0; // current value, will be incremented as we scan the table byte B; // byte equivalent of v String S; // string used to extract the bits of B boolean P[] = new boolean [8]; // table of Booleans corresponding to these bits for (int h=0; h