Sign in to follow this  
zoonel

CellMaker Rev

Recommended Posts

Hi, this is a modified version of the Cellmaker plugin by Ego Eram Reputo.
Use Effects->Render->CellMaker Rev
CellMakerRev.zip

I needed to see the center of borders, so i quickly learned how to write a plugin (thanks to codelab;)). Reading the original post and answers i used the MadJik's coding approach for efficiency.
Here is what it does:

It simply makes a grid of cells within a given selection. There are three corner options, hard, soft (corner pixels are removed) and rounded (three of the corner pixels are removed for a rounded look).


+ entire/not entire cells option
+ choose start grid reference
+ move grid
+ show borders centers
+ a lot faster then the original plugin
- it has the same flaw of the original plugin:
Hidden Content:
The plugin checks only if the 4 corners are visible to draw a cell. So this may happen.
37642_3c8adf73aacc43b5f2a85caf86568a16


A picture to show the possibilities
file.php?id=5267&mode=view
Hidden Content:
37642_dc2bdde05a9faea7dc2928a089e204eb


And the source Code in codelab
Hidden Content:
// CellMaker Rev v1.0
// (CellMaker plugin (by Ego Eram Reputo) modified by MadJik remodified by X).
//
// Makes a grid of cells inside a given selection.
// The selection may be more than one area.
// Cell walls drawn in Primary color.
//
#region UICode
int Amount1=12; // [2,255] Cell Width
int Amount2=12; // [2,255] Cell Height
int Amount3=0; // [0,2] Corners: Hard, Soft, Rounded
bool Amount4 = false; // [0,1] Draw borders centers
bool Amount5 = true; // [0,1] Draw only entire Cells
bool Amount6 = true; // [0,1] Draw grid from top left of selection
int Amount7=0; // [-128,128] Move Horizontaly
int Amount8=0; // [-128,128] Move Verticaly
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{

// Other variables
PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
ColorBgra Pix;

int Top, Top2, Bottom, Bottom2, Left, Left2, Right, Right2, CellWidth, W2, CellHeight, H2;
bool IsLeft, IsTop, IsIncluded ;
bool L2T2,LT2,RT2,L2T=false,LT,RT,L2B,LB,RB;
CellWidth = (int) Amount1 + 1 ;
CellHeight = (int) Amount2 + 1;
W2 = (int)(Amount1/2) + 1;
H2 = (int)(Amount2/2) + 1;
//!! c# doesnt do the proper negative modulo
//int XOffset = -selection.Left % CellWidth;
//int YOffset = -selection.Top % CellHeight;
int XOffset = (CellWidth - (selection.Left + Amount7 ) % CellWidth) % CellWidth;
int YOffset = (CellHeight - (selection.Top + Amount8 ) % CellHeight) % CellHeight;
// Clear the canvas in the case of changed parameters
for(int y = rect.Top; y < rect.Bottom; y++)
for (int x = rect.Left; x < rect.Right; x++)
dst[x,y] = src[x,y];

// Loop through all the cells in the selection
for(int y = rect.Top; y < rect.Bottom; y++)
{
Top = (int)( y / CellHeight ) * CellHeight ;
if(Amount6)
{
Top -= YOffset ;
if(y >= Top + CellHeight)
Top += CellHeight;
}
Bottom = Top + CellHeight;
Top2 = Top - CellHeight ;
//Bottom2 = Bottom + CellHeight;
IsTop = y==Top;
for (int x = rect.Left; x < rect.Right; x++)
{

IsIncluded = !Amount5;
// Find the values for each of the cell vertices
Left = (int)( x / CellWidth ) * CellWidth;
if(Amount6)
{
Left -= XOffset;
if(x >= Left + CellWidth)
Left += CellWidth;
}
Right = Left + CellWidth;
Left2 = Left - CellWidth;
//Right2 = Right + CellWidth;
IsLeft = x==Left;
Pix = src[x,y];

// Test if the Cell is included in the selection
// Extra checks for borders and angles
// Try to minimize IsVisible calls
if(Amount5)
{
if(selectionRegion.IsVisible(Left,Top))
{
RT = selectionRegion.IsVisible(Right, Top);
LB = selectionRegion.IsVisible(Left, Bottom);
RB = selectionRegion.IsVisible(Right, Bottom);
IsIncluded = RT && LB && RB ;
if(!IsIncluded && IsLeft)
{
L2T = selectionRegion.IsVisible(Left2,Top);
L2B = selectionRegion.IsVisible(Left2, Bottom);
IsIncluded = L2T && L2B && LB ;
}
if(!IsIncluded && IsTop)
{
LT2 = selectionRegion.IsVisible(Left, Top2);
RT2 = selectionRegion.IsVisible(Right, Top2);
IsIncluded = RT && LT2 && RT2 ;
if(!IsIncluded && IsLeft)
{
L2T2 = selectionRegion.IsVisible(Left2, Top2);
IsIncluded = L2T && L2T2 && LT2 ;
}
}
}
}
if (IsIncluded)
{
// tests for the crossings effects
switch (Amount3)
{
case 0: // Easy: just test if we are on the grid, draw PrimaryColor
if (IsLeft||IsTop) Pix = PrimaryColor;
break;
case 1: // Corner level 1, one x or y must be on the grid but not the both!
if (IsLeft^IsTop) Pix = PrimaryColor;
break;
case 2: // Corner level 2, more test to define if we need to draw the pixel!
if (IsLeft) { if ((Math.Abs(y - Top)>1)&&(Math.Abs(y - Bottom)>1)) Pix = PrimaryColor; }
else if (IsTop) { if ((Math.Abs(x - Left)>1)&&(Math.Abs(x - Right)>1)) Pix = PrimaryColor; }
else if (( ( ((y - Top)==1) || ((Bottom - y)==1) ) ) && ( ((x - Left)==1) || ((Right - x)==1) ) ) Pix = PrimaryColor;
break;
default:
break;
}
// Draw the centers of borders
if(Amount4 && !IsLeft && !IsTop && ( ((y == (Top + H2) || y == (Bottom - H2)) && (x==(Left+1) || x==(Right-1))) || ((x == (Left + W2) || x == (Right - W2)) && (y==(Top+1) || y==(Bottom-1))) ) ) Pix = PrimaryColor;
}
dst[x,y] = Pix;
}
}
}


ps: I took the same icon as original plugin, and copy some code from ego eram reputo and MadJik. If this is not allowed i'll delete what's needed.
ps2: I still dont quite understand how some functions works. I've seen a lot of
for (int y = rect.Top; y < rect.Bottom; y++)
{
for (int x = rect.Left; x < rect.Right; x++)
{
if(selectionRegion.IsVisible(x,y))

But the plugins only works within selected region, so why do that?
Also is there a similar function as selectionRegion.IsVisible(x,y) for segments or areas, because calling IsVisible for a lot pixel is very slow.
Thx Edited by Ego Eram Reputo
Updated link to original

Share this post


Link to post
Share on other sites
I took the same icon as original plugin, and copy some code from ego eram reputo and MadJik. If this is not allowed i'll delete what's needed.

It might have been worthwhile to create a new icon - but I have no special attachment to the one I used. Be my guest and use it and the code as you like.

Yes the IsVisible test is slow, and no it's not really necessary as each pixel, by definition, is inside the current selection.

I like your enhancements! For a first time this is a pretty impressive effort. Bravo!

Share this post


Link to post
Share on other sites

Would it be possible to add a couple of features to this effect?

1. an adjustable line thicknes

2. adjustable rounded corners

 

To make somethink like this :

cellmaker-request-527cbdd.png

 

 

Share this post


Link to post
Share on other sites

That would require quite a rewrite. I'll put it on my list of things to do (which is looong ).

In the short term you might be better to tile a single cell created with the Shapes tool. Rick has added corner radius as an option to the rounded rectangle shape, an of course Shapes support line thickness.

Share this post


Link to post
Share on other sites

That would be nice. Actually I did use tiling and the rounded rectangle tool tool shape to create the above picture. Another feature that I like of this effect is that the cells can be created inside an irregular selection. I will be patient and wait. :) 

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