Display Text and Strings for debugging

GLVGLV
edited January 2018 in Questions about Code

Hello,

I display text in the console and on screen (graphics window) as required primarily for debugging. Ease of use and editing is important. I posted a sample of code that I wrote and use to display to screen.

Feedback and suggestions welcome.

Added a picture.

GLV

// Author: GLV
// Updated 2018-01-01
// Version 00
// "https://" + "forum.processing.org/two/discussion/25778"
// Displays strings and numerical data on screen primarily for debugging
// Neatly formatted and decimal points align
// Easy to distinguish between ints and floats
// Ease of use and editing a requirement for use in different programs
// I can cut and paste the two columns and easily edit these!
// I may create a class for this later...

//Some variables used for display
  float float1 = PI;
  float float2 = PI;
  float float3 = PI;

  int int1 = 1;
  int int2 = 2;
  int int3 = 3;
  int int4 = 4;
  int int5 = 5;

  int x, y;

public void settings() 
  {  
  size(displayWidth, displayHeight); 
  }

public void setup()
  {
  }

public void draw()
  { 
  background(0);

  int4 = mouseX - mouseY;
  float1 = 10*sin (mouseX/100.0);
  float2 = 10*sin (mouseY/100.0);

  dispText3(width/2,height/2);

  dispText3(20, 20);
  }

// Method dispText3: 
// Displays neatly formatted colums (2 columns) of strings and values for debugging
// Used as an alternative to console as required

int i3;                                     // Needed a global i3 to increment i

void dispText3(int x_loc, int y_loc)
  {
  //location of text on screen
  int x3 = x_loc;
  int y3 = y_loc;

  //offsets for x and y 
  int x3_off = 200;                        //offset for column column 2 
  int y3_off = -30;                      //offset (spacing) for rows  I made this a global for now.

// Display string text for column (left)

  textSize(24);
  textAlign(LEFT, TOP);

//  y3 = y3 - y3_off;                      // Not used                 
  i3=0;  
  text("int1           ", x3,   y3i(y3, y3_off)); 
  text("int2           ", x3,   y3i(y3, y3_off)); 
  text("float1         ", x3,   y3i(y3, y3_off));  
  text("mouseX         ", x3,   y3i(y3, y3_off)); 
  text("mouseY         ", x3,   y3i(y3, y3_off)); 
  text("x              ", x3,   y3i(y3, y3_off)); 
  text("y              ", x3,   y3i(y3, y3_off)); 
  text("float2         ", x3,   y3i(y3, y3_off)); 
  text("int3           ", x3,   y3i(y3, y3_off)); 
  text("int4           ", x3,   y3i(y3, y3_off)); 
  text("int5           ", x3,   y3i(y3, y3_off)); 
  text("float3         ", x3,   y3i(y3, y3_off));  

// Display numerical text for column (right)

//  textSize(24);
  textAlign(RIGHT, TOP);

  x3 = x3 + x3_off;                         //offset for right column
  int f = 53;                               //offset for floating point numbers to align decimal point  
  i3 = 0;                                   //reset i for next column
  text(int1,              x3,   y3i(y3, y3_off)); 
  text(int2,              x3,   y3i(y3, y3_off)); 
  text(float1,            x3+f, y3i(y3, y3_off)); 
  text(mouseX,            x3,   y3i(y3, y3_off)); 
  text(mouseY,            x3,   y3i(y3, y3_off)); 
  text(x,                 x3,   y3i(y3, y3_off)); 
  text(y,                 x3,   y3i(y3, y3_off)); 
  text(float2,            x3+f, y3i(y3, y3_off)); 
  text(int3,              x3,   y3i(y3, y3_off)); 
  text(int4,              x3,   y3i(y3, y3_off)); 
  text(int5,              x3,   y3i(y3, y3_off)); 
  text(float3,            x3+f, y3i(y3, y3_off)); 
  } 

// Method y3i: 
// increments\offets each line (by off) with each function call until i3 reset to i3 = 0;

int y3i(int y_loc, int y_off)
  {
  y_loc =  y_loc - i3*y_off;
  i3++; 
  return  y_loc;
  }   

Capture

Tagged:

Comments

Sign In or Register to comment.