We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › data entry boxes that set points on graph
Page Index Toggle Pages: 1
data entry boxes that set points on graph (Read 953 times)
data entry boxes that set points on graph
Sep 1st, 2009, 10:45am
 
Me again.
Still working on my project.  My next step is to create 4 text boxes that will reflect desired temperature on the graph, so when the temp is reached it is recorded. Once that temp is reached I would like to have the time displayed next to the text box of the corresponding temperature, as well as a colored circle/ellipse recorded on the graph.
Basically I need to be steered in the right direction to learn how to code the input field and turn it into data.

for one input box and one output box.

*my temp input is called tempF
*my time on x is currentPoint
*I have a timer on screen that displays minutes(dis_m) and seconds (dis_s)

I need to:

1.create rects to display output and input.
2.create text input field
3.data in that field = temp1
4.data must be a number with no decimals
5.map out the values for temp1 and time1
6.when tempF reaches temp1, create a point value.
7.record time and display in output rectangle.
8.plot the point with the values from 6.

Once I figure out the data/text box i would like to code the plotting.
Let me know if this is a step in the right direction.
//in draw
rect(xo,yo,..,..);// set rect for time1 display
rect(xi,yi,..,..);// set rect for temp1 display
input code(??,xi,yi); // not sure yet how to code this.
input code = temp1; // input becomes temp1 value


//with my graphing map code
float yw = map(tempF,minTemp,maxTemp, ...,...);//map temp1 value
float xw = map(currentPoint,numberOfGraphPoints,...,...);// map time1 value

//after my graph plotting code
if(tempF = temp1){
fill(colorcode);
point(xw,yw) // i would like this to be a circle/ellipse
text(nf(dis_m,2)+":"+ nf(dis_s,2), xo,yo); // I was hoping this would print the time, but not continue counting.  
}
Re: data entry boxes that set points on graph
Reply #1 - Sep 1st, 2009, 12:29pm
 
Ok here is a start.

I guess I need to add a few steps for it to do what I want.

1. add mouse pressed code so text can be entered for each box
2. no typing will display unless mouse is pressed in that field.
3. need blinking cursor where text is to be entered.
4. need to convert lastInput to a value.

This code is just an experiment to test the display of the time.  That part works.  Now I just need to convert the input to a value, plug in a formula for it to display the time.
I going to try to enter a number, and when that number is equal to the seconds, then display the time.
Basically if(dis_s=lastInput){
text(...time..., float,float);
}
so if I enter 20, at 20 seconds, "00:20" should print on the adjacent box. But as it is now, the lastInput is not a value.

Code:

int dis_m, dis_s;
boolean startcount = false;
PFont font10;
PFont font24;
int TimeLapse = 0;
int StartTime;
float String;
String lastInput = new String();
String currentInput = new String();
void setup()
{
 //setup fonts for use throughout the application
 font10 = loadFont("Verdana-10.vlw");
 font24 = loadFont("Verdana-24.vlw");

size(600,200);
background(255,255,255);

}

void draw()
{
 
textFont(font10);  
   stroke(0);
   fill(255);
   rect(10,18,50,15);// temp input rect
   textAlign(LEFT);
   stroke(255);
   rect(10,34,50,15);// gives background to input field
   stroke(0); // resets stroke to black
   fill(0);
   text(lastInput,25,30);
   text("F",50,30);
   
   fill(255,0,0);
   text(currentInput,25,45);
 
   noFill();
   rect(65,18,50,15); // creates frame for temp display
   

drawbuttons();
if(mousePressed && rectSTART())
{
StartTime = millis();

startcount = true;
}

if(mousePressed && rectSTOP())
{
startcount = false;
}

if(mousePressed && rectRESET())
{
 
dis_m = 0;
dis_s = 0;

}

calculate();
display();
}

void drawbuttons()
{
fill(6,203,27);  rect(400,45,50,20); // green start
fill(250,0,17);  rect(400,70,50,20); // red stop
fill(250,122,30);  rect(400,95,50,20); //orange reset

fill(0);
   textFont(font10);  
   textAlign(CENTER);
   text("Start", 425,59);
   text("Stop", 425, 84);
   text("Reset", 425, 109);
}

boolean rectSTART()
{
if(mouseX >= 400 && mouseX <= 450 && mouseY >= 45 && mouseY <= 65) return true;
else return false;
}

boolean rectSTOP()
{
if(mouseX >= 400 &&  mouseX <= 450 && mouseY >= 70 && mouseY <= 90) return true;
else return false;
}

boolean rectRESET()
{
if(mouseX >= 400 && mouseX <= 450 && mouseY >= 95 && mouseY <= 115) return true;
else return false;
}

void calculate()
{
if(startcount)
{
TimeLapse += millis() - StartTime;
int seconds = (millis() - StartTime) / 1000;
int minutes = seconds/60;
int hours = minutes/60;
seconds -=minutes * 60;
minutes -= hours*60;




dis_m = minutes;
dis_s = seconds;
}
}
void display()
{
stroke(0);
   fill(255,255,255);
 rect(460,50,100,60); // stopwatch  
fill(0);
textFont(font24);
textAlign(LEFT);
text(nf(dis_m,2)+":"+nf(dis_s,2),477,88);
}
void keyPressed()
{
 if(key == ENTER)
{
  lastInput = currentInput = currentInput + key;
  currentInput = "";
  stroke(255);
  fill(255);
   rect(10,33,50,15);// covers old data for type field
  stroke(0);
   fill(255);
   rect(10,18,50,15); // covers old data for temp field
   rect(65,18,50,15); // covers old data for time field
   fill(0);    
   textFont(font10);    
  text(nf(dis_m,2)+":"+nf(dis_s,2),75,30); // displays time of enter
}
else if(key == BACKSPACE && currentInput.length() > 0)
{
  currentInput = currentInput.substring(0, currentInput.length() - 1);
}
else
{
  currentInput = currentInput + key;
}
}
Re: data entry boxes that set points on graph
Reply #2 - Sep 1st, 2009, 4:41pm
 
would controlP5 be a good tool for this?
Page Index Toggle Pages: 1