static float easingInOutBounce(float t, float b, float c, float d) { if (t < d / 2) { return easingInBounce(t * 2, 0, c, d) * .5 + b; } else { return easingOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b; } }
//-------------------------------------------------------------- void ofApp::update(){ drawLine.clear(); triangulation.reset(); // 現在の位置 vector<ofPoint>& points = svgLines[currIndex].polyline.getVertices(); float scaleWidth = (maxWidth/svgLines[currIndex].width); float scaleHeight = (maxHeight/svgLines[currIndex].height); if (scaleWidth < scaleHeight) { scaleHeight = scaleWidth; } else { scaleWidth = scaleHeight; } // 次の位置 int nextIndex = currIndex == svgLines.size() - 1 ? 0 : currIndex + 1; vector<ofPoint>& nextPoints = svgLines[nextIndex].polyline.getVertices(); float nextScaleWidth = (maxWidth/svgLines[nextIndex].width); float nextScaleHeight = (maxHeight/svgLines[nextIndex].height); if (nextScaleWidth < nextScaleHeight) { nextScaleHeight = nextScaleWidth; } else { nextScaleWidth = nextScaleHeight; } // モーフィング処理 float size = points.size(); float value = ofMap(morphingCount, 0, maxMorphingCount, 0.f, 1.f); // イージング //value = 1 - pow(1 - value, 5); value = easingOutBounce(value); for (int i = 0; i < size; i++) { // たまにサンプル数分、頂点をくれない場合がある if (i >= nextPoints.size()) { continue; } float x = ofMap(value, 0.f, 1.f, points[i].x*scaleWidth, nextPoints[i].x*nextScaleWidth); float y = ofMap(value, 0.f, 1.f, points[i].y*scaleHeight, nextPoints[i].y*nextScaleHeight); drawLine.addVertex(x, y); triangulation.addPoint(ofPoint(x, y)); } morphingCount++; if (morphingCount > maxMorphingCount) { morphingCount = 0; currIndex++; if (currIndex == svgLines.size()) { currIndex = 0; } } drawLine.close(); triangulation.triangulate(); }
static float easingInBounce(float t, float b, float c, float d) { return c - easingOutBounce(d - t, 0, c, d) + b; }