public static N8Level GetLevel() { N8Level Level = new N8Level(); Cylindrical c = new Cylindrical(500, 0, -1000); char[] bases = new char[] { 'a', 'c', 'g', 't' }; Random rand = new Random(); int max = Utilities.MAX_BLOCK_COUNT - 16; int BlocksPerRung = MakeRung(Level, c, bases[rand.Next(bases.Length)]); int NumRungs = max / BlocksPerRung; for (int i = 1; i < NumRungs; i++) { MakeRung(Level, c, bases[rand.Next(bases.Length)]); } Level = MinorModifiers.AddBorder(Level); return Level; }
public static IEnumerator<Point> RandomWalk(int InitThetaDegrees, int ThetaStepDegrees, int RStepMax, int RStepMin, Point init, Random r = null) { Random myRand = r ?? rand; Cylindrical C = new Cylindrical(); C.Theta_Degrees = InitThetaDegrees; Point current = init; while (true) { yield return current; int RStep = myRand.Next(RStepMin, RStepMax); C.R = RStep; int ThetaStep = myRand.Next(-ThetaStepDegrees / 2, ThetaStepDegrees / 2); C.Theta_Degrees += ThetaStep; Vector3D cartesian = C.ToCartesian(); current = new Point((int)cartesian.X + current.X, (int)cartesian.Y + current.Y); } }
private static int MakeRung(N8Level Level, Cylindrical current, char type) { int blockcount = 0; int tsteps = 5; int ttotal = 30; int rsteps = 7; double tstep = (ttotal * Utilities.DegToRad) / tsteps; double hstep = 30; bool runged = false; for (int i = 0; i < tsteps; i++) { string backbonecolor = "white"; if ((i >= tsteps / 2) && !runged) { backbonecolor = "black"; } current.Theta += tstep; current.H += hstep; N8Block Block1 = Level.blocks.GenerateBlock("megapixel" + backbonecolor, "Phosphate Deoxyribose Backbone"); blockcount++; N8Block Block2 = Level.blocks.GenerateBlock("megapixel" + backbonecolor, "Phosphate Deoxyribose Backbone"); blockcount++; Block1.position = current.ToCartesian(); Block1.rotation = current.GetNormalRotation(); current.R = -current.R; Block2.position = current.ToCartesian(); Block2.rotation = current.GetNormalRotation(); current.R = -current.R; //Halfway up the ladder, do the rung if ((i >= tsteps / 2) && !runged) { //T and C are slightly shorter than A and G, so we need to account for that. //colorA is the longer color, colorB is the shorter one; if direction is negative we flip which direction we go. string colorA; string colorB; string nameA; string nameB; int direction = 1; switch (type) { case ('a'): colorA = ADENINE_COLOR; colorB = THYMINE_COLOR; nameA = "Adenine"; nameB = "Thymine"; break; //Why can't you just let me fall through? case ('t'): colorA = ADENINE_COLOR; colorB = THYMINE_COLOR; nameA = "Adenine"; nameB = "Thymine"; direction = -1; break; case ('g'): colorA = GUANINE_COLOR; colorB = CYTOSINE_COLOR; nameA = "Guanine"; nameB = "Cytosine"; break; case ('c'): colorA = GUANINE_COLOR; colorB = CYTOSINE_COLOR; nameA = "Guanine"; nameB = "Cytosine"; direction = -1; break; default: colorA = ERRORA_COLOR; colorB = ERRORB_COLOR; nameA = "Errornine"; nameB = "Errorsine"; break; } double initR = current.R; current.R *= direction; double rstep = (2 * current.R) / (double)rsteps; int j; for (j = 0; j < (rsteps / 2) - 1; j++) { N8Block shortblock = Level.blocks.GenerateBlock("pixel" + colorB, nameB); blockcount++; current.R -= rstep; shortblock.position = current.ToCartesian(); shortblock.rotation = current.GetNormalRotation(); } for (; j < rsteps-1; j++) { N8Block longblock = Level.blocks.GenerateBlock("pixel" + colorA, nameA); blockcount++; current.R -= rstep; longblock.position = current.ToCartesian(); longblock.rotation = current.GetNormalRotation(); } current.R = initR; runged = true; } } return blockcount; }
/// <summary> /// Rotates an entire level. Currently doesn't do tronics. /// </summary> /// <param name="Input"></param> /// <param name="RotationDegrees"></param> /// <param name="axis"></param> /// <returns></returns> public static N8Level RotateLevel(N8Level Input, double RotationDegrees, Vector3D axis) { var LevelBlocks = Input.blocks.Blocks; axis.Normalize(); foreach (N8Block b in LevelBlocks) { Cylindrical c = new Cylindrical(b.position, axis); c.Theta += RotationDegrees * Utilities.DegToRad; b.position = c.ToCartesian(); b.rotation = b.rotation * new Quaternion(axis, RotationDegrees); } return Input; }