コード例 #1
0
ファイル: poly_mutator.cpp プロジェクト: wesulee/img_iter
/*
Generate a random simple polygon inside a rectangle
vert is number of vertices (>= 3)
width, height are dimensions of rectangle
spacing (0 - 1 inclusive) determines random spacing along circle
sharpness (0 - 1 inclusive) determines how spiky polygon will be
*/
Polygon poly_mutator::randSimplePoly(const float spacing, const float sharpness) {
	// get center of poly close to rectangle center with padding from edge
	const int cenX = static_cast<int>((width / 2) + (randNorm() * width / 3));
	const int cenY = static_cast<int>((height / 2) + (randNorm() * height / 3));
	// polygon vertices
	Polygon::Container v;
	v.reserve(vertCount);
	Point p;
	// begin generating vertices
	const float radInc = 2 * PI / vertCount;
	float rad = randUni() * 2 * PI;
	for (int vert = 0; vert < vertCount; ++vert, rad += radInc) {
		float radRand = rad + radInc * randNorm() / 2.1 * spacing;
		std::pair<float, float> intPoint = getPos(cenX, cenY, radRand, width, height);
		// vector from center to intersection
		float vx = intPoint.first - static_cast<float>(cenX);
		float vy = intPoint.second - static_cast<float>(cenY);
		// delta from center
		float vMult = randNorm();
		float dx = (vx / 2) * (1.0 + vMult * sharpness);
		float dy = (vy / 2) * (1.0 + vMult * sharpness);
		p.x = static_cast<int>(cenX + dx);
		p.y = static_cast<int>(cenY + dy);
		v.push_back(p);
	}
	return Polygon(v);
}
コード例 #2
0
ファイル: Vec3.cpp プロジェクト: bduvenhage/stitch-engine
//=======================================================================//
stitch::Vec3 stitch::Vec3::uniqueValue(uintptr_t key)
{
    std::map<uintptr_t, Vec3>::const_iterator iter=uniqueValueMap_.find(key);
    
    if (iter!=uniqueValueMap_.end())
    {
        return iter->second;
    } else
    {
        Vec3 newRandVec=randNorm();
        uniqueValueMap_[key]=newRandVec;
        return newRandVec;
    }
}