Jump to content

Negative Coordinates, with 0,0 being the center of an image?


Recommended Posts

Hello.  

 

I love Paint.net and have been using it for several years.  Thank you for the great software.

 

I am working on a new project, a Minecraft map, and it would help immensely to have the center of the image I'm editing read as 0,0.  This way, I can hover over a portion of the image (it's a top-down view of a world) and be able to easily see where I need to go in-game to check it out.

 

Of course, 0,0 in Paint.net is the upper-left corner of the image (and this is "correct" for 99.99% of applications.)

 

Minecraft spawn is 0,0 and extends into the negatives in the south and west directions and into the positive in the north and east.

 

I realize I could use a calculator, but a small addition or addon would be extremely helpful.  It might even make Paint.net the editor of choice for other Minecraft map makers and I bet it would have other applications as well.

 

Thanks for your time and consideration.

Link to comment
Share on other sites

This plugin could help: http://forums.getpaint.net/index.php?showtopic=15476

 

Add a new layer and create a graph with two vertical and two horizontal cells. Adjust the layer blend mode so you can see the map through it. Lines cross in the center.

 

EDIT: it just occurred to me you are looking for coordinates and not just the center. In that case, I don't think a plugin is allowed to tamper with those things. Sorry.

 

EDIT 2: you can try editing your minecraft map with 0,0 in the upper left instead. The absolute value of the coordinates in minecraft will then correspond to the pixel coordinates in Paint.net. You can use command blocks to set the player's spawn point somewhere else if need be.

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

 

Yes, that unfortunately is not quite what I'm after.  I do indeed want a Cartesian coordinate display.  It doesn't have to replace the existing status bar display... an additional display would be perfectly fine.

 

As far as setting the world's spawn point, I am currently doing this with a mod called PerfectSpawn.  It allows me to set the spawn point to a fixed value, and eliminate any "fuzzing" that the game does when a new player spawns.  This is only a workaround though, and hopefully a temporary one.  Spawn will need to bet set at 0,0 once the map is finished.  Also, if I edit other maps with different sizes, I'll have to keep changing the config of PerfectSpawn for testing... then again when I'm ready to playtest it.

 

I'll keep having a look at the Plugins page though.  Thanks for your help.

Link to comment
Share on other sites

How about this:

1. Add a new transparent layer :LayersAddNewLayer: above your map.

2. Mark the center of this layer with the pixel you want to be at (0,0). Use a color easily distinguishable - red in the example below.

3. Activate the rectangle select tool :RectangleSelectTool:

4. Place the cursor on the newly defined origin and drag out a selection to the destination. The offset will be shown in the tool bar. You will have to mentally add the negative sign yourself

yhsjjie_175.png

Here the destination is (-73, -41)

Link to comment
Share on other sites

Thanks, Ego Eram Reputo!

 

A very solid workaround.  I should have thought of that.

 

I've been fighting with the syntax of If/Then statements in Excel to do the calculations... assuming a 5000x5000 image, my syntax was something like "If A1 < 2500, Then A1-2500."  It's hurting my brain.  (Feel free to comment if you're handy with Excel, too!  :P )

 

Thanks again.  If I can't get this spreadsheet method to work pretty soon, I'll just use your dragging method.  

Link to comment
Share on other sites

Here's the CodeLab script:

Spoiler

// Name: Coordinate Plane
// Submenu: Render
// Author: toe_head2001
// Title:
// Version: 0.1
// Desc:
// Keywords:
// URL:
// Help:
#region UICode
IntSliderControl Amount1 = 100; // [10,1000] Step
#endregion

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;
    int step = Amount1;
    int horLoops = (int)Math.Ceiling(selection.Width / (float)step);
    int verLoops = (int)Math.Ceiling(selection.Height / (float)step);
    int leftEdge = centerX - step * (horLoops / 2);
    int topEdge = centerY - step * (verLoops / 2);

    dst.CopySurface(src, rect.Location, rect);

    using (RenderArgs ra = new RenderArgs(dst))
    {
        Graphics plane = ra.Graphics;
        plane.TextRenderingHint = TextRenderingHint.AntiAlias;
        plane.Clip = new Region(rect);

        using (SolidBrush overlayBrush = new SolidBrush(Color.FromArgb(150, Color.White)))
        {
            plane.FillRectangle(overlayBrush, selection);
        }
        
        Point point = new Point();
        using (Pen planePen = new Pen(Color.Red, 2))
        using (SolidBrush textBrush = new SolidBrush(Color.Black))
        using (Font textFont = new Font("Arial", 8, FontStyle.Regular))
        {
            for (int y = 0; y < verLoops; y++)
            {
                for (int x = 0; x < horLoops; x++)
                {
                    point.X = leftEdge + step * x;
                    point.Y = topEdge + step * y;
                    plane.DrawEllipse(planePen, point.X, point.Y, 1, 1);
                    plane.DrawString((point.X - centerX).ToString() + ", " + ((point.Y - centerY) * -1).ToString(), textFont, textBrush, point);
                }
            }
        }
    }
}

 

UPDATE: You can get this plugin in my Plugin Pack.

(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

Thanks again, toe_head2001!

 

Fantastic work.  I really appreciate it.

 

It was easy to install CodeLab and just as simple to build your script.

 

While I would still love to see an addon developed that simply outputs the Cartesian coordinates of the cursor (as it would be less intrusive and more precise), this script will work perfectly for my application (as I don't need absolute precision and toggling the layer's visibility is trivial to do.)

 

Thank you very much!

 

Edit:  P.S.  I just edited your code a bit, changing the white overlay translucency from 150 to 0 and now I find it to be even better.  :)  Also a very simple adjustment.  Very satisfied. 

Edited by dracho
Link to comment
Share on other sites

P.S.  I just edited your code a bit, changing the white overlay translucency from 150 to 0 and now I find it to be even better.   :)  Also a very simple adjustment.  Very satisfied.

If you're going to set it to 0, you might as well just delete that entire code block (those 4 lines).

(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

  • 1 year later...

Hello, toe_head2001 it's me again.  Working on the same project (a few iterations down the road.)  I was wondering if it's possible to center 0,0 on the bottom left corner of the image, instead of the center.  Thanks again!  :)

Link to comment
Share on other sites

On 6/11/2016 at 9:52 PM, toe_head2001 said:

Here's the CodeLab script:

  Reveal hidden contents


// Name: Coordinate Plane
// Submenu: Render
// Author: toe_head2001
// Title:
// Version: 0.1
// Desc:
// Keywords:
// URL:
// Help:
#region UICode
IntSliderControl Amount1 = 100; // [10,1000] Step
#endregion

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;
    int step = Amount1;
    int horLoops = (int)Math.Ceiling(selection.Width / (float)step);
    int verLoops = (int)Math.Ceiling(selection.Height / (float)step);
    int leftEdge = centerX - step * (horLoops / 2);
    int topEdge = centerY - step * (verLoops / 2);

    dst.CopySurface(src, rect.Location, rect);

    using (RenderArgs ra = new RenderArgs(dst))
    {
        Graphics plane = ra.Graphics;
        plane.TextRenderingHint = TextRenderingHint.AntiAlias;
        plane.Clip = new Region(rect);

        using (SolidBrush overlayBrush = new SolidBrush(Color.FromArgb(150, Color.White)))
        {
            plane.FillRectangle(overlayBrush, selection);
        }
        
        Point point = new Point();
        using (Pen planePen = new Pen(Color.Red, 2))
        using (SolidBrush textBrush = new SolidBrush(Color.Black))
        using (Font textFont = new Font("Arial", 8, FontStyle.Regular))
        {
            for (int y = 0; y < verLoops; y++)
            {
                for (int x = 0; x < horLoops; x++)
                {
                    point.X = leftEdge + step * x;
                    point.Y = topEdge + step * y;
                    plane.DrawEllipse(planePen, point.X, point.Y, 1, 1);
                    plane.DrawString((point.X - centerX).ToString() + ", " + ((point.Y - centerY) * -1).ToString(), textFont, textBrush, point);
                }
            }
        }
    }
}

 

UPDATE: You can get this plugin in my Plugin Pack.

Hello, toe_head2001 it's me again.  Working on the same project (a few iterations down the road.)  I was wondering if it's possible to center 0,0 on the bottom left corner of the image, instead of the center.  Thanks again!  

Link to comment
Share on other sites

35 minutes ago, dracho said:

I was wondering if it's possible to center 0,0 on the bottom left corner of the image, instead of the center. 

 

Oh sure, that should be easy. I'll work on it tomorrow.

(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

@dracho, how this?

 

Spoiler

// Name: Coordinate Plane Points
// Submenu: Render
// Author: toe_head2001
// Title:
// Version: 1.1
// Desc: Generates center-based coordinate plane points
// Keywords:
// URL:
// Help:
#region UICode
IntSliderControl Amount1 = 100; // [25,1000] Step
IntSliderControl Amount2 = 150; // [0,255] Overlay
PanSliderControl Amount3 = Pair.Create(0.00,0.000); // Center
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    Point center = new Point
    {
        X = ((selection.Right - selection.Left) / 2) + selection.Left,
        Y = ((selection.Bottom - selection.Top) / 2) + selection.Top
    };
    Point offset = new Point
    {
        X = (int)(center.X + center.X * Amount3.First),
        Y = (int)(center.Y + center.Y * Amount3.Second)
    };
    int horLoops = (int)Math.Ceiling(selection.Width / (float)Amount1);
    int verLoops = (int)Math.Ceiling(selection.Height / (float)Amount1);    
    int leftEdge = (offset.X - selection.Left) % Amount1;
    int topEdge = (offset.Y - selection.Top) % Amount1;

    dst.CopySurface(src, rect.Location, rect);

    using (Graphics plane = new RenderArgs(dst).Graphics)
    {
        plane.TextRenderingHint = TextRenderingHint.AntiAlias;
        plane.Clip = new Region(rect);

        using (SolidBrush overlayBrush = new SolidBrush(Color.FromArgb(Amount2, Color.White)))
        {
            plane.FillRectangle(overlayBrush, selection);
        }

        Point point = Point.Empty;
        string pointText;
        SizeF pointTextSize;
        using (SolidBrush pointBrush = new SolidBrush(Color.Red))
        using (SolidBrush textBrush = new SolidBrush(Color.Black))
        using (Font textFont = new Font("Arial", 8, FontStyle.Regular))
        {
            for (int y = 0; y < verLoops; y++)
            {
                for (int x = 0; x < horLoops; x++)
                {
                    point.X = leftEdge + Amount1 * x;
                    point.Y = topEdge + Amount1 * y;

                    plane.FillRectangle(pointBrush, point.X - 1, point.Y - 1, 3, 3);

                    pointText = (point.X - offset.X).ToString() + ", " + ((point.Y - offset.Y) * -1).ToString();
                    pointTextSize = plane.MeasureString(pointText, textFont);
                    if (pointTextSize.Width >= Amount1)
                        pointText = (point.X - offset.X).ToString() + ",\n" + ((point.Y - offset.Y) * -1).ToString();
                    plane.DrawString(pointText, textFont, textBrush, point);
                }
            }
        }
    }
}

 

 

There's a Preview button in CodeLab these days. :)  If you're satisfied with how it works, you can build a DLL file.

CodeLab-previewButton.png

(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

HF1WDe8.png

27 minutes ago, toe_head2001 said:

@dracho, how this?

 

  Hide contents


// Name: Coordinate Plane Points
// Submenu: Render
// Author: toe_head2001
// Title:
// Version: 1.1
// Desc: Generates center-based coordinate plane points
// Keywords:
// URL:
// Help:
#region UICode
IntSliderControl Amount1 = 100; // [25,1000] Step
IntSliderControl Amount2 = 150; // [0,255] Overlay
PanSliderControl Amount3 = Pair.Create(0.00,0.000); // Center
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    Point center = new Point
    {
        X = ((selection.Right - selection.Left) / 2) + selection.Left,
        Y = ((selection.Bottom - selection.Top) / 2) + selection.Top
    };
    Point offset = new Point
    {
        X = (int)(center.X + center.X * Amount3.First),
        Y = (int)(center.Y + center.Y * Amount3.Second)
    };
    int horLoops = (int)Math.Ceiling(selection.Width / (float)Amount1);
    int verLoops = (int)Math.Ceiling(selection.Height / (float)Amount1);    
    int leftEdge = (offset.X - selection.Left) % Amount1;
    int topEdge = (offset.Y - selection.Top) % Amount1;

    dst.CopySurface(src, rect.Location, rect);

    using (Graphics plane = new RenderArgs(dst).Graphics)
    {
        plane.TextRenderingHint = TextRenderingHint.AntiAlias;
        plane.Clip = new Region(rect);

        using (SolidBrush overlayBrush = new SolidBrush(Color.FromArgb(Amount2, Color.White)))
        {
            plane.FillRectangle(overlayBrush, selection);
        }

        Point point = Point.Empty;
        string pointText;
        SizeF pointTextSize;
        using (SolidBrush pointBrush = new SolidBrush(Color.Red))
        using (SolidBrush textBrush = new SolidBrush(Color.Black))
        using (Font textFont = new Font("Arial", 8, FontStyle.Regular))
        {
            for (int y = 0; y < verLoops; y++)
            {
                for (int x = 0; x < horLoops; x++)
                {
                    point.X = leftEdge + Amount1 * x;
                    point.Y = topEdge + Amount1 * y;

                    plane.FillRectangle(pointBrush, point.X - 1, point.Y - 1, 3, 3);

                    pointText = (point.X - offset.X).ToString() + ", " + ((point.Y - offset.Y) * -1).ToString();
                    pointTextSize = plane.MeasureString(pointText, textFont);
                    if (pointTextSize.Width >= Amount1)
                        pointText = (point.X - offset.X).ToString() + ",\n" + ((point.Y - offset.Y) * -1).ToString();
                    plane.DrawString(pointText, textFont, textBrush, point);
                }
            }
        }
    }
}

 

 

There's a Preview button in CodeLab these days. :)  Or you can build a DLL file if you're going to be using it a lot.

CodeLab-previewButton.png

That's awesome!  Thanks so much!  Really cool how you added that little slider system.  I might have been doing something wrong, because the settings didn't seem to affect the code, but I just manually edited the X and Y and opacity after previewing the settings.  Maybe that's working as intended.  

 

I do have one other request, if you feel like coding a bit more.  :P  If not, I'm satisfied!  I was hoping you might be able to make the coordinate text white instead of black when it's on top of a dark color.  You can see in my screenshot that I prefer 0 overlay opacity (so I can keep the .png color codes precise - this is a template that Minecraft uses to generate terrain) but the text in the water is difficult to read.  

 

Thanks, toe_head.  

Edited by dracho
added screenshot
Link to comment
Share on other sites

2 minutes ago, dracho said:

I might have been doing something wrong, because the settings didn't seem to affect the code, but I just manually edited the X and Y and opacity after previewing the settings.  Maybe that's working as intended.  

 

Right, adjusting the UI controls during the Preview doesn't change the code. In other words, you can't change the default values by opening the Preview.

That would be very annoying to programmers who are constantly opening Preview to test things after making code changes.

 

7 minutes ago, dracho said:

I was hoping you might be able to make the coordinate text white instead of black when it's on top of a dark color.

 

You want a Toggle (checkbox), or do you want it to automatically set the text color by detecting the light/dark background?

Or do want a Color Wheel in the UI, so you can set the text to any color?

(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

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