Well, im making a graph that plots the hour and minute digits from a list of times onto a clock.
Part of the code I have pulling data out of the text file gives the 'hour number' as an integer, then another variable maps it to fit TWO_PI, so it sits at the correct angle on my 'clock'.
I want the plotted points to increase their inner radius every time there is a repeated number eg so if my list of time data was 10:10, 12:23, 12:01, the '12 o'clock' point would have been extended twice, making it twice as high as the '10 o'clock' point.
Maybe it would be easier to look at my code, for the data file just paste this into a text file calles testnums2.txt:
01441 pm sym
01551 pm sym
02332 pm sym
01818 pm rep
02002 pm sym
02020 pm rep
and my code is:
Code: Table dataTable;
int currentRow = 1;
int level;
int lastLevel;
PFont textfont;
void setup(){
size (400, 400);
dataTable = new Table("testnums2.txt");
}
void draw(){
noStroke();
fill(162, 205, 90, 10);
ellipse(width/2, height/2, 290, 290);
fill(0);
textfont = loadFont("ArialMT-12.vlw");
textFont(textfont);
text("click anywhere to continue", 20, 20);
int time = getTime ();//gets the current time in 4 digits using getTime() function.
float timeMapped = map(time, 0, 2400, 0, 200);// Creates a float of the current time mapped to 0, 200.
int previousTime = getPreviousTime ();// gets previous time.
float previousTimeMapped = map(previousTime, 0, 2400, 0, 200);//maps previous time to 0, 200.
text(time, 20, 20+(currentRow*10));
int hourNumber = getHour ();//gets hour number.
float hourCircular = map(hourNumber, 0, 24, 0, TWO_PI * 2) - HALF_PI; //converts hour number to a map of hours into degrees
fill(255, 0, 0);
noStroke();
ellipse(cos(hourCircular) * 150 + 200, sin(hourCircular) * 150 + 200, 5, 5); //ellipses at hour marks around centre 200, 200.
int previousHour = getPreviousHour();
float previousHourCircular = map(previousHour, 0, 24, 0, TWO_PI * 2) - HALF_PI;
fill(0, 0, 0);
ellipse(cos(previousHourCircular) * 150 + 200, sin(previousHourCircular) * 150 + 200, 5, 5);//ellipses at previous hour point.
stroke(0);
line(cos(previousHourCircular) * 150 + 200, sin(previousHourCircular)* 150 + 200, cos(hourCircular) * 150 + 200, sin(hourCircular)* 150 + 200);
//println(hourNumber);
int minuteNumber = getMinute (); //gets minute number.
float minCircular = map(minuteNumber, 0, 60, 0, TWO_PI) - HALF_PI; //converts min number to a map of hours into degrees
fill(255, 0, 0);
noStroke();
ellipse(cos(minCircular) * 50 + 200, sin(minCircular) * 50 + 200, 5, 5); //ellipses at min marks around centre 200, 200.
int previousMinute = getPreviousMinute();
float previousMinCircular = map(previousMinute, 0, 60, 0, TWO_PI) - HALF_PI;
fill(0, 0, 0);
ellipse(cos(previousMinCircular) * 50 + 200, sin(previousMinCircular) * 50 + 200, 5, 5);//ellipses at previous hour point.
stroke(0);
line(cos(previousMinCircular) * 50 + 200, sin(previousMinCircular)* 50 + 200, cos(minCircular) * 50 + 200, sin(minCircular)* 50 + 200);
println(time);
println(previousMinute);
}
void mousePressed() {
if (mousePressed && (mouseButton == LEFT)) {
int increase = 1;
currentRow = currentRow+increase;
currentRow = constrain(currentRow, 0, 200);
lastLevel = level;
level = level+5;
// println(time);
} else if (mousePressed && (mouseButton == RIGHT)) {
int increase = 1;
currentRow = currentRow-increase;
//println(previousTime);
}
}
int getTime () {
int row;
row = currentRow;
String timeData = (dataTable.getString(row, 0));
int number = int(timeData);
return number;
}
int getPreviousTime () {
int row;
row = currentRow-1;
String timeData = (dataTable.getString(row, 0));
String Digits = (timeData.substring(1,5));
int number = int(Digits);
return number;
}
int getHour () {
int row;
row = currentRow;
String timeData = (dataTable.getString(row, 0));
String hourDigits = (timeData.substring(1,3));
int number = int(hourDigits);
return number;
}
int getPreviousHour () {
int row;
row = currentRow-1;
String timeData = (dataTable.getString(row, 0));
String hourDigits = (timeData.substring(1,3));
int digits = int(hourDigits);
int number = int(hourDigits);
return number;
}
int getMinute () {
int row;
row = currentRow;
String timeData = (dataTable.getString(row, 0));
String minuteDigits = (timeData.substring(3,5));
int number = int(minuteDigits);
return number;
}
int getPreviousMinute () {
int row;
row = currentRow-1;
String timeData = (dataTable.getString(row, 0));
String minuteDigits = (timeData.substring(3,5));
int number = int(minuteDigits);
return number;
}