Reptillian Posted January 7, 2022 Share Posted January 7, 2022 (edited) In this code of mine, I am finding that the pattern disappear if pixel size changes, and it is dependent on the pixel size. I'm not sure why it happens: Other than that, it works fine though it could use a little polishing. // Name: // Submenu: // Author: // Title: // Version: // Desc: // Keywords: // URL: // Help: #region UICode IntSliderControl pixel_size = 1; // [1,100] Pixel Size ColorWheelControl color_a = ColorBgra.FromBgr(0, 0, 0); // [PrimaryColor] Color A ColorWheelControl color_b = ColorBgra.FromBgr(255, 255, 255); // [SecondaryColor] Color B ReseedButtonControl seed = 0; // Reseed #endregion // This single-threaded function is called after the UI changes and before the Render function is called // The purpose is to prepare anything you'll need in the Render function int length_w,length_h,enlarged_w,enlarged_h,old_pixel_size; bool initialized,rebuild; Random myRandomA,myRandomB; Random Init = new Random(); int new_seed; int[] vx; int[] vy; int[,] surface; void PreRender(Surface dst, Surface src) { if (!initialized){ length_w=(int)(Math.Ceiling((double)((src.Width-1)/pixel_size))); length_h=(int)(Math.Ceiling((double)((src.Width-1)/pixel_size))); myRandomA = new Random(Init.Next()); myRandomB = new Random(Init.Next()); vx = new int[length_w]; vy = new int[length_h]; surface = new int[length_w,length_h]; old_pixel_size=pixel_size; } if (old_pixel_size != pixel_size){ length_w=(int)(Math.Ceiling((double)((src.Width-1)/pixel_size))); length_h=(int)(Math.Ceiling((double)((src.Width-1)/pixel_size))); enlarged_w = length_w * pixel_size; enlarged_h = length_h * pixel_size; enlarged_w = ( enlarged_w - src.Width ); enlarged_h = ( enlarged_h - src.Height); myRandomA = new Random(Init.Next()); myRandomB = new Random(Init.Next()); vx = new int[length_w]; vy = new int[length_h]; surface = new int[length_w,length_h]; surface[0,0]=0; rebuild = true; old_pixel_size = pixel_size; } if (!initialized||rebuild||(new_seed != seed)){ myRandomA = new Random(Init.Next()); myRandomB = new Random(Init.Next()); for (int x = 0 ; x < length_w ; x++){ vx[x]=myRandomA.Next()%2; } for (int y = 0 ; y < length_h ; y++){ vy[y]=myRandomB.Next()%2; } for (int y = 1 ; y < length_h ; y++){ surface[0,y]=(surface[0,y-1]+vy[y-1])%2; } for(int y = 0 ; y < length_h ; y++){ for (int x = 1 ; x < length_w ; x++){ surface[x,y]=(vx[x-1]+surface[x-1,y]+y+2)%2; } } } new_seed=seed; initialized = true; rebuild = false; } // Here is the main multi-threaded render function // The dst canvas is broken up into rectangles and // your job is to write to each pixel of that rectangle void Render(Surface dst, Surface src, Rectangle rect) { int val; // Step through each row of the current rectangle for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; // Step through each pixel on the current row of the rectangle for (int x = rect.Left; x < rect.Right; x++) { val = surface[((x+enlarged_w)/pixel_size)%length_w,((y+enlarged_h)/pixel_size)%length_h]; if (val==1){dst[x,y] = color_a;} else{ dst[x,y] = color_b;} } } } Edited January 7, 2022 by Reptillian Quote G'MIC Filter Developer Link to comment Share on other sites More sharing options...
midora Posted January 7, 2022 Share Posted January 7, 2022 May not be related to your issue but ust looking to the code length_w=(int)(Math.Ceiling((double)((src.Width-1)/pixel_size))); I would change the position of the cast length_w=(int)(Math.Ceiling(((double)(src.Width-1)/pixel_size))); 1 Quote Link to comment Share on other sites More sharing options...
Reptillian Posted January 7, 2022 Author Share Posted January 7, 2022 Removing the -1 did fix the problem. Also, changed the position of cast. Thanks. 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.