|
采用红外扫描测距,然后绘出场地图.
采用中型电机旋转一周,红外测距获得测距值,存放在文件中,通过processing按文件内容进行绘图.
===========processing 的代码如下=============
String[] lines;
int index = 0;
int count = 0 ;
void setup() {
size(200, 200);
background(0);
stroke(255);
frameRate(12);
lines = loadStrings("shoroomdata .rtf");
}
void draw() {
if (index < lines.length) {
String[] pieces = split(lines[index], '\t');
if (pieces.length == 1) {
//int x = int(pieces[0]) * 2;
//int y = int(pieces[1]) * 2;
float x = sin(count*TWO_PI/72.0)*int(pieces[0])+100;
float y = cos(count*TWO_PI/72.0)*int(pieces[0])+100;
print(x);print(y);
line(100,100,(int)x,(int)y);
count++;
}
// Go to the next line for the next run through draw()
index = index + 1;
}
}
|
|