void ApplySierpenskiIterations() { float2 nextLocation; float2 nT; for (int i = 0; i < iterations; i++) { int rand = Random.Range_(0, 3); if (rand == 0) { nT = p1; } else if (rand == 1) { nT = p2; } else { nT = p3; } nextLocation = (currentLocation + nT) / 2f; colors[(((int)nextLocation.x) * yWidth + (int)nextLocation.y)] = Color.red; currentLocation = nextLocation; } }
void ApplyBarnsley() { float2 nextLocation; float2 scale = new float2(xWidth / 6f, yWidth / 10.1f); float2 offSet = new float2(xWidth / 2f, 0f); int2 paintCoord; nextLocation = currentLocation; for (int i = 0; i < iterations; i++) { int rand = Random.Range_(0, 100); if (rand < 1) { nextLocation.x = 0f; nextLocation.y = 0.16f * currentLocation.y; } else if (rand < 86) { nextLocation.x = 0.85f * currentLocation.x + 0.04f * currentLocation.y; nextLocation.y = -0.04f * currentLocation.x + 0.85f * currentLocation.y + 1.6f; } else if (rand < 93) { nextLocation.x = 0.2f * currentLocation.x + -0.26f * currentLocation.y; nextLocation.y = 0.23f * currentLocation.x + 0.22f * currentLocation.y + 1.6f; } else { nextLocation.x = -0.15f * currentLocation.x + 0.28f * currentLocation.y; nextLocation.y = 0.26f * currentLocation.x + 0.24f * currentLocation.y + 0.44f; } paintCoord.x = (int)((nextLocation.x * scale.x) + offSet.x); paintCoord.y = (int)((nextLocation.y * scale.y) + offSet.y); currentLocation = nextLocation; if (paintCoord.x >= xWidth || paintCoord.y >= yWidth || paintCoord.x < 0 || paintCoord.y < 0) { continue; } colors[paintCoord.y * xWidth + paintCoord.x] = Color.green; } }
private void Awake() { Random.Initialize(); Screen.fullScreen = false; }