Reptillian Posted March 16, 2021 Share Posted March 16, 2021 (edited) EDIT: I got a working code, but it's the best I can do. Spoiler // Name: Henon Phase Diagram // Submenu: // Author: // Title: // Version: // Desc: // Keywords: // URL: // Help: #region UICode DoubleSliderControl a = 2.566; // [-3.1415,3.1415] A-Factor IntSliderControl lines = 100; // [1,10000] Lines IntSliderControl pts = 100; // [1,2000] Points per lines DoubleSliderControl x0_start = -0.5; // [-5,0] X0 - Start DoubleSliderControl x0_end = 0.5; // [0,5] X0 - End IntSliderControl x0_increment = 8; // [0,10] X0 - Increment DoubleSliderControl scale = 1; // [0.1,4] Scale AngleControl rotation_angle = 0; // [-180,180] Rotation PanSliderControl position = Pair.Create(0.0,0.0); // Position CheckboxControl include_alpha = false; // Alpha #endregion int [,] Henon_Surface; int maxnum=0; double rot_x ( double a, double b, double cos_ang, double sin_ang ) { return a * cos_ang - b * sin_ang; } double rot_y ( double a, double b, double cos_ang, double sin_ang ) { return a * sin_ang + b * cos_ang; } bool inrange (int a, int b){ bool left_cond = a >= 0; bool right_cond = a < b; return left_cond && right_cond ; } void PreRender(Surface dst, Surface src) { int w = src.Width; int h = src.Height; if (Henon_Surface == null){Henon_Surface = new int [w,h];} else {Array.Clear(Henon_Surface, 0, w*h);} bool use_rotation_formula ; if (rotation_angle != 0){use_rotation_formula = true; } else {use_rotation_formula = false; } int total_steps = x0_increment - 1 ; if (total_steps == 0 ) {total_steps++;} double c = Math.Cos(a); double s = Math.Sin(a); int ex = w - 1; int ey = h - 1; double posx = (double)(ex * ( (position.First + 1) / 2)); double posy = (double)(ey * ( (position.Second + 1) / 2)); double hex = (double) (ex / 2); double hey = (double) (ey / 2); double dist = Math.Min(hex,hey) * scale; double dpi = Math.PI * 2; double ang = -rotation_angle / 180 * Math.PI; double cos_ang = Math.Cos(ang); double sin_ang = Math.Sin(ang); double d_h = (double)(h); int end_step; end_step = Math.Max(total_steps - 1,1); double interp_factor,end_interp_factor,t,xi,yi,m,n,xn,yn,cx,cy,d_step,d_end_step; int icx,icy; for ( int step = 0 ; step < x0_increment ; step++){ d_step = (double)(step); d_end_step = (double)(end_step); interp_factor = d_step / d_end_step; t = x0_start * (1-interp_factor) + x0_end * (interp_factor); xi = t; for (int line_id = 0 ; line_id < lines ; line_id++){ yi = line_id/d_h * dpi; end_interp_factor = (double)(line_id / lines); for ( int ptn = 0 ; ptn < pts ; ptn++) { m = xi ; n = yi - xi*xi; xn = xi*c - n*s; yn = xi*s + n*c; xi = xn ; yi = yn ; if ( m != t){ if (use_rotation_formula) { cx = Math.Round( posx + rot_x(xi,yi,cos_ang,sin_ang)/2*dist); cy = Math.Round( posy + rot_y(xi,yi,cos_ang,sin_ang)/2*dist); icx = (int)(cx); icy = (int)(cy); } else { cx = Math.Round( posx + xi/2*dist); cy = Math.Round( posy + yi/2*dist); icx = (int)(cx); icy = (int)(cy); } if (inrange(icx,w)&&inrange(icy,h)){ Henon_Surface[icx,icy] = Math.Max(Henon_Surface[icx,icy],line_id); maxnum=Math.Max(Henon_Surface[icx,icy],maxnum); } } } } } } void Render(Surface dst, Surface src, Rectangle rect) { // Delete any of these lines you don't need byte val; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { val = (byte) (Henon_Surface[x,y]*100); dst[x,y] = ColorBgra.FromBgraClamped(val,val,val,255); } } } Edited March 16, 2021 by Reptillian Quote G'MIC Filter Developer 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.