Question Graph drawer Write a class that provides a method to draw a graph of a function given as an array of x-coordinates and an array of corresponding y-coordinates. It has the heading
วาดกราฟ โดยเขียนฟังก์ชันวาดกราฟโดยให้ค่า x และ y ในรูปแบบของ array
public void drawGraph(float[]x,float[]y)
The method draws straight lines from one point to another.It also draws the axes.
ฟังก์ชั่นวาดเส้นตรงตามแกน
Answer
int i;
int j;
float[]x={5,20,50,75.5,105,130,150,180,195};
float[]y={150,50,130,80,100,60,80,10,50};
void setup(){
size(200,200);
strokeWeight(5);
background(250);
drawGraph();
}
void drawGraph(){
while(i<x.length&&j<=x.length){
j=i+1;
line(x[i],y[i],x[j],y[j]);
ellipse(x[i],y[i],5,5);
i=i+1;
j=j+2;
}
}
source : Java for students
Douglas Bell and Mike Parr. -- 2nd ed. page 253
ISBN : 0-13010922-3
ไม่มีความคิดเห็น:
แสดงความคิดเห็น