当前位置: 首页>>代码示例>>C++>>正文


C++ randFloat函数代码示例

本文整理汇总了C++中randFloat函数的典型用法代码示例。如果您正苦于以下问题:C++ randFloat函数的具体用法?C++ randFloat怎么用?C++ randFloat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了randFloat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: randFloat

void TestCanvas::testCubicBezier(GiCanvas* canvas)
{
    for (int i = 0; i < 100; i++) {
        canvas->beginPath();
        
        float x1 = randFloat(10.f, 600.f);
        float y1 = randFloat(10.f, 600.f);
        float x2 = x1 + randFloat(-50.f, 50.f);
        float y2 = y1 + randFloat(-50.f, 50.f);
        float x3 = x2 + randFloat(-50.f, 50.f);
        float y3 = y2 + randFloat(-50.f, 50.f);
        float x4 = x3 + randFloat(-50.f, 50.f);
        float y4 = y3 + randFloat(-50.f, 50.f);
        
        canvas->moveTo(x1, y1);
        
        for (int j = randInt(1, 10); j > 0; j--) {
            canvas->bezierTo(x2, y2, x3, y3, x4, y4);
            
            x1 = x2; y1 = y2;
            x2 = 2 * x4 - x3;
            y2 = 2 * y4 - y3;
            x3 = 4 * (x4 - x3) + x1;
            y3 = 4 * (y4 - y3) + y1;
            x4 = x3 + randFloat(-50.f, 50.f);
            y4 = y3 + randFloat(-50.f, 50.f);
        }
        
        canvas->setPen(0xFF000000 | randInt(0, 0xFFFFFF), -1.f, -1);
        canvas->drawPath(true, false);
    }
}
开发者ID:huangzongwu,项目名称:vglite,代码行数:32,代码来源:testcanvas.cpp

示例2: vec

glm::vec3 QuaternionDemo::randomUnitVector()
{
    glm::vec3 vec(randFloat() - 0.5f,
            randFloat() - 0.5f,
            randFloat() - 0.5f);
    return glm::normalize(vec);
}
开发者ID:filkry,项目名称:quaternion_demo,代码行数:7,代码来源:quaternion_demo.cpp

示例3: drawBomb

void drawBomb(void* ptr){
    Bomb *b = ptr;
    glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

    if(b->isDeleted || b->cnt > 100){
        b->isDeleted = 1;
        return;
    }
    float rate = 1.0f - (float)b->cnt / 100.0f;

    glEnableClientState(GL_VERTEX_ARRAY);

    for(int i = 0; i < FIRES; i++){
        GLfloat point[] = {
            b->fires[i].x, b->fires[i].y, b->fires[i].z
        };
        glColor4f(
                  randFloat() * rate, 
                  randFloat() * rate, 
                  randFloat() * rate, 
                  1.0f // 
                  );
        glVertexPointer(3, GL_FLOAT, 0, point);
        glDrawArrays(GL_POINTS, 0, 1);
    }
}
开发者ID:hiratara,项目名称:danmakuiphone,代码行数:26,代码来源:cube.c

示例4: train_test

static void train_test( void ) {
    float hiddenWeights[2][3] = {{0, 0, 0}, {0, 0, 0}};
    float outputWeights[1][3] = {{0, 0, 0}};
    Node inputNodes[2] = {{NULL, randFloat() * 2 -1}, {NULL, randFloat() * 2 - 1}};
    Node hiddenNodes[2] = {{hiddenWeights[0]}, {hiddenWeights[1]}};
    Node outputNodes[1] = {{outputWeights[0]}};
    Node desiredOutputNodes[1] = {{NULL, randFloat() - 0.5}};
    Layer inputLayer = {inputNodes, 2};
    Layer hiddenLayer = {hiddenNodes, 2};
    Layer outputLayer = {outputNodes, 1};
    Layer desiredOutputLayer = {desiredOutputNodes, 1};
    TestCase testCase = {&inputLayer, &desiredOutputLayer};

    int i, j;
    for( i = 0; i < 1000; ++i ) {
        j = 0;
        desiredOutputNodes[0].output = randFloat() - 0.5;
        while( fabs( outputLayer.nodes[0].output - desiredOutputNodes[0].output ) > 0.01 ) {
            train( &testCase, &hiddenLayer, &outputLayer );
            if( j++ > 1000 ) {
                printf( "Converged %d sets so far.\n", i -1 );
                printf( "Desired Output: %f, Current Output: %f\n", desiredOutputNodes[0].output, outputLayer.nodes[0].output );
                assert ( 1 == 0 && "Did not converge in a timely manner" );
            }
        }
    }
}
开发者ID:chessami92,项目名称:ceen4920-backpropagation,代码行数:27,代码来源:backprop_test.c

示例5: randIntInRange

void Endpoint::sendDatagram(const QByteArray& datagram) {
    datagramsSent++;
    
    // some datagrams are dropped
    const float DROP_PROBABILITY = 0.1f;
    if (randFloat() < DROP_PROBABILITY) {
        return;
    }
    
    // some are received out of order
    const float REORDER_PROBABILITY = 0.1f;
    if (randFloat() < REORDER_PROBABILITY) {
        const int MIN_DELAY = 1;
        const int MAX_DELAY = 5;
        // have to copy the datagram; the one we're passed is a reference to a shared buffer
        _delayedDatagrams.append(QPair<QByteArray, int>(QByteArray(datagram.constData(), datagram.size()),
            randIntInRange(MIN_DELAY, MAX_DELAY)));
        
        // and some are duplicated
        const float DUPLICATE_PROBABILITY = 0.01f;
        if (randFloat() > DUPLICATE_PROBABILITY) {
            return;
        }
    }
    
    _other->_sequencer->receivedDatagram(datagram);
    datagramsReceived++;
}
开发者ID:dv8eve,项目名称:hifi,代码行数:28,代码来源:MetavoxelTests.cpp

示例6: randFloat

void ParticlePool::missileTrail(const Position &pos, float radius)
{
	radius *= 0.5;
	float entspeed = pos.getVelocityMagnitude();
	
	for (int i = 0; i < 6; i++)
	{
		float randAngle   = randFloat(M_PI-M_PI/60, M_PI+M_PI/60);
		float speed		  = randFloat(1000.0, 1700.0);
		float offset_time = randFloat(0, getDt()) * (entspeed-speed);
		
		float spawnX	= pos.getX() - (radius + offset_time) * -cos(pos.getR() + M_PI);
		float spawnY	= pos.getY() - (radius + offset_time) *  sin(pos.getR() + M_PI);
		float spawnVelX = speed * ( cos(pos.getR() + randAngle)) + pos.getX_vel();
		float spawnVelY = speed * (-sin(pos.getR() + randAngle)) + pos.getY_vel();

		Position spawnPos = Position(spawnX, spawnY);
		spawnPos.setX_vel(spawnVelX);
		spawnPos.setY_vel(spawnVelY);

		Particle p = Particle(
                         255, 
                         randInt(64, 215), 
                         0, 
                         randInt(128,255), 
						 randFloat(0.16, 0.24), 
                         spawnPos, 
                         900);
		add(p);
	}
}
开发者ID:yixu34,项目名称:Mastrix,代码行数:31,代码来源:particlepool.cpp

示例7: colorFromString

Color colorFromString(string s)
{
	static Color s_cLastCol;
	Color c;
	
	if(s == "random_pastel")	//Some random pastel color (good for parasprites)
	{
		float h, s, v;
		h = randFloat(0.0, 360.0);
		s = randFloat(40.0, 100.0);
		v = 100.0;
		c = HsvToRgb(h,s,v);
		c.r /= 100;
		c.g /= 100;
		c.b /= 100;
		s_cLastCol = c;
		return c;
	}
	else if(s == "last")	//Last color we got from this function
		return s_cLastCol;
	
	s = stripCommas(s);

	//Now, parse
	istringstream iss(s);
	int r, g, b, a;
	if(iss >> r >> g >> b)
	{
		if(!(iss >> a))
			c.from256(r,g,b);
		else
			c.from256(r,g,b,a);
	}
开发者ID:meh2481,项目名称:pony48,代码行数:33,代码来源:globaldefs.cpp

示例8: randInt

void ParticlePool::explodeMineAt(const Position &source, float sourceRadius)
{
	int numParticles = randInt(300, 400);
	for (int i = 0; i < numParticles; i++)
	{
		float randAngle = randFloat(0.0f, M_PI * 2);
		float randDist  = randFloat(0, sourceRadius);
		float spawnX	= source.getX() + randDist * cos(randAngle);
		float spawnY	= source.getY() + randDist * sin(randAngle);
		float speed		= randFloat(-100.0f, 30.0f);
		float spawnVelX = speed * cos(randAngle);
		float spawnVelY = speed * sin(randAngle);

		Position spawnPos = Position(spawnX, spawnY);
		spawnPos.setX_vel(spawnVelX);
		spawnPos.setY_vel(spawnVelY);

		Particle p = Particle(
			255, randInt(100,200), 255,  randInt(170, 255),
			randFloat(0.5, 1.2),  
			spawnPos, 
			400);

		add(p);
	}
}
开发者ID:yixu34,项目名称:Mastrix,代码行数:26,代码来源:particlepool.cpp

示例9: while

void Crack::findStart() 
{
	// shift until crack is found
	bool bFound = false;
	int timeout = 0;
	uint px, py;
	while ((!bFound) || (timeout++>1000)) 
	{
		// pick random point
		px = randInt(0, m_image.width()-1);
		py = randInt(0, m_image.height()-1);

		if(m_cgrid[py*m_image.width() + px] < UNCRACKED)
			bFound=true;
	}
    
	if (bFound) 
	{
		// start crack
		int angle = m_cgrid[py*m_image.width() + px];
	
		if (randInt(0, 100) < 50)
			angle -= 90 + int(randFloat(-m_degreesFromPerpendicular, m_degreesFromPerpendicular));
		else
			angle += 90 + int(randFloat(-m_degreesFromPerpendicular, m_degreesFromPerpendicular));

		m_line.setLine(Point(px, py), angle, m_image.width(), m_image.height());
		m_pts = m_line.points();
		m_ptIndex = 0;

		startCrack();
	}
}
开发者ID:dparks1134,项目名称:Art,代码行数:33,代码来源:Crack.cpp

示例10: CHECK_STATUS_AND_RETURN_IF_FAIL

//----------------------------------------------------------------------------------------------------------------------
MStatus CustomSphere::redoIt()
{
    // loop for the number of arguments passed in and create some random spheres
    for( unsigned int i = 0; i < m_count; ++i )
    {
        // fist I'm going to create a maya command as follows
        // sphere -name "sphere[n]" where n is the value of i
        std::string cmd;
        float rad=randFloat(m_minRadius,m_maxRadius);
        cmd=boost::str(boost::format("sphere -name \"sphere%d\" -r %f") %i %rad)  ;
        // now execute the command
        MStatus status = MGlobal::executeCommand( cmd.c_str() );
        // and check that is was succesfull
        CHECK_STATUS_AND_RETURN_IF_FAIL(status,"Unable to execute sphere command");

        // now move to a random position first grab some positions
        float x=randFloat(-m_xExtent,m_xExtent);
        float y=randFloat(-m_yExtent,m_yExtent);
        float z=randFloat(-m_zExtent,m_zExtent);
        // build the command string
        // move x y z "sphere[n]"
        cmd=boost::str(boost::format("move %f %f %f \"sphere%d\"") %x %y %z %i)  ;
        // execute
        status=MGlobal::executeCommand(cmd.c_str());
        CHECK_STATUS_AND_RETURN_IF_FAIL(status,"unable to move object");

    }
    std::string mesg=boost::str(boost::format("%d Spheres created") %m_count)  ;
    MGlobal::displayInfo( mesg.c_str() );
    return MStatus::kSuccess;
}
开发者ID:Qaanaaq,项目名称:MayaAPICode,代码行数:32,代码来源:CustomSphere.cpp

示例11: randomizeScene

void randomizeScene(void)
{
	for (int i = 0; i < (int) randFloat(50,100); i++) { // 50 to 100 objects	
		float decideShape = randFloat(0, 1);
		if (decideShape < 0.7) { // 70% point
			makeVertex();
			finishedShapes.push_back(currentVertices);
			finishedShapes.back().type = GL_POINTS;
			clearCurrentVertex();
		}
		else if (decideShape > 0.9) { // 10% polygon
			for (int i = 0; i < (int)randFloat(3, 7); i++) { // 3 to 7 vertices in a polygon
				makeVertex();
			}
			finishedShapes.push_back(currentVertices);
			finishedShapes.back().type = GL_POLYGON;
			clearCurrentVertex();
		}
		else { // 20% line
			makeVertex();
			makeVertex();
			finishedShapes.push_back(currentVertices);
			finishedShapes.back().type = GL_LINES;
			clearCurrentVertex();
		}
	}
}
开发者ID:phamd,项目名称:OpenGL-Interactive-Screensaver,代码行数:27,代码来源:main.cpp

示例12: makeVertex

void makeVertex(void)
{
	currentVertex.position = Vector2d(randFloat(0, gWidth), randFloat(0, gHeight));
	currentVertex.direction = Vector2d(randFloat(-1, 1), randFloat(-1, 1));
	currentVertex.colour = getColour(gColour);
	currentVertices.push_back(currentVertex);
}
开发者ID:phamd,项目名称:OpenGL-Interactive-Screensaver,代码行数:7,代码来源:main.cpp

示例13: spawnTroops

static void spawnTroops( int side, int minCnt, int maxCnt )
{
	int numToSpawn = minCnt + ( rand( ) % ( maxCnt - minCnt ) );

	float baseX;
	if( introMode ) {
		baseX = 500.0f + randFloat( 200.0f, 480.0f ) * sign( randFloat( -1.0f, 1.0f ) );
	} else {
		baseX = randFloat( 20.0f, 980.0f );
	}
	float baseY = ( side == 0 ) ? 650.0f : -60.0f;

	Vector2 spawnPos;
	spawnPos.x = baseX;


	float stepX = ( baseX < 500.0f ) ? 25.0f : -25.0f;
	float signY = ( side == 0 ) ? 1.0f : -1.0f;
	while( numToSpawn > 0 ) {
		spawnPos.y = baseY + ( randFloat( 0.0f, 30.0f ) * signY );
		spawnTroop( spawnPos, side );
		spawnPos.x += stepX + randFloat( -10.0f, 10.0f );
		--numToSpawn;
	}
}
开发者ID:JesseRahikainen,项目名称:LD32_Ezrtel,代码行数:25,代码来源:gameScreen.c

示例14: vec2

Particle::Particle(vec2 l)
{
    location_ = l;
    lifespan_ = 1.0;
    acceleration_ = vec2(0,0.05);
    velocity_ = vec2(randFloat(-1,1), randFloat(-2,0));
}
开发者ID:jefarrell,项目名称:NatureOfCode_Cinder,代码行数:7,代码来源:Particle.cpp

示例15: randFloat

void TestCanvas::testCubicBezier(GiCanvas* canvas, int n)
{
    float x1 = randFloat(100.f, 400.f);
    float y1 = randFloat(100.f, 400.f);
    
    for (int i = 0; i < n; i++) {
        canvas->beginPath();
        
        float x2 = x1 + randFloat(-50.f, 50.f);
        float y2 = y1 + randFloat(-50.f, 50.f);
        float x3 = x2 + randFloat(-50.f, 50.f);
        float y3 = y2 + randFloat(-50.f, 50.f);
        float x4 = x3 + randFloat(-50.f, 50.f);
        float y4 = y3 + randFloat(-50.f, 50.f);
        
        canvas->moveTo(x1, y1);
        
        for (int j = randInt(1, 10); j > 0; j--) {
            canvas->bezierTo(x2, y2, x3, y3, x4, y4);
            
            x1 = x2; y1 = y2;                   // P2
            x2 = 2 * x4 - x3;                   // Q2=2P4-P3
            y2 = 2 * y4 - y3;
            x3 = 4 * (x4 - x3) + x1;            // Q3=4(P4-P3)+P2
            y3 = 4 * (y4 - y3) + y1;
            x4 = x3 + randFloat(-50.f, 50.f);
            y4 = y3 + randFloat(-50.f, 50.f);
        }
        
        if (s_randStyle) {
            canvas->setPen(0xFF000000 | randInt(0, 0xFFFFFF), -1.f, -1, 0);
        }
        canvas->drawPath(true, false);
    }
}
开发者ID:rhcad,项目名称:vglite,代码行数:35,代码来源:testcanvas.cpp


注:本文中的randFloat函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。