private void CreateCircleGeometry(RenderContext renderContext) { CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Scale(1, Width / Height); ctx.Translate(X, Y); ctx.Rotate(RotationAngle * RC); ctx.BeginPath(); ctx.Arc(0, 0, Width, 0, Math.PI * 2, false); ctx.ClosePath(); ctx.LineWidth = 0; ctx.FillStyle = Color.ToString(); ctx.Alpha = Opacity; ctx.Fill(); ctx.Restore(); }
public override void Draw(RenderContext renderContext) { double rad = radius; if (skyRelative) { rad /= renderContext.FovScale / 3600; } Vector3d screenSpacePnt = renderContext.WVP.Transform(center); if (screenSpacePnt.Z < 0) { return; } if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, (Vector3d)center) < .55) { return; } if (renderContext.gl != null) { //todo draw in WebGL } else { CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Alpha = Opacity; ctx.BeginPath(); ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true); ctx.LineWidth = strokeWidth; ctx.FillStyle = fillColor.ToString(); if (fill) { ctx.Fill(); } ctx.Alpha = 1.0; ctx.StrokeStyle = lineColor.ToString(); ctx.Stroke(); ctx.Restore(); } }
private void CreateDonutGeometry(RenderContext renderContext) { //todo move to dashed lines in future CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Translate(X, Y); ctx.Scale(1, Height / Width); ctx.Rotate(RotationAngle * RC); ctx.BeginPath(); ctx.Arc(0, 0, Width / 2, 0, Math.PI * 2, false); ctx.ClosePath(); ctx.LineWidth = 9; ctx.StrokeStyle = Color.ToString(); ctx.Alpha = Opacity; ctx.Stroke(); ctx.Restore(); }
public void Draw(RenderContext renderContext, float opacity, bool cull) { InitBuffer(renderContext); if (renderContext.gl == null) { if (!imageReady) { return; } renderContext.Device.Save(); renderContext.WVP.ProjectArrayToScreen(worldList, transformedList); CanvasContext2D ctx = renderContext.Device; ctx.Alpha = .4; double width = renderContext.Width; double height = renderContext.Height; Vector3d viewPoint = Vector3d.MakeCopy(renderContext.ViewPoint); double scaleFactor = renderContext.FovScale / 100; foreach (DataItem item in items) { // todo filter by date // if (Vector3d.Dot(viewPoint, item.Location) < 0) if (item.Tranformed.Z < 1) { double x = item.Tranformed.X; double y = item.Tranformed.Y; double size = .1 * item.Size / scaleFactor; double half = size / 2; if (x > -half && x < width + half && y > -half && y < height + half) { //ctx.DrawImage(starProfile, x - size / 2, y - size / 2, size, size); ctx.BeginPath(); // ctx.FillStyle = "rgb(200,0,0)"; ctx.FillStyle = item.Color.ToFormat(); ctx.Arc(x, y, size, 0, Math.PI * 2, true); ctx.Fill(); } } } renderContext.Device.Restore(); } else { Vector3d zero = new Vector3d(); Matrix3d matInv = Matrix3d.MultiplyMatrix(renderContext.World, renderContext.View); matInv.Invert(); Vector3d cam = Vector3d.TransformCoordinate(zero, matInv); foreach (TimeSeriesPointVertexBuffer pointBuffer in pointBuffers) { TimeSeriesPointSpriteShader.Use( renderContext, pointBuffer.VertexBuffer, starTexture.Texture2d, Color.FromArgb(255 * opacity, 255, 255, 255), DepthBuffered, (float)(this.JNow), this.TimeSeries ? (float)Decay : 0, cam, (float)(scale * (renderContext.Height / 960)), MinSize, ShowFarSide, Sky ); renderContext.gl.drawArrays(GL.POINTS, 0, pointBuffer.Count); } // renderContext.gl.disable(0x8642); } }
public override void Draw(RenderContext renderContext) { bool onScreen = true; double rad = radius; if (skyRelative) { rad /= renderContext.FovScale / 3600; } Vector3d screenSpacePnt = renderContext.WVP.Transform(center); if (screenSpacePnt.Z < 0) { onScreen = false; } if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, center) < .55) { onScreen = false; } if (renderContext.gl != null) { if (Annotation.BatchDirty || AnnotationDirty) { Vector3d up = Vector3d.Create(0, 1, 0); Vector3d xNormal = Vector3d.Cross(center, up); Vector3d yNormal = Vector3d.Cross(center, xNormal); double r = radius / 44; int segments = 72; double radiansPerSegment = Math.PI * 2 / segments; List <Vector3d> vertexList = new List <Vector3d>(); for (int j = 0; j <= segments; j++) { double x = Math.Cos(j * radiansPerSegment) * r; double y = Math.Sin(j * radiansPerSegment) * r; vertexList.Add(Vector3d.Create(center.X + x * xNormal.X + y * yNormal.X, center.Y + x * xNormal.Y + y * yNormal.Y, center.Z + x * xNormal.Z + y * yNormal.Z)); } if (strokeWidth > 0 && vertexList.Count > 1) { for (int i = 0; i < (vertexList.Count - 1); i++) { LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1)); } LineList.AddLine(vertexList[vertexList.Count - 1], vertexList[0], lineColor, new Dates(0, 1)); } if (fill) { List <int> indexes = Tessellator.TesselateSimplePoly(vertexList); for (int i = 0; i < indexes.Count; i += 3) { TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2); } } AnnotationDirty = false; } } else { if (onScreen) { CanvasContext2D ctx = renderContext.Device; ctx.Save(); ctx.Alpha = Opacity; ctx.BeginPath(); ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true); ctx.LineWidth = strokeWidth; ctx.FillStyle = fillColor.ToString(); if (fill) { ctx.Fill(); } ctx.Alpha = 1.0; ctx.StrokeStyle = lineColor.ToString(); ctx.Stroke(); ctx.Restore(); } } }
public void Draw() { CanvasElement canvas = Document.GetElementById <CanvasElement>("graph"); CanvasContext2D ctx = (CanvasContext2D)canvas.GetContext(Rendering.Render2D); if (image != null) { image.DrawHistogram(ctx); } string red = "rgba(255,0,0,255)"; string green = "rgba(0,255,0,255)"; string blue = "rgba(0,0,255,255)"; ctx.StrokeStyle = red; ctx.BeginPath(); ctx.MoveTo(lowPosition, 0); ctx.LineTo(lowPosition, 150); ctx.Stroke(); ctx.StrokeStyle = green; ctx.BeginPath(); ctx.MoveTo(highPosition, 0); ctx.LineTo(highPosition, 150); ctx.Stroke(); ctx.StrokeStyle = blue; ctx.BeginPath(); ctx.Arc(center, 75, 10, 0, Math.PI * 2, false); ctx.ClosePath(); ctx.Stroke(); List <Vector2d> Curve = new List <Vector2d>(); //todo get from combo box switch (SelectedCurveStyle) { case 0: // Linear { Curve.Clear(); Curve.Add(Vector2d.Create(lowPosition, 150)); Curve.Add(Vector2d.Create(highPosition, 0)); break; } case 1: // Log { Curve.Clear(); double factor = 150 / Math.Log(255); double diff = (highPosition - lowPosition); int jump = diff < 0 ? -1 : 1; double step = Math.Abs(256.0 / (diff == 0 ? .000001 : diff)); double val = .000001; for (int i = lowPosition; i != highPosition; i += jump) { Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Log(val) * factor)))); val += step; } } break; case 2: // Power 2 { Curve.Clear(); double factor = 150 / Math.Pow(255, 2); double diff = (highPosition - lowPosition); int jump = diff < 0 ? -1 : 1; double step = Math.Abs(256.0 / (diff == 0 ? .000001 : diff)); double val = .000001; for (int i = lowPosition; i != highPosition; i += jump) { Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Pow(val, 2) * factor)))); val += step; } } break; case 3: // Square Root { Curve.Clear(); double factor = 150 / Math.Sqrt(255); double diff = (highPosition - lowPosition); int jump = diff < 0 ? -1 : 1; double step = Math.Abs(256.0 / (diff == 0 ? .000001 : diff)); double val = .000001; for (int i = lowPosition; i != highPosition; i += jump) { Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Sqrt(val) * factor)))); val += step; } } break; } if (Curve.Count > 1) { ctx.BeginPath(); ctx.StrokeStyle = blue; ctx.MoveTo(Curve[0].X, Curve[0].Y); for (int i = 1; i < Curve.Count; i++) { ctx.LineTo(Curve[i].X, Curve[i].Y); } ctx.Stroke(); } }