public void DrawConnector(SKCanvas canvas, float _radX, float _radY) { float totalFlow = 0; float totalSpO2 = 0; float totalSpO2To = 0; float totalSpO2From = 0; float currentVolume = 0; float radius = 0; scale = _radX * scaleRelative; radius = _radX / 2.5f; if (_radX > _radY) { scale = _radY * scaleRelative; radius = _radY / 2.5f; } // calculate the total volume and average spO2 if lumping is the case foreach (BloodCompartmentConnector c in connectors) { totalFlow += (float)c.CurrentFlow * Speed; if (totalFlow >= 0) { totalSpO2 += (float)c.Comp1.TO2; if (NoLoss) { totalSpO2From += (float)c.Comp1.TO2; totalSpO2To += (float)c.Comp1.TO2; } else { totalSpO2From += (float)c.Comp1.TO2; totalSpO2To += (float)c.Comp2.TO2; } } else { totalSpO2 += (float)c.Comp2.TO2; if (NoLoss) { totalSpO2From += (float)c.Comp2.TO2; totalSpO2To += (float)c.Comp2.TO2; } else { totalSpO2From += (float)c.Comp2.TO2; totalSpO2To += (float)c.Comp1.TO2; } } } colorTo = AnimatedElementHelper.CalculateBloodColor(totalSpO2To / connectors.Count); colorFrom = AnimatedElementHelper.CalculateBloodColor(totalSpO2From / connectors.Count); currentAngle += totalFlow * Direction; if (Math.Abs(currentAngle) > Math.Abs(StartAngle - EndAngle)) { currentAngle = 0; } if (sizeCompartment != null) { currentVolume = (float)sizeCompartment.VolCurrent; circleOut.StrokeWidth = AnimatedElementHelper.RadiusCalculator(currentVolume, scale); } else { circleOut.StrokeWidth = 22; } // calculate position locationOrigen = AnimatedElementHelper.GetPosition(StartAngle, radius, RadiusXOffset, RadiusYOffset); locationTarget = AnimatedElementHelper.GetPosition(EndAngle, radius, RadiusXOffset, RadiusYOffset); float left = (float)Math.Sin(270 * 0.0174532925) * RadiusXOffset * radius + XOffset; float right = (float)Math.Sin(90 * 0.0174532925) * RadiusXOffset * radius + XOffset; float top = (float)Math.Cos(180 * 0.0174532925) * RadiusYOffset * radius + YOffset; float bottom = (float)Math.Cos(0 * 0.0174532925) * RadiusYOffset * radius + YOffset; mainRect.Left = left; mainRect.Right = right; mainRect.Top = top; mainRect.Bottom = bottom; circleOut.Shader = SKShader.CreateSweepGradient( new SKPoint(0f, 0f), new SKColor[] { colorFrom, colorTo }, new float[] { StartAngle / 360f, EndAngle / 360f } ); using (SKPath path = new SKPath()) { path.AddArc(mainRect, StartAngle, Math.Abs(StartAngle - EndAngle)); canvas.DrawPath(path, circleOut); } location1 = AnimatedElementHelper.GetPosition(StartAngle + currentAngle, radius, RadiusXOffset, RadiusYOffset); canvas.DrawCircle(location1.X + XOffset, location1.Y + YOffset, 10, paint); }
public void DrawCompartment(SKCanvas canvas, float _radX, float _radY) { float totalVolume = 0; float totalSpO2 = 0; float radius = 0; scale = _radX * scaleRelative; radius = _radX / 2.5f; if (_radX > _radY) { scale = _radY * scaleRelative; radius = _radY / 2.5f; } // calculate the total volume and average spO2 if lumping is the case foreach (BloodCompartment c in compartments) { totalVolume += (float)c.VolCurrent; totalSpO2 += (float)c.TO2; } paint.Color = AnimatedElementHelper.CalculateBloodColor(totalSpO2 / compartments.Count); float twidth = textPaint.MeasureText(Name); // calculate position location = AnimatedElementHelper.GetPosition(Degrees, radius, RadiusXOffset, RadiusYOffset); // calculate position locationOrigen = AnimatedElementHelper.GetPosition(StartAngle, radius, RadiusXOffset, RadiusYOffset); locationTarget = AnimatedElementHelper.GetPosition(EndAngle, radius, RadiusXOffset, RadiusYOffset); float left = (float)Math.Sin(270 * 0.0174532925) * RadiusXOffset * radius; float right = (float)Math.Sin(90 * 0.0174532925) * RadiusXOffset * radius; float top = (float)Math.Cos(180 * 0.0174532925) * RadiusYOffset * radius; float bottom = (float)Math.Cos(0 * 0.0174532925) * RadiusYOffset * radius; float r = AnimatedElementHelper.RadiusCalculator(totalVolume, scale); if (IsVessel) { mainRect.Left = left; mainRect.Top = top; mainRect.Right = right; mainRect.Bottom = bottom; using (SKPath path = new SKPath()) { path.AddArc(mainRect, StartAngle, Math.Abs(StartAngle - EndAngle) * Direction); circleOut.Color = paint.Color; circleOut.StrokeWidth = r; canvas.DrawPath(path, circleOut); offset.X = Math.Abs(locationOrigen.X - locationTarget.X) / OffsetXFactor; canvas.DrawTextOnPath(Name, path, offset, textPaint2); } } else { paint.StrokeWidth = 10; canvas.DrawCircle(location, r, paint); canvas.DrawText(Name, location.X - twidth / 2, location.Y + 7, textPaint); if (compartments[0].IsPump) { SKPoint or = new SKPoint(0, 0); SKPoint dest = new SKPoint(0, 0); or = location; dest = location; or.X = location.X + (float)Math.Cos(pumpLocation) * 40; or.Y = location.Y + (float)Math.Sin(pumpLocation) * 40; dest.X = location.X + (float)Math.Cos(pumpLocation + Math.PI) * 40; dest.Y = location.Y + (float)Math.Sin(pumpLocation + Math.PI) * 40; pumpLocation += compartments[0].dataCollector.VolumeFlowOut / 10000; if (pumpLocation > 2 * Math.PI) { pumpLocation = 0; } canvas.DrawLine(or, dest, pumpColorStroke); } } }