Reptillian Posted December 4, 2021 Share Posted December 4, 2021 (edited) This is yet another translation of my filter. I'm working exclusively with Render. Might be done, or not. Output: Here are the TODOs list: 1) Enable Anti-aliasing 2) Find ways to color the image // Name: // Submenu: // Author: // Title: // Version: // Desc: // Keywords: // URL: // Help: #region UICode IntSliderControl max_iter = 50; // [1,200] Maximum Iteration DoubleSliderControl k_a_perc = 50; // [-100,100] K-A Tau (%) DoubleSliderControl k_b_perc = -50; // [-100,100] K-B Tau (%) AngleControl variable_angle = 45; // [-180,180] Angle DoubleSliderControl axis_scale = 2; // [1,15] Axis-Scale PanSliderControl point_xy = Pair.Create(0.000, 0.000); // Point CheckboxControl antialiased_mode = true; // Use Anti-aliasing? #endregion double tau = 2 * Math.PI; double tc = .7 / (2 * Math.PI); double rot_x(double a, double b, double sin_ang,double cos_ang){ return a*cos_ang-b*sin_ang; } double rot_y(double a, double b, double sin_ang,double cos_ang){ return a*sin_ang+b*cos_ang; } double oscil_a(double a,double b, double k_a){ return a+k_a-tc*Math.Sin(tau*b); } double oscil_b(double a,double b, double k_b){ return a+k_b-tc*Math.Sin(tau*b); } double norm2(double a,double b){ return Math.Sqrt(a*a+b*b); } void Render(Surface dst, Surface src, Rectangle rect) { int ww = src.Width-1; int hh = src.Height-1; double d_ww=(double)(ww); double d_hh=(double)(hh); double sd = Math.Max(d_ww,d_hh)/Math.Min(d_ww,d_hh); double sx = ww>hh?sd:1; double sy = ww>hh?1:sd; double cx = d_ww/2; double cy = d_hh/2; double ox = (point_xy.First+1)*cx; double oy = (point_xy.Second+1)*cy; double cxsx=cx/sx/axis_scale; double cysy=cy/sy/axis_scale; double ang = variable_angle/180*Math.PI; double sin_ang=Math.Sin(ang); double cos_ang=Math.Cos(ang); double k_a=k_a_perc/100*tau; double k_b=k_b_perc/100*tau; double ix,iy,txp,xp,yp,ev; int i_ev; byte b_ev; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; iy=(y-oy)/cysy; for (int x = rect.Left; x < rect.Right; x++) { ix=(x-ox)/cxsx; xp=rot_x(ix,iy,sin_ang,cos_ang); yp=rot_y(ix,iy,sin_ang,cos_ang); for (int n = 0 ; n < max_iter ; n ++){ txp=xp; xp=oscil_a(xp,yp,k_a); yp=oscil_b(yp,txp,k_b); } ev = norm2(xp,yp); i_ev=(int)(Math.Round(ev*200)); b_ev=(byte)(i_ev); dst[x,y] = ColorBgra.FromBgr(b_ev,b_ev,b_ev); } } } Edited December 5, 2021 by Reptillian Quote G'MIC Filter Developer I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me. Link to comment Share on other sites More sharing options...
Roly Poly Goblinoli Posted December 4, 2021 Share Posted December 4, 2021 if b_ev just goes from 0 to 255 you could use it as the alpha to lerp between two colors using the ColorBgra.Blend(colorA, colorB, alphaB) overload 1 Quote Link to comment Share on other sites More sharing options...
Reptillian Posted December 4, 2021 Author Share Posted December 4, 2021 2 hours ago, NinthDesertDude said: if b_ev just goes from 0 to 255 you could use it as the alpha to lerp between two colors using the ColorBgra.Blend(colorA, colorB, alphaB) overload I resorted to trying to find a color formula instead: Quite limited, but it's better than before. // Name: // Submenu: // Author: // Title: // Version: // Desc: // Keywords: // URL: // Help: #region UICode IntSliderControl max_iter = 50; // [1,200] Maximum Iteration DoubleSliderControl k_a_perc = 50; // [-100,100] K-A Tau (%) DoubleSliderControl k_b_perc = -50; // [-100,100] K-B Tau (%) AngleControl variable_angle = 45; // [-180,180] Angle DoubleSliderControl axis_scale = 2; // [1,15] Axis-Scale PanSliderControl point_xy = Pair.Create(0.000, 0.000); // Point CheckboxControl antialiased_mode = true; // Use Anti-aliasing? #endregion double tau = 2 * Math.PI; double tc = .7 / (2 * Math.PI); double rot_x(double a, double b, double sin_ang,double cos_ang){ return a*cos_ang-b*sin_ang; } double rot_y(double a, double b, double sin_ang,double cos_ang){ return a*sin_ang+b*cos_ang; } double oscil_a(double a,double b, double k_a){ return a+k_a-tc*Math.Sin(tau*b); } double oscil_b(double a,double b, double k_b){ return a+k_b-tc*Math.Sin(tau*b); } double norm2(double a,double b){ return Math.Sqrt(a*a+b*b); } void Render(Surface dst, Surface src, Rectangle rect) { int ww = src.Width-1; int hh = src.Height-1; double d_ww=(double)(ww); double d_hh=(double)(hh); double sd = Math.Max(d_ww,d_hh)/Math.Min(d_ww,d_hh); double sx = ww>hh?sd:1; double sy = ww>hh?1:sd; double cx = d_ww/2; double cy = d_hh/2; double cxsx=cx/sx/axis_scale; double cysy=cy/sy/axis_scale; double ang = variable_angle/180*Math.PI; double sin_ang=Math.Sin(ang); double cos_ang=Math.Cos(ang); double k_a=k_a_perc/100*tau; double k_b=k_b_perc/100*tau; double ix,iy,txp,xp,yp,ev,disp; int lim=antialiased_mode?2:1; byte r,g,b; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { ev=0; double[] col = new double[3] {0,0,0}; for (int m = 0 ; m < lim ; m++){ disp=m*.5; iy=(y+disp-cy)/cysy; ix=(x+disp-cx)/cxsx; ix-=point_xy.First; iy-=point_xy.Second; xp=rot_x(ix,iy,sin_ang,cos_ang); yp=rot_y(ix,iy,sin_ang,cos_ang); for (int n = 0 ; n < max_iter ; n ++){ txp=xp; xp=oscil_a(xp,yp,k_a); yp=oscil_b(yp,txp,k_b); } ev=norm2(xp,yp); col[0]+=(Math.Sin(ev)+1)/2; col[1]+=(Math.Cos(ev+ev/2)+1)/2; col[2]+=(Math.Sin(ev*2)+1)/2; } col[0]/=lim; col[1]/=lim; col[2]/=lim; r = (byte)((int)(Math.Round(col[0]*255))); g = (byte)((int)(Math.Round(col[1]*255))); b = (byte)((int)(Math.Round(col[2]*255))); dst[x,y]=ColorBgra.FromBgr(b,g,r); } } } Quote G'MIC Filter Developer I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me. Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted December 5, 2021 Share Posted December 5, 2021 This is quite neat. I could play with it for hours 3 hours ago, Reptillian said: Quite limited, but it's better than before. I don't much like the colorization changing with the parameters. I'd prefer to be able to set the parameters to fix the shape AND THEN alter the colors. Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
Reptillian Posted December 5, 2021 Author Share Posted December 5, 2021 36 minutes ago, Ego Eram Reputo said: I don't much like the colorization changing with the parameters. I'd prefer to be able to set the parameters to fix the shape AND THEN alter the colors. The last statement is how this plugin works, so I'm not sure what you mean. Also, finished code is at the plugin section. Quote G'MIC Filter Developer I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me. 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.