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.
Page Index Toggle Pages: 1
Circle radius. (Read 1668 times)
Circle radius.
Oct 23rd, 2009, 3:43am
 
I'm working with somethign similar to the clock example from Processing, but I would like to alter the radius of the circle created using the maths from the example, could someone show me where in this code I can change the radius of the circle? -  I have tried changing some values but i dont really understand what it starts doing once it goes wrong! Thanks!

void setup() {
 size(200, 200);
 stroke(255);
 smooth();
}
void draw() {
 background(0);
 fill(80);
 noStroke();
 // Angles for sin() and cos() start at 3 o'clock;
 // subtract HALF_PI to make them start at the top
 ellipse(100, 100, 160, 160);
 float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
 float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
 float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
 stroke(255);
 strokeWeight(1);
 line(100, 100, cos(s) * 72 + 100, sin(s) * 72 + 100);
 strokeWeight(2);
 line(100, 100, cos(m) * 60 + 100, sin(m) * 60 + 100);
 strokeWeight(4);
 line(100, 100, cos(h) * 50 + 100, sin(h) * 50 + 100);
 
 // Draw the minute ticks
 strokeWeight(2);
 for (int a = 0; a < 360; a+=6) {
   float x = 100 + ( cos(radians(a)) * 72 );
   float y = 100 + ( sin(radians(a)) * 72 );
   point(x, y);
 }
}
Re: Circle radius.
Reply #1 - Oct 23rd, 2009, 3:58am
 
I modified the code a bit to see more clearly what is what.

Code:
int outerRadius = 200;
int innerRadius = 180;
int centerX = 200;
int centerY = 200;

void setup() {
size(400, 400);
stroke(255);
smooth();
}
void draw() {
background(0);
fill(80);
noStroke();
// Angles for sin() and cos() start at 3 o'clock;
// subtract HALF_PI to make them start at the top
ellipse(centerX, centerY, outerRadius*2, outerRadius*2);
float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
stroke(255);
strokeWeight(1);
line(centerX, centerY, cos(s) * innerRadius + centerX, sin(s) * innerRadius + centerY);
strokeWeight(2);
line(centerX, centerY, cos(m) * innerRadius*5/6 + centerX, sin(m) * innerRadius*5/6 + centerY);
strokeWeight(4);
line(centerX, centerY, cos(h) * innerRadius*4/6 + centerX, sin(h) * innerRadius*4/6 + centerY);

// Draw the minute ticks
strokeWeight(2);
for (int a = 0; a < 360; a+=6) {
  float x = centerX + ( cos(radians(a)) * innerRadius );
  float y = centerY + ( sin(radians(a)) * innerRadius );
  point(x, y);
}
}
Re: Circle radius.
Reply #2 - Oct 23rd, 2009, 4:56am
 
Wicked that's helped a lot, it wasn't that clear in the example! I've got that working but there's still another step i'm not sure about.
I am using 'times' imported from a text file instead of using the second(), minute() & hour() functions, so when the number '3' comes through from the text file my script plots it a point on the circle (in the 3 o'clock position).
I want to make innerRadius a variable so if the the number 3 comes through again the innerRadius increases a bit. I understand creating variables and simple functions, but I cant use something like:

'if(number is 3){ innerRadius++;}'

because would need 24 of these for the hour data and far too many for the minutes, any ideas of a better way I could approach it? Thanks!
Re: Circle radius.
Reply #3 - Oct 23rd, 2009, 4:59am
 
innerRadius is already a variable, so you can adjust it as you please.

I don't fully understand what you mean by creating "24 of these".
Of what exactly ?

What are you trying to accomplish ?
Re: Circle radius.
Reply #4 - Oct 23rd, 2009, 6:03am
 
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;

}
Re: Circle radius.
Reply #5 - Oct 23rd, 2009, 12:06pm
 
I guess you should just make an array with 24 elements, one for each hour. Save in that array the number of occurences in the file and multiply with a factor and add that value to the innerRadius when plotting the point for a specific hour.
Re: Circle radius.
Reply #6 - Oct 23rd, 2009, 12:22pm
 
I'll give that a try cheers:) L.
Page Index Toggle Pages: 1