续:一种让数值在指定范围内由小到大再变小的生成方法(固定时间内)
2013-09-20 02:29
411 查看
#include "stdafx.h" #include <windows.h> #include<time.h> #include <iostream> using namespace std; const static int TIME_PER_FRAME = 100; SYSTEMTIME sys; const static int TOTAL_TIME = 10000; const static int CHANGING_TIMES = 4; const static int RANGE = 80; const static int FRONT = 100; int GetCurTime() { GetLocalTime(&sys); return sys.wMinute * 60000 + sys.wSecond * 1000 + sys.wMilliseconds;//big enough for this test code } int main() { int startTime,endTime; int curPassedTime = 0; int changedTimes = 0; int curValue = 0; int TIME_START = GetCurTime(); while(curPassedTime < TOTAL_TIME) { startTime = GetCurTime(); curPassedTime = startTime - TIME_START; if(curPassedTime > (changedTimes + 1) * TOTAL_TIME / CHANGING_TIMES) changedTimes += 1; int seedTime = curPassedTime - changedTimes * TOTAL_TIME / CHANGING_TIMES; if(seedTime < TOTAL_TIME / (2 * CHANGING_TIMES)) curValue = FRONT - seedTime * 2 * RANGE / (TOTAL_TIME / CHANGING_TIMES); else curValue = FRONT - 2 * RANGE + seedTime * 2 * RANGE / (TOTAL_TIME / CHANGING_TIMES); cout<< curValue << endl; endTime = GetCurTime(); if(endTime - startTime < TIME_PER_FRAME) Sleep(TIME_PER_FRAME - (endTime - startTime));//fixed FPS } }
相关文章推荐
- 一种让数值在指定范围内由小到大再变小的生成方法
- JavaScript生成指定范围的时间列表
- Javascript 生成指定范围数值随机
- Javascript 生成指定范围数值随机数
- js中Math.random()生成指定范围数值的随机数
- Javascript 生成指定范围数值随机数(转)
- 在javascript中随机数 math random如何生成指定范围数值的随机数
- js中Math.random()生成指定范围数值的随机数
- [三卷天书]记一个asp.net生成两个日期范围内生成随机时间的方法
- 生成一组指定范围内随机数(取50个数字,100到200的随机数字) LINQ方法
- Javascript 生成指定范围数值随机数
- js中Math.random()生成指定范围数值的随机数
- js中Math.random()生成指定范围数值的随机数
- Javascript 生成指定范围数值随机数 By shawl.qiu
- Javascript 生成指定范围数值随机数
- 生成指定范围的时间列表
- Math生成指定范围内不重复的随机数方法
- JavaScript生成指定范围随机数和随机序列的方法
- 数据库生成指定范围内日期时间
- js中Math.random()生成指定范围数值的随机数