public void BeginRender(float width, float height) { _canvas = (HtmlCanvasElement) document.createElement("canvas"); _canvas.width = (int) width; _canvas.height = (int) height; _canvas.style.width = width + "px"; _canvas.style.height = height + "px"; _context = (CanvasRenderingContext2D)_canvas.getContext("2d"); _context.textBaseline = "top"; }
private static void CreateCanvasElement() { var canvas = new HtmlCanvasElement { id = "canvas2D" }; canvas.style.width = new JsString("100%"); canvas.style.height = new JsString("100%"); HtmlContext.document.body.appendChild(canvas); _canvasRenderingContext2D = canvas.As<HtmlCanvasElement>().getContext("2d").As<CanvasRenderingContext2D>(); }
/// <summary> /// Draws the display object into the specified context ignoring it's visible, alpha, shadow, and transform. /// Returns true if the draw was handled (useful for overriding functionality). /// NOTE: This method is mainly for internal use, though it may be useful for advanced uses. /// </summary> /// <param name="ctx">The canvas 2D context object to draw into.</param> /// <param name="ignoreCache">Indicates whether the draw operation should ignore any current cache. /// For example, used for drawing the cache (to prevent it from simply drawing an existing cache back into itself).</param> public void draw(CanvasRenderingContext2D ctx, bool ignoreCache) { }
/// <summary> /// Draws the display object into the specified context ignoring it's visible, alpha, shadow, and transform. /// Returns true if the draw was handled (useful for overriding functionality). /// NOTE: This method is mainly for internal use, though it may be useful for advanced uses. /// </summary> /// <param name="ctx">The canvas 2D context object to draw into.</param> /// <param name="ignoreCache">Indicates whether the draw operation should ignore any current cache. /// For example, used for drawing the cache (to prevent it from simply drawing an existing cache back into itself).</param> public bool draw(CanvasRenderingContext2D ctx, bool ignoreCache) { return false; }
/// <summary> /// Draws only the path described for this Graphics instance, skipping any non-path instructions, including fill and stroke descriptions. /// Used by DisplayObject.clippingPath to draw the clipping path, for example. /// </summary> /// <param name="ctx">The canvas 2D context object to draw into.</param> public void drawAsPath(CanvasRenderingContext2D ctx) { }
/// <summary> /// Applies this display object's transformation, alpha, globalCompositeOperation, clipping path (mask), and shadow to the specified context. /// This is typically called prior to draw. /// </summary> /// <param name="ctx">The canvas 2D to update.</param> public void setupContext(CanvasRenderingContext2D ctx) { }
public void render(Scene scene, CanvasRenderingContext2D ctx, double screenWidth, double screenHeight) { this.screenWidth = screenWidth; this.screenHeight = screenHeight; for (var y = 0; y < screenHeight; y++) { for (var x = 0; x < screenWidth; x++) { var color = this.traceRay( new Ray(scene.camera.pos, getPoint(x, y, scene.camera)), scene, 0); var c = Color.toDrawingColor(color); ctx.fillStyle = "rgb(" + c.r + ", " + c.g + ", " + c.b + ")"; ctx.fillRect(x, y, x + 1, y + 1); } } }