风火轮 –动画效果:擦除、形状、轮子、随机线条、翻转远近、缩放、旋转、弹跳效果

今天再花了一个白天时间,把PPT动画的进入效果全部实现。

  1. 浮入效果

头文件

class TCbwAnimationEffect_Erase : public TCbwAnimationEffect { // 擦除

virtual void __fastcall BuildMaskMat(cv::Mat& destMat, cv::Mat& srcMat,

TRect displayRect);

public:

__fastcall TCbwAnimationEffect_Erase();

static TCbwAnimationEffect * Build();

};

class TCbwAnimationEffect_Shape : public TCbwAnimationEffect { // 形状

virtual void __fastcall BuildMaskMat(cv::Mat& destMat, cv::Mat& srcMat,

TRect displayRect);

public:

__fastcall TCbwAnimationEffect_Shape();

static TCbwAnimationEffect * Build();

};

class TCbwAnimationEffect_Wheel : public TCbwAnimationEffect { // 轮子

virtual void __fastcall BuildMaskMat(cv::Mat& destMat, cv::Mat& srcMat,

TRect displayRect);

public:

__fastcall TCbwAnimationEffect_Wheel();

static TCbwAnimationEffect * Build();

};

class TCbwAnimationEffect_RandomLine : public TCbwAnimationEffect { // 随机线

virtual void __fastcall BuildMaskMat(cv::Mat& destMat, cv::Mat& srcMat,

TRect displayRect);

BYTE * FOccurredLines;

public:

__fastcall TCbwAnimationEffect_RandomLine();

static TCbwAnimationEffect * Build();

};

class TCbwAnimationEffect_RotateToNear : public TCbwAnimationEffect_SameMask

{ // 翻转式由远及近

virtual void __fastcall BuildDisplayMat(cv::Mat& destMat, cv::Mat& srcMat,

TRect displayRect);

public:

__fastcall TCbwAnimationEffect_RotateToNear();

static TCbwAnimationEffect * Build();

};

class TCbwAnimationEffect_Zoom : public TCbwAnimationEffect_SameMask { // 缩放

virtual void __fastcall BuildDisplayMat(cv::Mat& destMat, cv::Mat& srcMat,

TRect displayRect);

public:

__fastcall TCbwAnimationEffect_Zoom();

static TCbwAnimationEffect * Build();

};

class TCbwAnimationEffect_Rotate : public TCbwAnimationEffect_SameMask { // 旋转

virtual void __fastcall BuildDisplayMat(cv::Mat& destMat, cv::Mat& srcMat,

TRect displayRect);

public:

__fastcall TCbwAnimationEffect_Rotate();

static TCbwAnimationEffect * Build();

};

class TCbwAnimationEffect_Bounce : public TCbwAnimationEffect { // 随机线

virtual TRect __fastcall BuildDisplayRect(OBJECTMAT * m);

public:

__fastcall TCbwAnimationEffect_Bounce();

static TCbwAnimationEffect * Build();

};

实现:

// ***************************** 擦除效果 **************************************

__fastcall TCbwAnimationEffect_Erase::TCbwAnimationEffect_Erase()

: TCbwAnimationEffect() {

EffectType = cetErase;

}

TCbwAnimationEffect * TCbwAnimationEffect_Erase::Build() {

return new TCbwAnimationEffect_Erase;

}

void __fastcall TCbwAnimationEffect_Erase::BuildMaskMat(cv::Mat& destMat,

cv::Mat& srcMat, TRect displayRect) {

int effectOptionType = MyOptionType.Items[1].CurrentValue * 2;

// 为了共用CbwEffectDirection类型

TRect wholeRect(0, 0, displayRect.right - displayRect.left,

displayRect.bottom - displayRect.top);

TRect partRect = wholeRect;

bool vertFlag =

(cedFromBottom == effectOptionType || cedFromTop == effectOptionType);

double delta = double(FCurrentIndex + 1) / FPeriodLength * (vertFlag ?

partRect.bottom : partRect.right);

if (cedFromBottom == effectOptionType) // 自底部

partRect.top = partRect.bottom - delta;

if (cedFromLeft == effectOptionType) // 自左侧

partRect.right = partRect.left + delta;

if (cedFromTop == effectOptionType) // 自顶部

partRect.bottom = partRect.top + delta;

if (cedFromRight == effectOptionType) // 自右侧

partRect.left = partRect.right - delta;

BYTE * pSrc = srcMat.data;

BYTE * pDst = destMat.data;

for (int row = 0; row < destMat.rows; ++row)

for (int col = 0; col < destMat.cols; ++col) {

bool hasValueFlag = (*pSrc++ != 0);

if (!hasValueFlag)

* pDst = 0;

int y = (row - partRect.top) * (partRect.bottom - row);

int x = (col - partRect.left) * (partRect.right - col);

bool inFlag = (y >= 0 && x >= 0);

*pDst++ = (inFlag ? 255 : 0);

}

}

// ***************************** 擦除效果 **************************************

// ***************************** 形状效果 **************************************

__fastcall TCbwAnimationEffect_Shape::TCbwAnimationEffect_Shape()

: TCbwAnimationEffect() {

EffectType = cetShape;

}

TCbwAnimationEffect * TCbwAnimationEffect_Shape::Build() {

return new TCbwAnimationEffect_Shape;

}

void __fastcall TCbwAnimationEffect_Shape::BuildMaskMat(cv::Mat& destMat,

cv::Mat& srcMat, TRect displayRect) {

int zoomType = MyOptionType.Items[1].CurrentValue; // 放大、缩小

int shapeType = MyOptionType.Items[2].CurrentValue; // 类型

TRect wholeRect(0, 0, displayRect.right - displayRect.left,

displayRect.bottom - displayRect.top);

double cx = wholeRect.right / 2.0, cy = wholeRect.bottom / 2.0;

double deltaX = double(FCurrentIndex + 1) / FPeriodLength * cx;

double deltaY = double(FCurrentIndex + 1) / FPeriodLength * cy;

double startX = deltaX, startY = deltaY;

double endX = wholeRect.right - deltaX, endY = wholeRect.bottom - deltaY;

if (zoomType == csdZoomOut) {

startX = cx - deltaX;

startY = cy - deltaY;

endX = cx + deltaX;

endY = cy + deltaY;

}

BYTE * pSrc = srcMat.data;

BYTE * pDst = destMat.data;

for (int row = 0; row < destMat.rows; ++row)

for (int col = 0; col < destMat.cols; ++col) {

bool hasValueFlag = (*pSrc++ != 0);

if (!hasValueFlag)

* pDst = 0;

bool inFlag = false;

double a = (cx - startX) * 1.5, b = (cy - startY) * 1.5;

if (shapeType == cstCircle) { // 圆

if (a > 0 && b > 0) {

double v = (row - cy) * (row - cy) / (b * b) +

(col - cx) * (col - cx) / (a * a);

inFlag = (v <= 1);

}

}

if (shapeType == cstRect) { // 方框

inFlag =

(fabs(cx - startX) >= fabs(cx - col) && fabs(cy - startY) >=

fabs(cy - row));

}

if (shapeType == cstDiamond) { // 菱形

if (a > 0 && b > 0) {

if (zoomType == csdZoomOut) {

a *= 2;

b *= 2;

}

bool lr1 = (col < (((-a) * (1 - (row - cy) / (b))) + cx));

bool lr2 = (col < (((-a) * (1 - (row - cy) / (-b))) + cx));

bool lr3 = (col < (((a) * (1 - (row - cy) / (-b))) + cx));

bool lr4 = (col < (((a) * (1 - (row - cy) / (b))) + cx));

inFlag = (!lr1 && !lr2 && lr3 && lr4);

}

}

if (shapeType == cstPlus) { // 加号

inFlag =

(fabs(cx - startX) > fabs(cx - col) || fabs(cy - startY) >

fabs(cy - row));

}

*pDst++ = (inFlag != (zoomType == csdZoomOut) ? 0 : 255);

}

}

// ***************************** 形状效果 **************************************

// ***************************** 轮子效果 **************************************

__fastcall TCbwAnimationEffect_Wheel::TCbwAnimationEffect_Wheel()

: TCbwAnimationEffect() {

EffectType = cetWheel;

}

TCbwAnimationEffect * TCbwAnimationEffect_Wheel::Build() {

return new TCbwAnimationEffect_Wheel;

}

void __fastcall TCbwAnimationEffect_Wheel::BuildMaskMat(cv::Mat& destMat,

cv::Mat& srcMat, TRect displayRect) {

bool clockwiseFlag = (MyOptionType.Items[1].CurrentValue == 0); // 方向

int pattern = MyOptionType.Items[2].CurrentValue + 1; // 轮辐图案

if (pattern == 5)

pattern = 8;

TRect wholeRect(0, 0, displayRect.right - displayRect.left,

displayRect.bottom - displayRect.top);

double cx = wholeRect.right / 2.0, cy = wholeRect.bottom / 2.0;

TCbwFloatPoint centerPoint(cx, cy);

double unitDegree = 360 / pattern;

double deltaDegree = double(FCurrentIndex + 1) / FPeriodLength * unitDegree;

BYTE * pSrc = srcMat.data;

BYTE * pDst = destMat.data;

for (int row = 0; row < destMat.rows; ++row)

for (int col = 0; col < destMat.cols; ++col) {

TCbwFloatPoint p(col, row);

double theta = p.ThetaToPoint(centerPoint);

if (clockwiseFlag)

theta = 360 - theta;

bool inFlag = false;

for (int i = 0; i < pattern; ++i) {

if (theta >= unitDegree * i && (theta - unitDegree * i) <=

deltaDegree)

inFlag = true;

}

*pDst++ = inFlag ? 255 : 0;

}

}

// ***************************** 轮子效果 **************************************

// ***************************** 随机线效果 **************************************

__fastcall TCbwAnimationEffect_RandomLine::TCbwAnimationEffect_RandomLine()

: TCbwAnimationEffect() {

EffectType = cetRandomLine;

FOccurredLines = NULL;

}

TCbwAnimationEffect * TCbwAnimationEffect_RandomLine::Build() {

return new TCbwAnimationEffect_RandomLine;

}

void __fastcall TCbwAnimationEffect_RandomLine::BuildMaskMat(cv::Mat& destMat,

cv::Mat& srcMat, TRect displayRect) {

bool horzFlag = (MyOptionType.Items[1].CurrentValue == 0); // 方向

TRect wholeRect(0, 0, displayRect.right - displayRect.left,

displayRect.bottom - displayRect.top);

int totalLineNumber = (horzFlag ? wholeRect.bottom : wholeRect.right);

int number = double(FCurrentIndex + 1) / FPeriodLength * totalLineNumber;

if (!FOccurredLines) {

FOccurredLines = new BYTE[totalLineNumber];

ZeroMemory(FOccurredLines, totalLineNumber);

}

int destNumber =

number -int(double(FCurrentIndex) / FPeriodLength * totalLineNumber);

BYTE * pSrc = srcMat.data;

BYTE * pDst = destMat.data;

vector<int>totalLines;

for (int i = 0; i < totalLineNumber; ++i)

totalLines.push_back(i);

while (destNumber-- > 0 && totalLines.size()) {

int n = random(totalLines.size());

while (FOccurredLines[totalLines[n]]) {

totalLines.erase(totalLines.begin() + n);

n = random(totalLines.size());

}

FOccurredLines[totalLines[n]] = 1;

totalLines.erase(totalLines.begin() + n);

}

for (int row = 0; row < destMat.rows; ++row)

for (int col = 0; col < destMat.cols; ++col) {

bool inFlag = (horzFlag ? FOccurredLines[row] :

FOccurredLines[col]);

*pDst++ = inFlag ? 255 : 0;

}

if (FCurrentIndex == FPeriodLength - 1) {

delete FOccurredLines;

FOccurredLines = NULL;

}

}

// ***************************** 随机线效果 **************************************

// ***************************** 翻转式由远及近效果 **************************************

__fastcall TCbwAnimationEffect_RotateToNear::TCbwAnimationEffect_RotateToNear()

: TCbwAnimationEffect_SameMask() {

EffectType = cetRotateToNear;

}

TCbwAnimationEffect * TCbwAnimationEffect_RotateToNear::Build() {

return new TCbwAnimationEffect_RotateToNear;

}

void __fastcall TCbwAnimationEffect_RotateToNear::BuildDisplayMat

(cv::Mat& destMat, cv::Mat& srcMat, TRect displayRect) {

bool clockwiseFlag = (MyOptionType.Items[1].CurrentValue == 0); // 顺时针

cv::Point2f center = cv::Point2f(srcMat.cols / 2, srcMat.rows / 2); // 旋转中心

double angle = -45 * (1-double(FCurrentIndex + 1) / FPeriodLength); // 旋转角度

if (clockwiseFlag)

angle *= -1;

double scale = 0.5 * (1+double(FCurrentIndex + 1) / FPeriodLength); // 缩放尺度

cv::Mat rotateMat = cv::getRotationMatrix2D(center, angle, scale);

cv::warpAffine(srcMat, destMat, rotateMat, srcMat.size());

}

// ***************************** 翻转式由远及近效果 **************************************

// ***************************** 缩放效果 **************************************

__fastcall TCbwAnimationEffect_Zoom::TCbwAnimationEffect_Zoom()

: TCbwAnimationEffect_SameMask() {

EffectType = cetZoomEffect;

}

TCbwAnimationEffect * TCbwAnimationEffect_Zoom::Build() {

return new TCbwAnimationEffect_Zoom;

}

void __fastcall TCbwAnimationEffect_Zoom::BuildDisplayMat(cv::Mat& destMat,

cv::Mat& srcMat, TRect displayRect) {

bool clockwiseFlag = (MyOptionType.Items[1].CurrentValue == 0); // 顺时针

cv::Point2f center = cv::Point2f(srcMat.cols / 2, srcMat.rows / 2); // 旋转中心

double scale = 0.5 * (1+double(FCurrentIndex + 1) / FPeriodLength); // 缩放尺度

cv::Mat rotateMat = cv::getRotationMatrix2D(center, 0, scale);

cv::warpAffine(srcMat, destMat, rotateMat, srcMat.size());

}

// ***************************** 缩放效果 **************************************

// ***************************** 旋转效果 **************************************

__fastcall TCbwAnimationEffect_Rotate::TCbwAnimationEffect_Rotate()

: TCbwAnimationEffect_SameMask() {

EffectType = cetRotateEffect;

}

TCbwAnimationEffect * TCbwAnimationEffect_Rotate::Build() {

return new TCbwAnimationEffect_Rotate;

}

void __fastcall TCbwAnimationEffect_Rotate::BuildDisplayMat(cv::Mat& destMat,

cv::Mat& srcMat, TRect displayRect) {

bool horzFlag = (MyOptionType.Items[1].CurrentValue == 0); // 方向

double periodLength = FPeriodLength / 2.0;

double value = (FCurrentIndex + 1) / periodLength;

int segment = value;

value -= int(value);

double scale = fabs(value - 0.5) * 2;

int cols = srcMat.cols * scale, rows = srcMat.rows;

if (!horzFlag) {

cols = srcMat.cols;

rows = srcMat.rows * scale;

}

if (cols == 0 || rows == 0)

return;

cv::Mat partMat = destMat(cv::Rect((destMat.cols - cols) / 2,

(destMat.rows - rows) / 2, cols, rows));

cv::Size dsize = cv::Size(cols, rows);

resize(srcMat, partMat, dsize);

if (value > 0.5 != (segment % 2))

flip(partMat, partMat, horzFlag ? 1 : 0);

}

// ***************************** 旋转效果 **************************************

// ***************************** 弹跳效果 **************************************

__fastcall TCbwAnimationEffect_Bounce::TCbwAnimationEffect_Bounce()

: TCbwAnimationEffect() {

EffectType = cetBounce;

}

TCbwAnimationEffect * TCbwAnimationEffect_Bounce::Build() {

return new TCbwAnimationEffect_Bounce;

}

TRect __fastcall TCbwAnimationEffect_Bounce::BuildDisplayRect(OBJECTMAT * m) {

double x = double(FCurrentIndex + 1) / FPeriodLength;

double v = sin((x - 1) * 3 * PI);

double y = fabs(200 * v / exp(0.3 * (x - 1)));

y = m->LeftTopPosition.y - y;

x = m->LeftTopPosition.x + (x - 1) * 500;

TRect result(x, y, x + m->Mat.cols, y + m->Mat.rows);

return result;

}

// ***************************** 弹跳效果 **************************************

配置:

图标

实现完成后,发现弹跳的效果没有达到预期。

先解决有问题,先完成,再完善。

本周按计划完成PPT动画效果框架设计与实现。年也过完了,下周把电子黑板的功能更上一层楼。

时间: 2024-10-10 20:54:36

风火轮 –动画效果:擦除、形状、轮子、随机线条、翻转远近、缩放、旋转、弹跳效果的相关文章

风火轮 – 动画效果

风火轮越来越有广告范,之前实现的素材导入功能已能解决50%的用户需求,即可以拖入现成的动画.视频及图片素材,效果见QQ空间之前的某篇日志. 从进化发展角度来看,现在的很多产品,纯硬件的竞争已是薄利见血,软件功能提升才是王道. 所以,软件实现得加强.电子黑板如此,风火轮也如此. 准备实现动画效果. 闭门造车是白手起家的最脑残做法,所以先放眼成熟产品,看哪些功能与UI可以借鉴. 做素材,一般会选取FLASH.Photoshop,而动画效果,PPT是大家耳熟能详的. 仔细研究一下,决定采用PPT的界面

动画animation的三个应用(漂浮的白云、旋转的星球、正方体合成)

× 目录 [1]漂浮的白云 [2]旋转的星球 [3]正方体合成 前面的话 前面介绍过动画animation的详细用法,本文主要介绍动画animation的三个效果 漂浮的白云 [效果演示] [简要介绍] 漂浮的白云主要通过远景白云和近景白云来实现立体漂浮效果.远景和近景分别使用两张背景图片,通过改变其背景定位来实现白云移动效果,通过设置不同的动画持续时间来实现交错漂浮的效果 [主要代码] .box{ position: relative; height: 300px; width: 500px;

炫酷CSS3鼠标hover图片缩放和标题效果

这是一款使用纯CSS3制作的效果非常炫酷的鼠标滑过图片缩放和标题效果.该CSS3图片效果中图片的边框被制作为不停动画的护栏效果,当用鼠标滑过图片时,图片会有非常炫酷的动画效果. CSS3 animations是一个非常神奇的技术,相比于javascript和flash,它只用少量的代码就可以制作出平滑的动画效果.现在,所有的现代浏览器,包括IE9都支持CSS3 transitions 和 animations. 在线演示:http://www.htmleaf.com/Demo/201502081

PS制作光束散射的旋转文字效果

下面就来介绍一下制作步骤(#^.^#) 1.新建一画布,背景用蓝色渐变.方向根据光束的照射来定. 2.用图形工具的路径画一个圆,然后添加文字.调整其间距和文字大小. 3.栅格化文字,并且复制一层.然后滤镜?模糊?动感模糊,可以重复两次,使其光线颜色加深. 3-1.角度要90度,不然就是横向的了. 3-2.给光线图层添加蒙板,在蒙板上加渐变, 让光线渐隐一下,ctrl+t后按住ctrl+shift+鼠标左键调整光线. 4.接着对文字图层也执行ctrl+t自由变换处理,把文字处理成旋转的效果,并把其

基于jQuery图片缩放tab切换效果

基于jQuery图片缩放tab切换效果 上图: 主要效果是一个切换的效果,鼠标移动进行效果切换,兼容IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗等 预览地址:http://www.qhttl.com/content/view/2014/07/23/jiaoben92/jiaoben92/index.html 基于jQuery图片缩放tab切换效果

闹钟AlarmAndMusic 滑动调整时间和页面旋转风车效果《IT蓝豹》

闹钟AlarmAndMusic 滑动调整时间和页面旋转风车效果 闹钟AlarmAndMusic 和支持播放音乐效果的,上下滑动调整时间和页面旋转风车效果,由于制作的gif有些问题,效果不明显,欢迎下载使用看看真实的效果.本例子主要由AlertActivity和AlarmService和AlarmAlertWakeLock三个类完成.AlarmAlertWakeLock主要代码:public class AlarmAlertWakeLock {    private static PowerMan

图片旋转切换效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

[转载]双线性插值算法进行图像缩放及性能效果优化

原文地址:双线性插值算法进行图像缩放及性能效果优化 一)转自http://handspeaker.iteye.com/blog/1545126 最近在编程时用到了双线性插值算法,对图像进行缩放.网上有很多这方面的资料,介绍的也算明白.但是,这些文章只介绍了算法,并没有具体说怎么实现以及怎么实现最好,举个例子,你可以按照网上文章的算法自己写一个双线性插值程序,用它对一张图片进行处理,然后再用matlab或者openCV的resize函数对同一张图片进行处理,得到的结果是不一样的,如果源图片较小,效

风火轮 –动画效果:浮入与劈裂

今天花了一个半小时,实现两个动画效果:浮入与劈裂. 浮入效果 头文件 enum CbwFloatDirection { // 浮入方向 cfdUp = 0, // 上浮 cfdDown = 1 // 下浮 }; /** * @class TCbwAnimationEffect_ FloatIn * @brief 动画基类 * * 处理浮入动画效果 * @author 陈斌文 * @version 1.0 * @date 2015-03-05 * @QQ: 282397369 */ class T