VeLC Posted May 2, 2022 Share Posted May 2, 2022 (edited) Draws an Archimedean spiral Found in Effects > Render Versions: 1.0(20220502) - Initial Release 1.1(20220503) - Add option for Initial Loop Number / larger Initial Point Offset increments 1.2(20220506) - Fix Initial Point Offset "typo" C# Code Snippet (Modified from CodeLab generated code) License: LPGL-3.0 Spoiler protected override void OnRender(Rectangle[] rois, int startIndex, int length) { if (length == 0 || IsCancelRequested) { return; } using CancellationTokenSource cts = new(); using System.Timers.Timer timer = new(20); timer.AutoReset = true; timer.Elapsed += (s, e) => { if (IsCancelRequested) { cts.Cancel(); } }; timer.Start(); try { Render(DstArgs.Surface, SrcArgs.Surface, EnvironmentParameters.SelectionBounds, cts.Token); } catch (OperationCanceledException) { } timer.Stop(); } #region UICode private DoubleSliderControl loops = 5; // [2,1000] Loops private IntSliderControl spacing = 25; // [1,100] Loop Spacing private DoubleSliderControl step = 10; // [1,360] Point Alignment private ListBoxControl offsetType = 1; // |Initial Loop Number|Initial Point Offset private IntSliderControl offset = 0; // [0,100] private DoubleSliderControl tension = 0.5; // [0,1] Line Curvature private IntSliderControl width = 1; // [1,100] Line Width private CheckboxControl clockwise = true; // Clockwise private PanSliderControl center = Pair.Create(0.000, 0.000); // Center private AngleControl rotation = 0; // [0,360] Rotation #endregion private PointF[] cachedPoints; private State cachedState; private void Render(Surface dst, Surface src, Rectangle rect, CancellationToken token) { dst.CopySurface(src, rect.Location, rect); using Graphics g = new RenderArgs(dst).Graphics; using Region gClipRegion = new(rect); g.Clip = gClipRegion; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias; float centerX = (float)(rect.Left + (center.First + 1) / 2 * rect.Width); float centerY = (float)(rect.Top + (center.Second + 1) / 2 * rect.Height); g.TranslateTransform(centerX, centerY); g.RotateTransform((float)-rotation); if (IsCancelRequested) return; PointF[] points; State state = new(this); if (state.Equals(cachedState)) { points = cachedPoints; } else { double a = offsetType == 1 ? offset : offset * spacing; double b = spacing / 360.0; double toRad = Math.PI / (clockwise ? 180 : -180); points = Enumerable .Range(0, (int)(loops * 360 / step + 1)) .AsParallel() .AsOrdered() .WithCancellation(token) .Select(i => { double theta = i * step; double r = a + b * theta; double rad = theta * toRad; (double sin, double cos) = Math.SinCos(rad); float x = (float)(r * cos); float y = (float)(r * sin); return new PointF(x, y); }) .ToArray(); } using Pen pen = new(EnvironmentParameters.PrimaryColor, width); pen.StartCap = LineCap.Round; pen.EndCap = LineCap.Round; g.DrawCurve(pen, points, (float)tension); cachedPoints = points; cachedState = state; } internal class State { private readonly double loops; private readonly int spacing; private readonly double step; private readonly byte offsetType; private readonly int offset; private readonly bool clockwise; public State(ArchimedeanSpiralEffectPlugin plugin) { loops = plugin.loops; spacing = plugin.spacing; step = plugin.step; offsetType = plugin.offsetType; offset = plugin.offset; clockwise = plugin.clockwise; } public override bool Equals(object obj) { return obj is State state && loops == state.loops && spacing == state.spacing && step == state.step && offsetType == state.offsetType && offset == state.offset && clockwise == state.clockwise; } public override int GetHashCode() { return HashCode.Combine(loops, spacing, step, offsetType, offset, clockwise); } } } ArchimedeanSpiral.zip Edited May 6, 2022 by VeLC Version 1.2 5 1 Quote Link to comment Share on other sites More sharing options...
Panchdara Posted May 3, 2022 Share Posted May 3, 2022 Hi. I think you might be missing top section of the source?? Quote Link to comment Share on other sites More sharing options...
VeLC Posted May 3, 2022 Author Share Posted May 3, 2022 Version 1.1 - Add option for Initial Loop Number / larger Initial Point Offset increments 1 Quote Link to comment Share on other sites More sharing options...
Panchdara Posted May 3, 2022 Share Posted May 3, 2022 Okay.... what am I missing here? Quote Link to comment Share on other sites More sharing options...
lynxster4 Posted May 3, 2022 Share Posted May 3, 2022 Quote My Art Gallery | My Shape Packs | ShapeMaker Mini Tut | Air Bubble Stained Glass Chrome Text with Reflections | Porcelain Text w/ Variegated Coloring | Realistic Knit PatternOpalescent Stained Glass | Frosted Snowman Cookie | Leather Texture | Plastic Text | Silk Embroidery Visit my Personal Website "Never, ever lose your sense of humor - you'll live longer" Link to comment Share on other sites More sharing options...
Panchdara Posted May 3, 2022 Share Posted May 3, 2022 7 minutes ago, lynxster4 said: I can't understand how to compile using Codelab - the dll is fine. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted May 3, 2022 Share Posted May 3, 2022 46 minutes ago, Panchdara said: I can't understand how to compile using Codelab - the dll is fine. The posted code is not meant to be used in CodeLab. Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.