模拟绳线的运动,某一时刻的效果如下:
参考代码:
void DrawString(IplImage *image, double t) { if(!image) return; cvSet(image, cvScalarAll(250)); int sampleCount = image->width/2; int marginalX = (image->width - sampleCount)/2; int marginalY = image->height/2; int scale = 100; int lineWidth = 2; // draw ends double y = sin(CV_PI*0/sampleCount)*cos(CV_PI*t)*scale + marginalY; cvCircle(image, cvPoint(0+marginalX, y), lineWidth, CV_RGB(0, 250, 0), 3, CV_AA); y = sin(CV_PI*sampleCount/sampleCount)*cos(CV_PI*t)*scale + marginalY; cvCircle(image, cvPoint(sampleCount+marginalX, y), 3, CV_RGB(0, 250, 0), lineWidth, CV_AA); for(int x = 0; x <= sampleCount; ++x){ y = ( sin(CV_PI*x/sampleCount)*cos(CV_PI*t) - 0.5*sin(2*CV_PI*x/sampleCount)*cos(2*CV_PI*t) + 0.33333333*sin(3*CV_PI*x/sampleCount)*cos(3*CV_PI*t) )*scale + marginalY; cvLine(image, cvPoint(x+marginalX, y), cvPoint(x+marginalX, y), CV_RGB(250, 0, 0), 2, CV_AA); } }