Jump to content

Unfinished plugins


xod

Recommended Posts

In this place we would like to post unfinished plugins made with CodeLab but which could be a source of inspiration for beginners.
I'll start with a fun(?) plug-in that can be further developed by those who want to do it.

Spoiler

        // Name: LongiStripes
        // Submenu: Render
        // Author: xod 
        // Title: LongiStripes
        // Version: 1.0
        // Desc: 
        // Keywords: 
        // URL: 
        // Help: 
        
        #region UICode
        DoubleSliderControl Amount1 = 0.75; // [0,1] Size
        IntSliderControl Amount2 = 100; // [0,400] Thickness
        ColorWheelControl Amount3 = ColorBgra.FromBgr(205,0,0); // [MediumBlue] Color
        DoubleSliderControl Amount4 = 0; // [0,1] Stripe1
        DoubleSliderControl Amount5 = 0.1; // [0,1] 
        DoubleSliderControl Amount6 = 0.3; // [0,1] Stripe2
        DoubleSliderControl Amount7 = 0.7; // [0,1] 
        DoubleSliderControl Amount8 = 0.9; // [0,1] Stripe3
        DoubleSliderControl Amount9 = 1; // [0,1] 
        DoubleSliderControl Amount10 = 1; // [0,1] X Distorsion
        DoubleSliderControl Amount11 = 1; // [0,1] Y Distorsion
        ListBoxControl Amount12 = 0; // Shapes|Ellipse|Rectangle|Triangle
        #endregion
        
        void Render(Surface dst, Surface src, Rectangle rect)
        {
           Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
           dst.CopySurface(src, rect.Location, rect);
           
            float centX = ((selection.Right - selection.Left) / 2f) + selection.Left;
            float centY = ((selection.Bottom - selection.Top) / 2f) + selection.Top;
            float size = (float)Amount1 * Math.Min(selection.Width - 4, selection.Height - 4);
            float half = size/2f;
            float sp1 = (float)Amount4;
            float sp2 = (float)Amount5;
            float sp3 = (float)Amount6;
            float sp4 = (float)Amount7;
            float sp5 = (float)Amount8;
            float sp6 = (float)Amount9;
            float xDis = (float) Amount10;
            float yDis = (float) Amount11;
            byte shapes = Amount12;
            
               using (RenderArgs ra = new RenderArgs(dst))
               { 
                Graphics g = ra.Graphics;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.Clip = new Region(rect);
                 {
                  using (Pen penel = new Pen (Amount3, Amount2))
                  {
                    PointF[] points =
                    {
                    new PointF (centX-half*xDis, centY-half*yDis),
                    new PointF (size,centY-half*yDis),
                    new PointF (centX-half*xDis,size)
                    };
                    
                    if(sp1>=sp2){sp2=sp1;}
                    if(sp2>=sp3){sp3=sp2;}
                    if(sp3>=sp4){sp4=sp3;}
                    if(sp4>=sp5){sp5=sp4;}
                    if(sp5>=sp6){sp6=sp5;}
                    
                    penel.Width = Amount2;
                    penel.CompoundArray = new float[] {sp1, sp2, sp3, sp4, sp5, sp6};
           
           switch (shapes)
                   {
                    case 0: //ellipse          
                    {
                    g.DrawEllipse(penel, centX-half*xDis, centY-half*yDis, size*xDis, size*yDis);
                    }
                    break;
        
                    case 1: //rectangle
                    {
                    g.DrawRectangle(penel, centX-half*xDis, centY-half*yDis, size*xDis, size*yDis);
                    }
                    break;
                    
                    case 2: //triangle
                    {   
                    g.DrawPolygon(penel, points);
                    }
                    break;
                   }
                  }
                 }
               }
        }



 

 

LongiStripes.zip

  • Upvote 4
Link to comment
Share on other sites

<3 @xod! Thank you for your effort. :cake: :coffee:  I have no idea of the plugin write. For the plugin writers indispensable. :trophy:

Live as if you were to die tomorrow. Learn as if you were to live forever.

Gandhi

 

mae3426x.png

Link to comment
Share on other sites

  • 2 months later...

Is there a way of formatting numbers so that unneeded zeros can be suppressed?
For example, the 0.0000 number to be displayed as 0 or 1.0000 to be displayed as 1.
Below I posted the code I'm working on.

 

Spoiler

 // Name: SineCosine
        // Submenu: 
        // Author: 
        // Title: SineCosine
        // Version: 1.0
        // Desc: SineCosine
        // URL:
        // Help:
        
        #region UICode
        IntSliderControl Amount1 = 440; // [30,800] Wave position
        IntSliderControl Amount2 = 300; // [0,600] oy position
        IntSliderControl Amount3 = 1; // [1,10] Period
        IntSliderControl Amount4 = 150; // [75,150] Circle radius
        IntSliderControl Amount5 = 50; // [0,100] Wave width
        IntSliderControl Amount6= 15; // [10,50] Point radius
        IntSliderControl Amount7 = 45; // [0,360] Angle * period
        #endregion
        
        void Render(Surface dst, Surface src, Rectangle rect)
        {
            Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
            float xlax = (selection.Right - selection.Left);//x length axis
            float centerY = (selection.Bottom - selection.Top)/2f - selection.Top;
            float centerX = (selection.Right - selection.Left)/2f - selection.Left;
            float PI  = (float)Math.PI;
            float xPos = Amount1; //ox
            float yPos = Amount2; //oy
            float frecv = (float)Amount3; //period
            float radius = Amount4; //radius
            float width = Amount5; //width
            float angle = (float)Amount7; //angle wave
            float dens = 0.01f; //lines density for drawing waves
            float ptDiam = Amount6; 
            float x = 0; 
            float y = 0;
            float y1;
            float r;
            float a1 = Math.Abs((float)Math.Sin(angle * frecv * PI / 180) * radius);
            float a2 = Math.Abs((float)Math.Cos(angle * frecv * PI / 180) * radius);
            float v1 = (float)Math.Sin(angle * frecv * PI / 180) * radius;
            float v2 = (float)Math.Cos(angle * frecv * PI / 180) * radius;
            float m1 = (float)Math.Sin(angle * frecv * PI / 180);
            float m2 = (float)Math.Cos(angle * frecv * PI / 180);
            
            dst.CopySurface(src, rect.Location, rect);
            using (RenderArgs ra = new RenderArgs(dst))
            {   
              Graphics g = ra.Graphics;
              g.Clip = new Region(rect);
              g.SmoothingMode = SmoothingMode.AntiAlias;
              StringFormat format = new StringFormat();
              format.Alignment = StringAlignment.Center;
              format.LineAlignment = StringAlignment.Center;
              using (Pen sPen = new Pen(Color.LightGray,1))
              using (SolidBrush textBrush = new SolidBrush(Color.Black))
              using (Font textFont = new Font("Tahoma", 10, FontStyle.Regular))      
              
              {  
                sPen.StartCap = LineCap.Round;
                sPen.EndCap = LineCap.Round;
                centerX = centerX - 200;
               
                //draw horizontal axis
                g.DrawLine(sPen, 0, yPos, xlax, yPos);
                
                //draw vertical axis
                g.DrawLine(sPen, centerX, yPos + radius, centerX, yPos - radius); 
                g.DrawString("1",textFont, textBrush, xPos - 10 , yPos - radius, format);
                g.DrawString("0",textFont, textBrush, xPos - 10 , yPos, format);
                g.DrawString("-1",textFont, textBrush, xPos - 10, yPos + radius, format);        
                
                //draw circle
                sPen.DashStyle = DashStyle.Solid;
                sPen.Color = Color.Gray;
                sPen.Width = 2; 
                g.DrawEllipse(sPen, centerX - radius, yPos - 2 * radius * 0.5f, 2 * radius, 2 * radius);; 
                g.DrawString("1",textFont, textBrush, centerX, yPos - radius - ptDiam * 0.85f , format);
                g.DrawString("-1",textFont, textBrush, centerX, yPos + radius + ptDiam * 0.85f, format);
                g.DrawString("1",textFont, textBrush, centerX + radius + ptDiam * 0.85f, yPos, format);
                g.DrawString("-1",textFont, textBrush, centerX - radius - ptDiam * 0.85f, yPos, format);
                
                //draw vector and point
                sPen.Width = 2;
                sPen.Color = Color.Green;
                sPen.EndCap = LineCap.RoundAnchor;
                sPen.DashStyle = DashStyle.Solid;
                g.DrawLine(sPen, centerX, yPos, centerX + v2 , yPos - v1 );
                g.DrawEllipse(sPen, centerX + v2 - ptDiam * 0.5f, yPos - v1 - ptDiam * 0.5f, ptDiam, ptDiam);
                
                //draw angle arc
                sPen.Width = 1;
                sPen.EndCap = LineCap.ArrowAnchor;
                g.DrawArc(sPen, centerX - radius * 0.3f, yPos - radius * 0.3f, radius * 0.6f, radius * 0.6f, 0, - angle * frecv);
                g.DrawString("x", textFont, textBrush, centerX + radius * 0.35f, yPos - radius * 0.11f, format);      
        
                //draw rectangle
                sPen.DashStyle = DashStyle.Dot;
                sPen.Width = 1;
                sPen.Color = Color.Green;
                    
                angle = angle * frecv;
                while (angle > 0)
                {
                  angle  =  angle - 360;  
                }
                angle  =  angle + 360;
        
                //quadrant I
                if(angle < 90)
                {
                g.DrawRectangle(sPen, centerX, yPos - a1,  a2 , a1);
                } 
                //quadrant II
                if(angle > 90 && angle < 180)
                {
                g.DrawRectangle(sPen, centerX - a2, yPos - a1,  a2, a1); 
                }
                //quadrant III
                if(angle > 180 && angle < 270)
                {
                g.DrawRectangle(sPen, centerX - a2, yPos, a2, a1); 
                }
                //quadrant IV
                if(angle > 270)
                {
                g.DrawRectangle(sPen, centerX, yPos, a2, a1);     
                }         
                               
                sPen.EndCap = LineCap.Round;
                sPen.DashStyle = DashStyle.Solid;    
                sPen.Width = 3;
                sPen.Color = Color.Red;
                angle = Amount7;      
                  
                //draw sin wave
                for (r = 0; r < angle * PI / 180; r += dens)
                {
                    y1 = -(float)Math.Sin(r * frecv) * radius;
                    g.DrawLine(sPen, xPos + x * width, yPos + y, xPos + x * width, yPos + y1);
                    y = y1;
                    x = r;
                }
                
                //draw sin line            
                for (r = 0; r < angle * PI / 180; r += dens)
                {
                    y1 = 0;
                    g.DrawLine(sPen, centerX, yPos + y, centerX, yPos + y1);
                    y = y1;
                    x = r;
                }
                    
                //draw cos wave
                sPen.Color = Color.Blue; 
                y = -(float)Math.Cos(PI / 180 * frecv) * radius;      
                for (r = 0; r < angle * PI / 180; r += dens)
                {
                    y1 = -(float)Math.Cos(r * frecv) * radius;
                    x = r;
                    g.DrawLine(sPen, xPos + x * width, yPos + y, xPos + x * width, yPos + y1);
                    y = y1;
                }
                
                //draw cos line            
                for (r = 0; r < angle * PI / 180; r += dens)
                {
                    y1 = 0;
                    g.DrawLine(sPen, centerX - y, yPos , centerX - y1, yPos);
                    y = y1;
                    x = r;                                                                     
                }
                
                //draw info
                format.Alignment = StringAlignment.Near;
                sPen.StartCap = LineCap.Flat;
                sPen.EndCap = LineCap.Flat;
                sPen.Color = Color.Red;
                sPen.Width = 10;
                g.DrawLine(sPen, xPos, yPos - 2 * radius * 0.95f, xPos + 30, yPos - 2 * radius * 0.95f); 
                g.DrawString("y = sin(" + (angle * frecv).ToString()+ ") = " + m1.ToString("N6"), textFont, textBrush, xPos + 35, yPos - 2 * radius * 0.95f, format);
                sPen.Color = Color.Blue;
                g.DrawLine(sPen, xPos, yPos - 2 * radius * 0.85f, xPos + 30, yPos - 2 * radius * 0.85f); 
                g.DrawString("z = cos(" + (angle * frecv).ToString()+ ") = "  + m2.ToString("N6"), textFont, textBrush, xPos + 35, yPos - 2 * radius * 0.85f, format);     
            }      
          }
        }

 

 

Link to comment
Share on other sites

  • 3 months later...

This is an object alignment plugin made with CodeLab.
It's very slow for big canvases because of the algorithm.

Spoiler

// Name: Alignment
// Submenu: 
// Author: xod
// Title: Alignment
// Version: 1.0
// Desc: Align the object on the canvas or in selection
// Keywords:
// URL:
// Help:
 
#region UICode
RadioButtonControl Amount1 = 1; // [0]|Center|Top Left|Bottom Left|Top Right|Bottom Right|Middle Left|Middle Right|Middle Top|Middle Bottom|Left|Middle Horizontal|Right|Top|Middle Vertical|Bottom|Cancel (Initial position)
#endregion
    
void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle sel = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    ColorBgra CurrentPixel;
    int sTop = sel.Top;
    int sBot = sel.Bottom;
    int sLeft = sel.Left;
    int sRite = sel.Right;
    int centX = sel.Width/2;
    int centY = sel.Height/2;
    int x = 0;
    int y = 0;
    int x1 = 0;
    int x2 = 0;
    int y1 = 0;
    int y2 = 0;
    int xPos = 0;
    int yPos = 0;
    bool fp1 = false;
    bool fp2 = false;
    bool fp3 = false;
    bool fp4 = false;

 {                               //                        sTop
    //find y1 ************************       _________________________________
    for (y = sTop; y < sBot; y++)//          |          |                     | 
    {                            //          |          |                     |
        for (x = sLeft; x < sRite; x++)//    |          |                     |
        {                         //         |          |y1                   |
          CurrentPixel = src[x,y];//         |          |                     |
          if(CurrentPixel.A != 0) //         |         _|_                    |
            {                     //         |   x1   |   |         x2        |
              fp1 = true;         //    sLeft|--------|Obj|-------------------|sRite
              y1 = y;             //         |        |___|                   |
              break;              //         |          |                     | 
            }                     //         |          |y2                   |
            if (fp1) break;       //         |          |                     |   
        }                         //         |__________|_____________________|
        if (fp1) break;           //                        sBot
    }                             //                                       

    //find y2 ************************    
    for (y = sBot - 1; y > sTop; y--)
    {
        for (x = sLeft; x < sRite; x++)
        {
          CurrentPixel = src[x,y];
          if(CurrentPixel.A != 0)
            {
              fp2 = true;
              y2 = y + 1;
              break;  
            }
            if (fp2) break;   
        }
        if (fp2) break;
    }   

     //find x1 ************************
     for (x = sLeft; x < sRite; x++)
    {
        for (y = sTop; y < sBot; y++)
        {
          CurrentPixel = src[x,y];
          if(CurrentPixel.A != 0)
            {
              fp3 = true;
              x1 = x;
              break;  
            }
            if (fp3) break;   
        }
        if (fp3) break;
    }   
     
     //find x2 *************************
     for (x = sRite - 1; x > sLeft; x--)
    {
        for (y = sTop; y < sBot; y++)
        {
          CurrentPixel = src[x,y];
          if(CurrentPixel.A != 0)
            {
              fp4 = true;
              x2 = x + 1;
              break;  
            }
            if (fp4) break;   
        }
        if (fp4) break;
    }
    //**********************************

    switch (Amount1)
      {
        case 0: //Center
        xPos = (sLeft - x1 + centX) - (x2 - x1)/2; 
        yPos = (sTop - y1 + centY) - (y2 - y1)/2;
        break;
        
        case 1: //Top Left
        xPos = sLeft - x1;
        yPos = sTop - y1;
        break;
        
        case 2: //Bottom Left
        xPos = sLeft - x1; 
        yPos = sBot - y2; 
        break;
        
        case 3: //Top Right
        xPos = sRite - x2;  
        yPos = sTop - y1; 
        break;
        
        case 4: //Bottom Right
        xPos = sRite - x2; 
        yPos = sBot - y2; 
        break;
        
        case 5: //Middle Left
        xPos = sLeft - x1;
        yPos = (sTop - y1 + centY) - (y2 - y1)/2;
        break;
        
        case 6: //Middle Right
        xPos = sRite - x2;
        yPos = (sTop - y1 + centY) - (y2 - y1)/2;
        break;
        
        case 7: //Middle Top
        xPos = (sLeft - x1 + centX) - (x2 - x1)/2;
        yPos = sTop - y1;
        break;
        
        case 8: //Middle Bottom
        xPos = (sLeft - x1 + centX) - (x2 - x1)/2;
        yPos = sBot - y2;
        break;
        
        case 9: //Left
        xPos = sLeft - x1;
        yPos = sTop-sTop;
        break;
        
        case 10: //Middle Horizontal
        xPos = (sLeft - x1 + centX) - (x2 - x1)/2;
        yPos = sTop-sTop;
        break;
        
        case 11: //Right
        xPos = sRite - x2;
        yPos = sTop-sTop;
        break;
           
        case 12: //Top
        xPos = sLeft - sLeft;
        yPos = sTop - y1;
        break;
        
        case 13: //Middle Vertical
        xPos = sLeft - sLeft;
        yPos = (sTop - y1 + centY) - (y2 - y1)/2;
        break;
        
        case 14: //Bottom
        xPos = sLeft - sLeft;
        yPos = sBot - y2;
        break;
        
        case 15: //Cancel (Initial position)
        xPos = sLeft - sLeft;
        yPos = sBot - sBot;
        break; 
                                         
      } 
  }
 
        Bitmap bmp = new RenderArgs(src).Bitmap;
        Graphics g = new RenderArgs(dst).Graphics;
        g.Clip = new Region(rect);
        g.Clear(Color.Transparent);
        g.DrawImage(bmp, xPos, yPos);

        bmp.Dispose();

        g.Dispose();
        //dst[0,0] = dst[0,0];

}

 

 

► Alignment.zip ◄

Edited by xod
Link to comment
Share on other sites

5 hours ago, xod said:

It's very slow for big canvases because of the algorithm.

 

It could be made more efficient by determining the centering values only once.

 

bool firstTime = true;
int x1, x2, y1, y2;
void Render(Surface dst, Surface src, Rectangle rect)
{
	if (firstTime)
	{
		// find centering variables, x1, x2, y1, y2.
			.
			.
			.
		firstTime = false;
	}
		.
		.
		.
}

If the centering variables were possibly modified while being computed  (set to one value then another), I'd rewrite it or store them in local variables until the end, at which point I'd assign them to the "global" variables. E.g.:

 

	if (firstTime)
	{
		int locX1;

		locX1 = sLeft;
		if (locX1 > 100)
			locX1 = 100;

		x1 = locX1;
		firstTime = false;
	}

 

I don't think that's absolutely necessary, but it's the safe way. The reason is, it would still work if you take off the firstTime test. Otherwise with multiple processors, a thread could access a variable during the time a different thread had set it to the non-final value. The basic rule is that a "global" (class-level, really) variable must be the same for every thread, and can never be assigned anything except its final value.

 

BTW, what's with the dst[0, 0] =  dst[0, 0]? I don't see what it's for, but in any case, it seems wrong to assign to a pixel outside the ROI. I think it could conceivably cause a problem, also (assuming it's not optimized out).  A thread could load the 0,0 pixel just before the thread assigned to that ROI updates it, then store back the old value over the updated value.

  • Upvote 1
Link to comment
Share on other sites

I'd completely forgotten about this thread.

 

Here's something for y'all to play with. It's a little map generator.

 

Sorry about the long data section. I used to have more than one palette in there.

 

Note: Render it over a black background. If you want to exclude areas of the canvas, make them blue (you can soften the edge by blurring the blue edge).

 

This became the base of my RPG world maps;

 

DMs version (lots of extra info in the layers)

world_Map_A3.jpg

 

The version the adventurers get

Olde_Worlde_Map_A3.jpg

 

Here's how the plugin UI looks, and a sample output....

 

5e_Uidemo.jpg

 

The code....

Spoiler

 


/* ========================================================================== */
/*                                                                            */
/*   ABC Perlin Noise 5e                                                      */
/*   (c) 2017 Ego Eram Reputo                                                 */
/*                                                                            */
/*   Description: Draws landscape using Hugo Elias' Value Noise routines      */
/*                                                                            */
/* ========================================================================== */

// Name: ABC Perlin Noise 5e
// Author: Ego Eram Reputo
// Submenu: Test
// URL: http://www.getpaint.net/redirect/plugins.html

#region UICode
IntSliderControl Amount1 = 50; // [1,1000] Smaller --------------------- \u2696 Scale -------------------- Larger
PanSliderControl Amount2 = Pair.Create(0.000,0.000); // Position
IntSliderControl Amount3 = 30; // [10,50] less ------------------------ \u2687 Detail ---------------------- More
IntSliderControl Amount4 = 50; // [1,200] Smoother ---------- \u2601 Elevation Variability ----------- Coarser
IntSliderControl Amount5 = 50; // [1,100] Less -------------------- \u26c5 Coverage -------------------- More
ReseedButtonControl Amount6 = 0; // [255] Reseed
CheckboxControl Amount7 = true; // [0,1] Toggle mountain shadowing on/off
#endregion

int HeightScale = 960; // was 1024;

UserBlendOps.NormalBlendOp NormalBlend = new UserBlendOps.NormalBlendOp();
UserBlendOps.MultiplyBlendOp MultiplyBlend = new UserBlendOps.MultiplyBlendOp();
UserBlendOps.AdditiveBlendOp AdditiveBlend = new UserBlendOps.AdditiveBlendOp();
UserBlendOps.DarkenBlendOp DarkenBlend = new UserBlendOps.DarkenBlendOp();

void Render(Surface dst, Surface src, Rectangle rect)
{
    ColorBgra srcBgra, ShadowColor, CurrentPixel ;
    float Width = src.Width;
    float Height = src.Height;
    float HeightMod = Height * 0.3f;
    float HalfWidth = Width * 0.5f;
    int LastVNvalue = 0;

   Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   
   int width = selection.Right - selection.Left;
   int height = selection.Bottom - selection.Top;

    try
    {
        r = new Random(Convert.ToInt32(Amount6));
        r1 = r.Next(1000, 10000);
        r2 = r.Next(100000, 1000000);
        r3 = r.Next(1000000000, 2000000000);
    }
    
    catch{}

    // Array for colorization = 32x BGR triplets
    byte [] ElevationPalette = {
//  wet	       dry
// deep blue = sea
255,095,044,
255,098,044,
255,103,046,
255,107,049,
255,112,051,
255,118,054,
255,122,056,
255,127,059,
255,133,061,
255,138,063,
255,143,065,
255,148,067,
255,153,069,
255,155,072,
255,161,075,
255,167,076,
255,172,079,
255,176,081,
255,182,084,
255,186,086,
255,191,089,
255,196,091,
255,200,093,
255,204,095,
255,208,097,
015,090,022,
015,090,022,
015,090,022,
015,090,022,
015,091,022,
015,091,022,
015,092,022,
015,092,022,
015,093,022,
015,093,022,
015,093,022,
015,094,022,
015,094,022,
015,096,022,
015,096,022,
015,097,022,
015,097,022,
015,097,022,
015,100,023,
015,101,023,
015,102,023,
015,102,023,
015,103,023,
015,103,023,
015,103,023,
015,104,023,
015,104,023,
015,106,023,
015,106,023,
015,106,023,
015,106,023,
015,106,023,
015,108,025,
015,108,025,
015,108,026,
015,108,026,
015,111,026,
015,114,028,
015,114,028,
015,114,028,
015,114,028,
015,115,030,
015,116,032,
015,116,032,
015,116,032,
015,116,033,
015,118,035,
015,118,035,
015,119,036,
015,120,036,
015,121,036,
015,123,039,
015,123,039,
015,123,039,
015,123,040,
015,124,042,
015,125,044,
015,125,044,
015,125,044,
015,126,044,
015,127,044,
015,127,044,
015,128,045,
015,128,045,
015,129,046,
015,130,047,
015,130,047,
015,130,047,
015,130,047,
015,130,047,
015,130,047,
015,130,047,
015,130,047,
015,131,048,
015,132,049,
015,133,050,
015,133,050,
015,133,050,
015,133,050,
015,133,050,
015,133,050,
015,133,050,
015,134,052,
015,135,053,
015,136,054,
015,136,054,
015,136,055,
015,136,057,
015,138,059,
015,138,059,
015,138,059,
015,138,061,
015,138,065,
015,140,067,
015,140,067,
015,140,069,
015,142,073,
015,144,075,
015,145,077,
015,145,077,
015,145,082,
015,146,086,
015,147,089,
015,147,091,
015,147,091,
015,147,094,
015,148,098,
015,150,101,
015,150,101,
015,150,103,
015,150,106,
015,151,109,
015,152,111,
015,152,111,
015,153,115,
016,154,119,
017,155,121,
018,156,122,
020,158,123,
028,164,130,
033,169,135,
036,171,138,
036,171,138,
042,175,141,
050,181,147,
054,184,150,
056,185,152,
056,185,152,
066,190,157,
075,195,164,
079,198,166,
079,198,166,
083,200,168,
094,205,175,
101,210,180,
104,212,182,
095,230,216,
103,233,227,
114,232,236,
120,231,241,
121,228,246,
117,226,245,
115,223,244,
114,221,244,
111,218,245,
109,216,246,
107,214,244,
106,212,245,
105,209,245,
103,206,245,
101,204,245,
098,202,244,
096,200,243,
096,200,244,
093,195,245,
091,193,244,
091,191,243,
088,189,245,
085,185,245,
084,185,245,
082,181,245,
081,179,244,
080,175,243,
079,172,240,
079,169,238,
080,165,237,
081,163,234,
081,161,232,
081,157,231,
082,153,229,
081,150,225,
081,147,223,
083,145,221,
081,140,219,
082,137,217,
082,133,217,
082,131,214,
082,127,213,
083,124,211,
082,122,210,
083,119,207,
083,115,204,
083,113,201,
085,110,201,
092,113,196,
100,117,192,
109,121,188,
119,123,185,
126,128,180,
137,134,175,
145,138,170,
153,140,167,
162,141,162,
167,144,157,
175,148,155,
179,153,160,
185,161,167,
189,167,172,
196,174,180,
200,180,185,
204,187,192,
208,193,199,
215,200,205,
219,206,209,
224,213,216,
229,220,222,
233,225,227,
238,232,233,
244,240,241,
249,247,247,
253,253,253,
255,255,255,
255,255,255,
255,255,255,
255,255,255,
255,255,255,
255,255,255,
255,255,255,
255,255,255,
255,255,255,
247,247,247,
236,236,236,
237,237,237,
241,241,241,
246,246,246,
250,250,250,
252,252,252,
252,252,252,
251,251,251,
251,251,251,
251,251,251,

};

    for(int y = rect.Top; y < rect.Bottom; y++)
    {
        for (int x = rect.Left; x < rect.Right; x++)
        {
            //dst[x,y]=Color.White; //.FromArgb((byte)(0xff, 0xff, 0xff, 0xff);
         CurrentPixel = src[x,y];
            
            // get Value Noise value from fractal Brownian motion (fBm) routine
            int c = (int)fBm(x,y);

            //c = (int)(c * 0.75f); // little bit of extra scaling.
            c = (int)Math.Sqrt(c * HeightScale);

            if (x==0)
            {
                //calculate height of off-canvas pixel for shadowing purposes
                int k = (int)fBm(x-1,y);
                // modify Value Noise value in same manner as (x=0, y)
                //LastVNvalue = cRm(k , Amount7);
                LastVNvalue = k; // redux 23/11
            }

            //int cVN = (c>308) ? c/4 : 77; // if below waterline (Value Noise = 308), use height = 77

            int d = c / 4; // normalize into range from 0 to 255 i.e 256 colors.

            if (CurrentPixel.B > 0)
            {
                d -= CurrentPixel.B*d/96;
            }
            if (CurrentPixel.R > 0)
            {
                d = Math.Min(255, d+(CurrentPixel.R*d/275));
            }
            if (CurrentPixel.G > 128)
            {
                    // flatten the elev
                    d -= (CurrentPixel.G-128);           
            } 
                       
            if (d>255) d= 255;
            if (d<0) d=0;
            
            d *= 3;  // byte offset in array

            // redux 23/11  d += (Amount6-1) * 3; // palette selector

            srcBgra = ColorBgra.FromBgra( ElevationPalette[d], ElevationPalette[++d], ElevationPalette[++d], 0xff);

            //   Light Direction and Shadowing:
            // Compare the current height value against the previous point's height value to find a slope/difference.
            // Draw pixels on the downside of slopes darker to fill that side with shadow.
            // Pixels on the lighter side of a slope get a slight brightening.

            int diff = (LastVNvalue - c)*c/360; // find slope between this pixel and last.

            byte r = Int32Util.ClampToByte((int)(diff * 1.299));
            byte g = Int32Util.ClampToByte((int)(diff * 1.587));
            byte b = Int32Util.ClampToByte((int)(diff * 1.114));

            if(diff > 16 && d > 8 && Amount7) // if slope > 16 and elevation is above sea level - darken these pixels
            {
                diff = Int32Util.ClampToByte(diff);
                ShadowColor = Color.FromArgb((byte)(138-diff), diff, diff, diff);
                srcBgra = MultiplyBlend.Apply(srcBgra, ShadowColor);
            }

            if(diff < -35 && d > 10 && Amount7) // if slope < -20 and elevation is above sea level - lighten these pixels
            {
                r = Int32Util.ClampToByte(srcBgra.R +10);
                g = Int32Util.ClampToByte(srcBgra.G +10);
                b = Int32Util.ClampToByte(srcBgra.B +10);
                ShadowColor = Color.FromArgb((byte)(180+diff), r, g, b);
                srcBgra = MultiplyBlend.Apply(srcBgra, ShadowColor);
            }
            
            LastVNvalue = c;    // store last Value Noise for use next time around.

            dst[x,y] = srcBgra;
        }
    }
}

// fBm = Fractal Brownian motion - a triple Value Noise routine.
double fBm(int x, int y)
{
    double k = (PerlinNoise2d(x, y) * HeightScale) * 12 / 15;
    k += (PerlinNoise2d(x + Amount6, y + Amount6) * HeightScale) * 2 / 15; // adds a bit more Noise, with much less weighting.
    k += (int)(PerlinNoise2d( x+ Amount6 / 4, y + Amount6 / 4) * HeightScale) / 15;  // adds a tiny bit more, with even less weighting.
    return k;
}


static Random r = new Random();
int r1 = r.Next(1000, 10000);
int r2 = r.Next(100000, 1000000);
int r3 = r.Next(1000000000, 2000000000);

double PerlinNoise2d(int x, int y)
{
    double total = 0.0;
    double frequency = 0.075f / Math.Sqrt(Amount1);     // was .015;    // USER ADJUSTABLE
    double persistence = (32 + Amount3 / 2) / 100.0;   // was .65;   // USER ADJUSTABLE
    double octaves = 8;           // was  8;         // USER ADJUSTABLE
    double amplitude = Amount4 / 45.0;         // was 1;       // USER ADJUSTABLE
    double cloudCoverage = -2.0 + (Amount5 / 22.0);     // was 0;   // USER ADJUSTABLE
    double cloudDensity = 0.6666666; //(Amount5 / 30.0) - 1;      // was 1;    // USER ADJUSTABLE

    for(int lcv = 0; lcv < octaves; lcv++)
    {
        total = total + Smooth(x * frequency, y * frequency) * amplitude;
        frequency *= 2;
        amplitude *= persistence;
    }

    total += cloudCoverage;
    total *= cloudDensity;

    // trying to distribute the values along a curve
    //total = total * total;

    //if(total < 0) total = 0.0;
    //if(total > 1) total = 1.0;
    //total = (total < 0) ? 0 : (total > 1) ? 1 : total;

    if (total > 1) total = 1-(total-1); // creating a downward slope from highest points
    total = (total < 0) ? 0 : total;

    return total;
}

double Smooth(double x, double y)
{
    double n1 = Noise((int)x, (int)y);
    double n2 = Noise((int)x + 1, (int)y);
    double n3 = Noise((int)x, (int)y + 1);
    double n4 = Noise((int)x + 1, (int)y + 1);

    double i1 = Interpolate(n1, n2, x - (int)x, 1);
    double i2 = Interpolate(n3, n4, x - (int)x, 1);

    return Interpolate(i1, i2, y - (int)y, 1);
}

double Noise(int x, int y)
{
    int n = x + y * 57;
    n = (n<<13) ^ n;

    return ( 1.0 - ( (n * (n * n * r1 + r2) + r3) & 0x7fffffff) / 1073741824.0);
}


double Interpolate(double x, double y, double a, int iType)
{
    double iVal, val;

    switch (iType)
    {
        case 0: // Linear_Interpolate
	       iVal = x*(1-a) + y*a;
        break;

        case 1:     // Cosine_Interpolate
            val = (1 - Math.Cos(a * Math.PI)) * .5;
            iVal = x * (1 - val) + y * val;
        break;
/*
        case 2:     // Sine_Interpolate = blocky.
            val = (1 - Math.Sin(a * Math.PI / 2)) * .5;
            iVal = x * (1 - val) + y * val;
        break;

        case 3: // Cubic Interpolate = dark & blocky
	       iVal = Math.Pow(x,2) + Math.Pow(y,2) + x ;
        break;

        case 4: // Sinh Interpolate = blocky
	       iVal = Math.Sinh(x) + Math.Sinh(y) ;
        break;
*/
        default:
        iVal = 0;
        break;
    }
    return iVal;
}

 

 

 

 

Edited by Ego Eram Reputo
fixed image links
  • Like 1
  • Upvote 2
Link to comment
Share on other sites

@xod This plugin is very promissing. I just tested it and I liked it. 

 

There is one feature that I like and can be a great feature for this effect.

 

Look at my example : I made a "Top left" alignment for the apple at the top. Then I selected another area in the canvas and repeated the alignment (Ctrl +F) and the apple was correctly aligned in the new selection.

 

I wonder if the "Repeat alignment"  could be applied to several selections so that the apple would be placed in several selected areas and not just one. (the grid layer is just for a guideline). 

apple-alignment-5375170.png

  • Like 2
Link to comment
Share on other sites

I understand xod. Thanks anyway.

 

But if someone could figure it out would be a great addition to the alignment effects. When I need to align an object inside a selection I usually use MJW's  "Paste from clipboard" effect which will align whatever is in the clipboard. It does center the object inside a selection but it does not have other types of alignments though the object can be moved around.

Link to comment
Share on other sites

Thanks @MadJik for compiling @Ego Eram Reputo 's mapper plugin.  Thanks for sharing the plugin EER!   :)

 

Can be used to create quick planets, also.  I left the original color, but the color could be changed easily.

 

ABCperlinnoise.png

 

Link to comment
Share on other sites

I saw your reply & gave you +1 ;) I have no issues with you passing on the dll.

 

@lynxster4 This little mapper became the base for Planetoid - so what you're doing with it is exactly how I intended it to be used:  2D and 3D mapping.

 

Link to comment
Share on other sites

Wow, @xod    This is super easy to use!  Nice clean interface.  Thank you!   :)

Link to comment
Share on other sites

13 hours ago, xod said:

This is my first plugin based on the Visual Studio Template provided by EER.

 

Its beautiful. I really like this. Well done xod.

 

Enhancements:

 

1. Any chance you could add some tool tips? I feel any control that doesn't explain its function with a text label should have a tooltip.

 

aligntooltip.png

 

2. Change the icon to gray with blue arrows, so it looks like your UI.

 

3. Add this into a new file called PDNSupport.cs (obviously change the red details to your own)

using System;
using PaintDotNet;
using System.Reflection;

namespace TileWorld
{

    public class PluginSupportInfo : IPluginSupportInfo
    {
        public string Author
        {
            get
            {
                return "Scott Stringer aka Ego Eram Reputo";
            }
        }
        public string Copyright
        {
            get
            {
                return "© 2017 Scott Stringer";
            }
        }

        public string DisplayName
        {
            get
            {
                return "TileWorld";
            }
        }

        public Version Version
        {
            get
            {
                return base.GetType().Assembly.GetName().Version;
            }
        }

        public Uri WebsiteUri
        {
            get
            {
                return new Uri("http://www.getpaint.net/redirect/plugins.html");
            }
        }
    }

}

^^ That adds your plugin data to the tooltip when you hover on it in the pdn menu. At the moment nothing shows up.

 

This is an omission I've been meaning to add to the template. I've got it added, but haven't rolled it out yet.

 

To get it to work, you need to add a reference in your Align.cs file. Immediately following the namespace, add the new line...

namespace Align
{
    [PluginSupportInfo(typeof(PluginSupportInfo), DisplayName = "Align")]

 

Results:

 

aligntooltipdemo.png

 

 

  • Upvote 1
Link to comment
Share on other sites

1 hour ago, Ego Eram Reputo said:

Immediately following the namespace, add the new line...

Technically, it goes on the line preceding the Effect class, as it's an Attribute decoration of that class.

 

Also, you don't need to use the constructor with DisplayName in it, as it can just get that from your implementation of IPluginSupportInfo. No need to type the name twice. :P

[PluginSupportInfo(typeof(PluginSupportInfo))]
class MyEffect: Effect
{

 

 

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

@Eli, you're right, but this plugin has a lot of problems.

 

1. If you use Magic Wand and select the entire canvas less the object and run an alignment the object is basically copied although nothing should happen.

 

2. If there are two objects per layer and one selection is created for one object and then a alignment is run, the other object will be brought in the selection.

I think the approach has to be completely changed and the code has to be rewritten from scratch.

 

EER, thank you for your suggestions and information.

Edited by xod
Link to comment
Share on other sites

@toe_head2001 - thanks for the info. I'll update the template. I might actually get to roll it out over my Christmas holidays.

 

5 hours ago, xod said:

1. If you use Magic Wand and select the entire canvas less the object and run an alignment the object is basically copied although nothing should happen.

 

Corner cases. Everyone misses them when they're starting out :mrgreen:

 

5 hours ago, xod said:

2. If there are two objects per layer and one selection is created for one object and then a alignment is run, the other object will be brought in the selection.

 

You need to blit the relocated selection object onto a copy of the source layer which has had the selection object erased. What you're describing sounds like you're moving the entire layer based on the location of the target object.

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...