Arbruteblade Posted February 7, 2010 Share Posted February 7, 2010 I'm trying to make a plugin which makes a rainbow gradient going from left to right, the top line works well, but everything else becomes black, what do I do, or what am I missing about codelab or about Paint.NET? Will I have to make the rest of the plugin in a c# writing program? The version of paint.NET is 3.5.2. Here's the code. #region UICode int Amount1 = 0; // [0,5430] Offset #endregion byte nextred = 255; byte nextgreen = 0; byte nextblue = 0; int width = 0; int number = 0; void progress() { if (nextred == 255) { if (nextblue == 0 && nextgreen < 255) nextgreen++; if (nextblue > 0) nextblue--; } if (nextgreen == 255) { if (nextred == 0 && nextblue < 255) nextblue++; if (nextred > 0) nextred--; } if (nextblue == 255) { if (nextgreen == 0 && nextred < 255) nextred--; if (nextgreen > 0) nextgreen--; } } void Render(Surface dst, Surface src, Rectangle rect) { int offset = Amount1; ColorBgra[] GradientStore = new ColorBgra[5430]; while (offset > 0) { progress(); offset--; } while (number < 5430) { GradientStore[number].R = nextred; GradientStore[number].G = nextgreen; GradientStore[number].B = nextblue; progress(); number++; } ColorBgra CurrentPixel; int x = rect.Left; int y; while (x < rect.Right) { y = rect.Top; while (y < rect.Bottom) { CurrentPixel = GradientStore[x]; CurrentPixel.A = src[x,y].A; dst[x,y] = CurrentPixel; y++; } x++; } } Also, am I in the right forum, any mods please move this if it isn't in the right forum. Quote Link to comment Share on other sites More sharing options...
Simon Brown Posted February 7, 2010 Share Posted February 7, 2010 You don't need calculate the RGB value by hand, Paint.NET provides a HsvColor class to convert between colour spaces. Quote Link to comment Share on other sites More sharing options...
Arbruteblade Posted February 7, 2010 Author Share Posted February 7, 2010 You don't need calculate the RGB value by hand, Paint.NET provides a HsvColor class to convert between colour spaces. My method creates about 1530 colors, using Hsv only creates 360 colors. Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted February 8, 2010 Share Posted February 8, 2010 Then try HsvColorF (new for 3.5.2). Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Arbruteblade Posted February 8, 2010 Author Share Posted February 8, 2010 I already have the gradient working, my problem is that it only writes to the top line of the picture and makes the rest black. Quote Link to comment Share on other sites More sharing options...
Arbruteblade Posted February 10, 2010 Author Share Posted February 10, 2010 I got it working, it overall taught me more about codelab's limitations, but I got it working by basing it slightly more on the template (CurrentPixel = src[x,y]), figuring out which variables should be global, etc. I also managed to improve the algorithm while editing, and I also had to handle, "What if it goes out of the array?" #region UICode int Amount1 = 0; // [0,1530] Offset #endregion byte nextred = 255; byte nextgreen = 0; byte nextblue = 0; int width = 0; int number = 0; int changecheck; bool done; bool done2; ColorBgra[] GradientStore = new ColorBgra[1530]; void progress() { if (nextred == 255 && done == false) { if (nextblue == 0 && nextgreen < 255) { nextgreen++; done = true; } if (nextblue > 0) { nextblue--; done = true; } } if (nextgreen == 255 && done == false) { if (nextred == 0 && nextblue < 255) nextblue++; if (nextred > 0) nextred--; } if (nextblue == 255 && done == false) { if (nextgreen == 0 && nextred < 255) { nextred++; done = true; } if (nextgreen > 0) { nextgreen--; done = true; } } done = false; } void Render(Surface dst, Surface src, Rectangle rect) { int offset = Amount1; if (offset != changecheck || done2 == false) { changecheck = Amount1; while (offset > 0) { progress(); offset--; } while (number < 1530) { GradientStore[number].R = nextred; GradientStore[number].G = nextgreen; GradientStore[number].B = nextblue; progress(); number++; } done2 = true; } number = 0; nextred = 255; nextgreen = 0; nextblue = 0; int position; ColorBgra CurrentPixel; int x = rect.Left; int y; while (x < rect.Right) { y = rect.Top; position = x; if (position >= 1529) position = position - 1529; while (y < rect.Bottom) { CurrentPixel = src[x,y]; CurrentPixel.R = GradientStore[position].R; CurrentPixel.G = GradientStore[position].G; CurrentPixel.B = GradientStore[position].B; dst[x,y] = CurrentPixel; y++; } x++; } Quote 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.