static void RenderRow (Bitmap canvas, int dotPeriod, int y) { if (y >= CANVAS_HEIGHT) return; if ((y % dotPeriod) == 0) System.Console.Write("*"); stopwatch.Restart(); for (int x = 0; x < CANVAS_WIDTH; x++) { Color c = RenderPixel(x, y); canvas.SetPixel(x, y, c); } //canvas.Refresh(); // added for make it work with Saltarelle var elapsed = stopwatch.ElapsedMilliseconds; double msPerPixel = (double)elapsed / CANVAS_WIDTH; totalTime+=elapsed; ReportSpeed(msPerPixel); SetTimeout(0, () => RenderRow(canvas, dotPeriod, y + 1) ); }
//static void Main(string[] args) { public static void Mainx() { // init structures objects = new List<RTObject>(); lights = new List<Light>(); random = new Random(01478650229); stopwatch = new Stopwatch(); speedSamples = new List<double>(); Bitmap canvas = new Bitmap(CANVAS_WIDTH, CANVAS_HEIGHT); // add some objects // in the original test it was 30 and not 300 for (int i = 0; i < 300; i++) { float x = (float)(random.NextDouble() * 10.0f) - 5.0f; // Range -5 to 5 float y = (float)(random.NextDouble() * 10.0f) - 5.0f; // Range -5 to 5 float z = (float)(random.NextDouble() * 10.0f); // Range 0 to 10 Color c = Color.FromArgb(255, random.Next(255), random.Next(255), random.Next(255)); Sphere s = new Sphere(new Vector3f(x, y, z), (float)(random.NextDouble()), c); objects.Add(s); } //Sphere debugSphere = new Sphere(new Vector3f(0, 0, 5.0f), 0.2f, Color.ForestGreen); //objects.Add(debugSphere); Plane floor = new Plane(new Vector3f(0, 1.0f, 0), -10.0f, Color.Aquamarine); objects.Add(floor); // add some lights lights.Add(new Light(new Vector3f(2.0f, 0.0f, 0))); lights.Add(new Light(new Vector3f(0, 10.0f, 7.5f))); // calculate width and height of a pixel in world space coords pixelWidth = (screenBottomRightPos.x - screenTopLeftPos.x) / CANVAS_WIDTH; pixelHeight = (screenTopLeftPos.y - screenBottomRightPos.y) / CANVAS_HEIGHT; // render it int dotPeriod = CANVAS_HEIGHT / 10; System.Console.WriteLine("Rendering...\n"); System.Console.WriteLine("|0%---100%|"); RenderRow(canvas, dotPeriod, 0); // save the pretties canvas.Save("output.png"); }