Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Runtime.InteropServices;
- namespace SPSharp
- {
- class Program
- {
- public struct RECT
- {
- public double x, y, w, h;
- public RECT(double a, double b, double c, double d)
- {
- x = a; y = b; w = c; h = d;
- }
- };
- public static bool contains(RECT R1, RECT R2)
- {
- if ((R2.x + R2.w) < (R1.x + R1.w)
- && (R2.x) > (R1.x)
- && (R2.y) > (R1.y)
- && (R2.y + R2.h) < (R1.y + R1.h)
- )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- [DllImport("user32.dll", SetLastError = false)]
- static extern IntPtr GetDesktopWindow();
- [DllImport("user32.dll")]
- static extern IntPtr GetWindowDC(IntPtr hWnd);
- [DllImport("user32.dll")]
- static extern bool GetCursorPos(ref Point POINT);
- [DllImport("user32.dll")]
- static extern int ShowCursor(bool b);
- public static int Handler(int direction,int X, int Y, int W, int H, int SW, int SH)
- {
- if (contains(new RECT(0, 0, SW, SH), new RECT(X, Y, W, H)))
- {
- return -1;
- } else
- {
- /* 1 2
- *
- *
- *
- * 3 4
- *
- */
- Point first = new Point(X, Y);
- Point second = new Point(X+W, Y);
- Point third = new Point(X, Y + H);
- Point fourth = new Point(X + W, Y + H);
- if (third.Y >= SH || fourth.Y >= SH)
- {
- if (direction == 1) return 2;
- if (direction == 3) return 4;
- } else if (first.X <= 0 || third.X <= 0)
- {
- if (direction == 4) return 2;
- if (direction == 3) return 1;
- } else if (first.Y <= 0 || second.Y <= 0)
- {
- if (direction == 2) return 1;
- if (direction == 4) return 3;
- } else if (second.X >= SW || fourth.X >= SW)
- {
- if (direction == 1) return 3;
- if (direction == 2) return 4;
- }
- }
- return -1;
- }
- static void Main(string[] args)
- {
- Graphics g = Graphics.FromHdc(GetWindowDC(GetDesktopWindow()));
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
- Image test = new Bitmap("bruh.png");
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
- int direction = 3;
- /* 1 = X++, Y++ -> v
- * 2 = X++, Y-- -> ^
- * 3 = X--, Y++ <- v
- * 4 = X--, Y-- <- ^
- */
- int W = (int)g.VisibleClipBounds.Width;
- int H = (int)g.VisibleClipBounds.Height;
- int X = W/2;
- int Y = H/2;
- double hi = 0;
- while (true)
- {
- g.DrawImage(test, X, Y);
- var r = Handler(direction, X,Y,test.Width, test.Height, W,H);
- if (r != -1)
- {
- direction = r;
- }
- switch (direction)
- {
- case 1:
- X+=4;Y+=4;break;
- case 2:
- X+=4;Y-=4;break;
- case 3:
- X-=4;Y+=4;break;
- case 4:
- X-=4;Y-=4;break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement