Jump to content

Codelab Help for a n00b


Recommended Posts

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.

Link to comment
Share on other sites

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++;
   }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...