Jump to content

Rei

Members
  • Posts

    27
  • Joined

  • Last visited

Everything posted by Rei

  1. Image reupload would be cool.
  2. OK, well this is my first plugin. Hope it's useful for more than just me. This plugin will allow you to make your image gradually transparent going from the center to the edges (or vice-versa). The transparency gain over distance to the center is modulable, as well as the circle size. If you have any feedback or suggestions, please share your opinion This is what the UI looks like : Before: After : The main difference between this and the gradient tool is the 'Fade Rate' slider, i.e. the modulability of the transparency gain over distance. Made with the CodeLab plugin for Paint.NET. Installation guide : Download the dll here: RadialFade.zip To install, either disregard the .bat and put the .dll in C:\Program Files\paint.net\Effects or put both files on your desktop and double-click the .bat. The second method is preferred if you are updating the plug-in. It will be installed under Effects\Render. PdN 3.5.11 users : Maximilian has come to your rescue! Download link in his post on page 2, make sure to upvote! Changelog : Hidden Content: 1.1 : + Added panning (thanks to MikeRobe for the idea!) - Changed Fade Rate slider from integer values to real values 1.2 : + Fade-in (rather than out) checkbox - Commented source code for readability 1.3 : + Made circle size adjustable Source Code : Hidden Content: // Submenu: Render // Name: Radial Fade // Title: Rei's Radial Fade // Author: Rei #region UICode double Amount1 = 3; // [0,10] Fade Rate double Amount2 = 0; // [-100,100] X Pan % double Amount3 = 0; // [-100,100] Y Pan % double Amount4 = 100; // [0,1000] Circle Size % bool Amount5 = false; // [0,1] Invert Alpha #endregion double distanceTo(int xPos, int yPos, int xTarget, int yTarget){ //Pythagorean theorem return Math.Sqrt((double)((xTarget-xPos)*(xTarget-xPos)+(yTarget-yPos)*(yTarget-yPos))); } double getRadius(Rectangle bounds){ //the Diameter is by default the biggest dimension (x or y) of the selection. //thus the Radius is half of that. return (Math.Max((bounds.Right-bounds.Left),(bounds.Bottom-bounds.Top))/2); } void Render(Surface dst, Surface src, Rectangle rect) { Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); int centerX = ((selection.Right - selection.Left) / 2)+selection.Left; int centerY = ((selection.Bottom - selection.Top) / 2)+selection.Top; //centerX and centerY represent the coordinates of the center of the fade circle, //which is by default the center of the selection centerX += (int) ((Amount2 *(selection.Left-centerX))/100.0); centerY += (int) ((Amount3 *(selection.Bottom-centerY))/100.0); double radius=getRadius(selection)*(Amount4/100.0); ColorBgra CurrentPixel; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { //here, we find out how far we are from the center of the fade circle to calculate alpha double distanceToCenter = distanceTo(x,y,centerX,centerY); CurrentPixel = src[x,y]; if(!Amount5){ if(distanceToCenter > radius) CurrentPixel.A = (byte) 0; else //distanceToCenter / radius gives us a raw representation of where the pixel is in the circle => how transparent it should be //this value is taken to the 'Amount1'th power so our alpha distribution is customizable and non-linear //we multiply this by 255 to scale from a [0.0,1.0] value to a byte //255.0-<expression> will invert this value (without this it fades in) CurrentPixel.A = (byte) Math.Min((CurrentPixel.A),((255.0)-(Math.Pow((distanceToCenter / radius),Amount1) * 255.0))); } else CurrentPixel.A = (byte) Math.Min((CurrentPixel.A),((Math.Pow((distanceToCenter / radius),Amount1) * 255.0))); dst[x,y] = CurrentPixel; } } } You are free to edit, use and publish this source in any way, whether you make or don't make profit off of it ; as long as I am mentioned as the original author and a link to this thread is provided. EDIT : New license : Do what you want.
×
×
  • Create New...