在 c++ 中使用递归放大和缩小图片 (sfml)
Zooming in and out a picture (sfml) using recursion in c++
使用以下代码,我将添加一个递归函数,而无需更改代码中的任何内容以使其工作:
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), TITLE);
int stop = 800;
sf::Color colour1(sf::Color::Black), colour2(sf::Color::Red);
// Start the main loop
while (window.isOpen()) {
// Process events
sf::Event event;
while (window.pollEvent(event)) {
// check the type of the event...
switch (event.type) {
// window closed
case sf::Event::Closed:
window.close();
break;
case sf::Event::MouseMoved: //mouse moved
stop = mapXtoMinSize(event.mouseMove.x); // convert x coordinate of mouse to minimum size of square to draw
break;
// we don't process other types of events
default:
break;
} //end switch
} //End-Process events
window.clear(colour2);
}
我只是想知道如何去做。
递
归函数通常是这样的:
int recursive(int x) {
if (x == 0) {
return 0;
} else {
return (x + recursive(x - 1));
}
}
这将对从 0 到 x 的所有整数求和,方法是重复调用自身来计算(x - 1)
的总和并将其添加到结果中。如果遇到基本情况 x == 0
,则递归结束,调用展开,直到它们到达原始状态,此时总和已计算完毕。请更具体。
在不知道你想用递归函数实现什么的情况下,我不能给你更多的建议。我不知道你评论"不更改代码中的任何内容"是什么意思。
相关文章:
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- SFML纹理像播放器
- 如何使用AngelScript注册SFML Vector2运算符
- 如何修复sfml c++代码编译错误
- SFML library: http request
- 落砂模拟碰撞检测C++和SFML
- 我无法缩小此分段错误的原因
- 使用 SFML 和 C++ 将 Pixel 打印到屏幕上
- 将stl字符串缩小到小于15个字符的容量
- OpenGL 和 GLM 矩阵无法正确扩展,总是按比例缩小
- SFML RenderWindow打开窗口需要很长时间
- 矢量下标超出SFML游戏中的范围
- 获取 SFML 窗口的 HWND 和高可用性?
- 将 Vulkan 与 SFML 结合使用?
- SFML 文本未绘制在窗口上
- SFML 碰撞永远不会在我的系统中注册
- 使用对象数组对 SFML 进行动画处理
- (SFML)按下键时,播放器构造函数未使用正确的动画进行更新
- 如何使用 SFML 在贪吃蛇游戏中定义游戏结束?
- 在 c++ 中使用递归放大和缩小图片 (sfml)