Jump to content
How to Install Plugins ×

Squirkle


Red ochre

Recommended Posts

This will render 'squirkle' shapes eg. from rounded lozenge through circle to square. It is different from 'rounded rectangle' as there is curvature in the 'flat' sides.

Probably best to see the screenshot below!

With a range of line and background colours, including transparent, it should be useful for frames, buttons and vignettes.

Now in the updated Red ochre plugin pack

I have changed the default shape setting to circle, because I found it more convenient!

(the .dll is only available in the pack now, the updated version now has the same name as the original version. The first version has the word 'middle' spelled as 'midddle', other than that, they are the same.)

Here is the code lab code too.

Hidden Content:

/* =================================================== */
/*	 */
/* squirkle    */
/* (c) 2011 Red Ochre	 */
/*	 */
/* Description: produces square/circle shapes	 */
/*	 */
/* ========================================== ======== */
// Name: squirkle
// Author: Red ochre (John Robbins)
// Submenu: Render
// URL: http://www.getpaint.net/redirect/plugins.html
// Title: Squirkle										 Feb 2012 Red Ochre

#region UICode
Pair<double, double> Amount1 = Pair.Create( 0.0 , 0.0 ); // middle
double Amount2 = 0; // [-90,90] angle (degrees)
double Amount3 = 0; // [-1,1] wide ...													  ...tall
double Amount4 = 2.5; // [0.5,20] exponent
double Amount5 = 2; // [0,10] size
byte Amount6 = 0; // line properties|primary color|secondary color|transparent|source image|inverted source|blue|cyan|green|yellow|red|magenta
byte Amount7 = 0; // background properties|secondary color|primary color|transparent|source image
int Amount8 = 10; // [0,200] line width
bool Amount9 = false; // [0,1] solid middle
bool Amount10 = true; // [0,1] smoothing
#endregion
void Render(Surface dst, Surface src, Rectangle rect)
{   ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
   ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
   ColorBgra cp;    // current pixel
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

   double X,Y;
   int H = selection.Bottom - selection.Top;
   int W = selection.Right - selection.Left;
   int small = H;if(H < W){small = W;}//smallest side
   double deg90 = Math.PI /2;
   double angle = (Amount2 * deg90/ 90);
   double sina = Math.Sin(angle);
   double sinb = Math.Sin(deg90 - angle);
   double cosa = Math.Cos(angle);
   double cosb = Math.Cos(deg90 - angle);
   double dx = (W / 2) * (1 + Amount1.First);
   double dy = (H / 2) * (1 + Amount1.Second);
   int Ox = (int)(selection.Left + dx );// horizontal position (moveable)
   int Oy = (int)(selection.Top + dy );// vertical position (moveable)
   double xrat = 1 + Amount3;
   double yrat = 1 - Amount3;// length and height multipliers
   double exp = Amount4;//exponent (power)
   int rf = (int)(Amount5 * small/10);// radius factor
   int lw = Amount8 ;// line width
   if(lw >= rf){lw = rf;}// to stop negative radius
   int B,G,R,A;
   int lb = PrimaryColor.B, lg = PrimaryColor.G,lr = PrimaryColor.R,la = PrimaryColor.A; // otherwise says values not assigned?
   int bb = SecondaryColor.B, bg = SecondaryColor.G, br = SecondaryColor.R, ba = SecondaryColor.A;

   for (int y = rect.Top; y < rect.Bottom; y++)
   {
    for (int x = rect.Left; x < rect.Right; x++)
    {
	    // assign line and background colours
	    cp = src[x,y];
	    B = (int)cp.B;G = (int)cp.G;R = (int)cp.R;A = (int)cp.A;
	    switch (Amount6)// line properties
		   {case 0: lb = PrimaryColor.B; lg = PrimaryColor.G; lr = PrimaryColor.R; la = PrimaryColor.A;break;    //line colour = primary colour default black
		    case 1: lb = SecondaryColor.B; lg = SecondaryColor.G; lr = SecondaryColor.R;la = SecondaryColor.A;break;    //secondary colour
		    case 2: lb = 0; lg = 0; lr = 0; la = 0;break;    // transparent
		    case 3: lb = B; lg = G; lr = R; la = A;break;    // as original source
		    case 4: lb = 255 - B; lg = 255 - G; lr = 255 - R; la = 255 ;break;    // inverted source
		    case 5: lb = 255;lg = 0;lr = 0; la = 255;break;// blue
		    case 6: lb = 255;lg = 255;lr = 0;la = 255;break;//cyan
		    case 7: lb = 0;lg = 255; lr = 0; la = 255;break;//green
		    case 8: lb = 0;lg = 255;lr = 255;la = 255;break;//yellow
		    case 9: lb = 0;lg = 0;lr = 255;la = 255;break;//red
		    case 10: lb = 255;lg = 0;lr = 255; la = 255;break;//magenta
		    }
		 switch (Amount7)//background properties
		   {case 0: bb = SecondaryColor.B; bg = SecondaryColor.G; br = SecondaryColor.R; ba = SecondaryColor.A;break;    //background colour = secondary colour default white
		    case 1: bb = PrimaryColor.B; bg = PrimaryColor.G; br = PrimaryColor.R; ba = PrimaryColor.A;break;    // primary
		    case 2: bb = B; bg = G; br = R; ba = 0;break;    //transparent
		    case 3: bb = B; bg = G; br = R; ba = A;break;    // as original source
		    }
	    // set BGRA values to background values
		 B = bb;G = bg;R = br;A = ba;

	    // work out X & Y co-ordinates with rotation
		 int cX =  + x  - Ox;  
		 int cY =  - (y  - Oy) ; //moving but not rotating
		 X = ((cX * cosa) + (-cY * cosb)) * xrat;// moving and rotating
		 Y = ((cX * sina) + (cY * sinb)) * yrat;// now X and Y are doubles and wide tall included


	    // SQUIRKLE
		  double xP = Math.Pow(Math.Abs(X),exp);
		  double yP = Math.Pow(Math.Abs(Y),exp);
		  int ro = rf + lw;
		  int ri = rf - lw;
		  int ro1 = rf + lw + 1;
		  int ri1 = (rf - lw) - 1;
		  double squirk = Math.Pow(xP + yP,1/exp);


		 if(!Amount9 && squirk >= ri && squirk <= ro){B = lb;G = lg;R = lr;A = la;}//ring line


		 if((Amount9)&&(squirk <= ro)){B = lb;G = lg;R = lr;A = la;}//solid


		    // smoothing
		 if(Amount10)
	    {
		  double rat = squirk - (int)(squirk);
		  double irat = 1 - rat;
		    // outer
		  if(squirk <= ro1 && squirk > ro)
			    {
				 B = (int)((irat * lb) + (rat * bb));
				 G = (int)((irat * lg) + (rat * bg));
				 R = (int)((irat * lr) + (rat * br));
				 A = (int)((irat * la) + (rat * ba));
			    }

		    // inner
		  if(!Amount9 && squirk < ri && squirk >= ri1)
			    {
				 B = (int)((rat * lb) + (irat * bb));
				 G = (int)((rat * lg) + (irat * bg));
				 R = (int)((rat * lr) + (irat * br));
				 A = (int)((rat * la) + (irat * ba));
			    }
		 }

	    // re assemble
	    cp = ColorBgra.FromBgra( Int32Util.ClampToByte(, Int32Util.ClampToByte(G), Int32Util.ClampToByte(R), Int32Util.ClampToByte(A));
	    dst[x,y] = cp;
    }
   }
}

Enjoy ;)

All feedback appreciated (well hopefully !)

squirklescreenshot800by600.jpg

Edited by Red ochre
  • Upvote 1

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Very nice! Cool things happen with the exponent setting turned down low.

Thanks :star:

(where did squirkle come from?)

Link to comment
Share on other sites

Looks really useful Red Ochre. I'll give it a shot & post my thoughts/efforts when they are done. Many thanks in advance for all your hard work :D

THiGVp.png

Knowledge is no burden to carry.

 

April Jones, 2012

 
Link to comment
Share on other sites

Squirkle: Square+circle :D like the name <downloads>

No, Paint.NET is not spyware...but, installing it is an IQ test. ~BoltBait

Blend modes are like the filling in your sandwich. It's the filling that can change your experience of the sandwich. ~Ego Eram Reputo

Link to comment
Share on other sites

Thank you all, for the positive reaction :D. - really appreciated.

'Squirkle', - Pdnnoob got it - I thought Squirkle is more 'quirky', and phonetically more logical than squircle.

I'd been reading a book by Alex Bellos called 'Alex's adventures in numberland', that descibes how the French mathematician Gabriel Lame, in 1818, started experimenting with values of the exponents in the circle formula. You know "the sum of the 2 squares equals the square hippopotamus" :P.

If the exponent is 1 it's a diamond, 2 is a circle, 2.5 was named a 'superellipse' by Piet Hein (Danish Architect), and as the exponent approaches infinty, it becomes a square. - I don't know of name when the value is less than 1.

I thought I'd try and program it into codelab and thought the results could be quite useful. Pdn has the advantage over all other graphics programs that I have tried, because of codelab - for a novice like me, it's far more accessible than VS studio and I can actually produce something useful !.

  • Upvote 1

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

  • 2 months later...

I like this. I can see that I am going to have a lot of fun with this. My only issue is that sometimes you can see the join. Who knows maybe I am being too finicky.

post-88404-132783231067_thumb.png

  • Upvote 1
signature1small.png
Link to comment
Share on other sites

I like this. I can see that I am going to have a lot of fun with this. My only issue is that sometimes you can see the join. Who knows maybe I am being too finicky.

Hello JadedLemon,

No you're not too finicky - just observant - that's good! ;)

I've just fixed the problem and am attaching a slightly updated version below - I won't update the version in the pack until I've sorted out the edge smoothing when the squirkle is angled.

Incidentally the problem was that when changing from a 'double' (eg. 1. 7) to an 'integer' the number is always rounded down and becomes 1, by simply adding 0.5 it now rounds 1.7 into the integer 2. - solving the problem.

As for the edge smoothing when it's angled - I'll have to have a think! :/

Anyway thanks for reporting back - I hope the beta version is useful and please try the recently improved 'squirklewarp' (in the pack) too.

Cheers

16th March 2012 - the updated version is now in the pack - the edge smoothing is better now! - so removing the 'beta' :)

- I changed that awkward integer into a double for this version ;)

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Ooops. I thought you knew about it or I would have screenshot that for you some time ago ... (Note to self, dont assume ...)

- I only did this one as a bit of fun really - and assumed that problem was to do with the edge smoothing :lol:

Quite nicely surprised that particular problem was so easy to solve!

Anyway I got into the more exciting 'squirklewarp' and forgot about this one - but I assume it is more important now as it compliments squirklewarp.

I'll do some more work on it soon ;)

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

  • 2 years later...

I have only tried one other plugin, so maybe it is a user ignorance issue, but this does not seem to be working on the beta of paint 4.0, at least it doesn't show under effects for me which is where i assume I should look.

 

Also what I was hoping this tool might do is draw a circle from the center out, is that what it does? I can't tell from the description.

 

 

UPDATE: I can now answer my own questons, it does work in 4.0 (under effects > Render) and you can use it to make concentric circles. However I now will sound nitpicky, but it leaves a bunch of dots/lines around each circle for some reason requiring lots of fix up time to get the circle looking nice, so not really what I was hoping for, it is however very cool for making neat shapes which was it's purpose.

Edited by circlularthinking
Link to comment
Share on other sites

  • 3 weeks later...

Hello 'circular thinking' or is circlular? :)

Squirkle doesn't use the 'G.D.I' - which meant I had to do the edge smoothing (anti-aliasing) myself - which is why it isn't perfect!

I have just published a plugin called 'Slinky' which easily draws concentric (and more interestingly eccentric) ellipses and circles. This does use the 'G.D.I' - so, smoothing was just one line of code - much easier!
I hope it is relevant for your purpose - the link is here:http://forums.getpaint.net/index.php?/topic/28267-slinky-eccentric-ellipses-new-21st-april-2014/

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

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