Sign in to follow this  
xod

Unfinished plugins

Recommended Posts

xod    178

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

Share this post


Link to post
Share on other sites
Seerose    1,965

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

Share this post


Link to post
Share on other sites
xod    178

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

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this