public void ApplyForceInRandomDirection(float strength, RandMT rand) { foreach (Fixture fixture in this.fixtures) { float angle = rand.UncheckedRandomRange(0.0f, Constants.TwoPi); Vector2 force = Vector2.FromAngle(angle) * strength; fixture.Body.ApplyForce(force.ToXna()); } }
public static void RandomMutaitons() { var bmp = new System.Drawing.Bitmap(FILE_IN); ImageSys img = new ImageSys(bmp); Texture txt = new Interpolent(img, Intpol.Nearest); var fitness = BuildFitness(txt); CPPN network = new CPPN(); VRandom rng = new RandMT(); network.Randomize(rng); Renderor ren = new Renderor(); ImageSys output = new ImageSys(256, 256); //img.BMP.Save(FILE_OUT + "test.png"); Console.WriteLine("Building Network..."); for (int i = 0; i < 200; i++) { network.Mutate(rng, 1.0); } Console.WriteLine("Aproximating Image: " + FILE_IN); //NOTE: Make it so we don't accept mutations that //result in NaN fitness! for (int i = 0; i < MAX_GEN; i++) { //network.Mutate(rng, 1.0); //0.1 network.Randomize(rng); ren.Render(network, output); string file = i.ToString("0000") + ".png"; output.BMP.Save(FILE_OUT + file); int nodes = network.NumNurons; int axons = network.NumAxons; double fit = fitness(network); //Console.WriteLine(); Console.WriteLine("Generation " + i + ": " + nodes + " " + axons + " " + fit); } }
public static void BuildData() { BuildFox(); if (data != null) { return; } data = new List <SubPixel>(foxpoints.Length * 5); var bmp = new System.Drawing.Bitmap(FILE_IN); ImageSys img = new ImageSys(bmp); Texture txt = new Interpolent(img, Intpol.Sinc3); VRandom rng = new RandMT(); double u, v; for (int i = 0; i < foxpoints.Length; i += 2) { double x = foxpoints[i]; double y = foxpoints[i + 1]; u = ((2.0 * x) - 256.0) / 256.0; v = ((2.0 * y) - 256.0) / 256.0; Color c = txt.Sample(u, -v); data.Add(new SubPixel(u, -v, c)); for (int j = 0; j < 4; j++) { double xp = x + rng.RandGauss() * 0.5; double yp = y + rng.RandGauss() * 0.5; u = ((2.0 * xp) - 256.0) / 256.0; v = ((2.0 * yp) - 256.0) / 256.0; Color cp = txt.Sample(u, -v); data.Add(new SubPixel(u, -v, cp)); } } bmp.Dispose(); }