วันเสาร์ที่ 29 สิงหาคม พ.ศ. 2558

LAB 2 find area circle

void setup(){
  size(600,600);
}

void draw(){
  background(0);
  textSize(15);
  circle(170+mouseX,300,200);
 
}







//=====function draw circle =====
void circle(int diameter,int X,int Y)//x and y is reference point
{
  int r=diameter/2;//r is radiuse
  float area=PI*(r*r);
  float circleFerence=2*PI*r;
  int x=300,y=200;
  stroke(0,150,255);
  noFill();
  ellipse(X,Y,r,r);
  diameterLine(r,X,Y);
  radiuseLine(r,X,Y);
  showValue(diameter,r,area,circleFerence,x,y);
}

//======make function for make diameter line =======
void diameterLine(int r,int X,int Y)//r is radiuse x and y is reference point of circle
{
  stroke(255,0,0);
  line(X+(r/2),Y,X-(r/2),Y);
  text("Diameter",X+(r/6),Y-5);
 
}

//=====make function for make radiuse line
void radiuseLine(int r,int X,int Y)//r is radiuse x and y is reference point of circle
{
  stroke(0,255,0);
  line(X,Y,X,Y+(r/2));
  text("radius",X+10,Y+(r/4));
}

//====make function for draw text=====
void showValue(int diameter,int r,float area,float circleFerence,int x,int y)
//x and y mean a reference point of text
{
  text("The diameter of this circle is   "+diameter,X+50,Y+460);
  text("The radius of this circle is  "+r,X+50,Y+480);
  text("The area of  this  circle is  "+area,X+50,Y+500);
  text("The circleference of this circle is  "+circleFerence,X+50,Y+520);
 
}
 
 

ไม่มีความคิดเห็น:

แสดงความคิดเห็น