• Log in or sign up for an account here: https://www.sythe.org/login

Outward Spiral Algorithm

Govind

The One Musketeer

Highly Respected
Mudkips
Retired Administrator
Joined
Apr 22, 2005
Sythe Gold
23
Messages
7,825
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
This is very old code of mine that I've recently found after backing up stuff off my old computer. Added some comments to it; thought I'd post it here.

Code:
#include <windows.h>
#define D_RIGHT 0
#define D_UP 1
#define D_LEFT 2
#define D_DOWN 3
typedef int DIRECTION;

void WindowSpiral(HWND hWnd, int jumpdiv)
{
	/* Declarations */
	RECT dimensions;  
	int centerX, centerY, jumps = 1, i, curX, curY, xjumpamt, yjumpamt;
	DIRECTION direction = D_RIGHT; 
	POINT p;

	/* Get the rect for dimension and jump configuration */
	GetWindowRect(hWnd,&dimensions);
	/* Integer division but at most we'd be off by one pixel; gets the center of the window */
	centerX = dimensions.left+((dimensions.right-dimensions.left)/2); 
	centerY = dimensions.top+((dimensions.bottom-dimensions.top)/2);
	/* These will be the amount jumped each iteration; integer division but good enough */
	xjumpamt = (dimensions.right-dimensions.left)/jumpdiv;
	yjumpamt = (dimensions.bottom-dimensions.top)/jumpdiv;

	/* Get into the middle of the window before we start */
	curX = centerX; curY = centerY;
	SetCursorPos(curX,curY);
	while(1)
	{
		//if(direction < 3) direction = D_RIGHT;
		for(i = 0; i < jumps; i++) 
		{
			switch(direction%4)
			{
				case D_RIGHT:
					curX+=xjumpamt;
					break;
				case D_UP:
					curY-=yjumpamt;
					break;
				case D_LEFT:
					curX-=xjumpamt;
					break;
				case D_DOWN:
					curY+=yjumpamt;
					break;
			}
			SetCursorPos(curX,curY);
			Sleep(50);
			// The above two lines are NOT necessary; they are only so you can see the current location of the spiral loop.
		}
		jumps++; direction++; // increment jumps and direction each time around so that the spiral will grow outward

		/* Check if we're out of the window rect; if so, no more*/
		GetCursorPos(&p);
		if(p.x >= dimensions.right) break;
		if(p.y >= dimensions.bottom) break;
		if(p.x <= dimensions.left) break;
		if(p.y <= dimensions.top) break;

	}	
}
From here, you can add GetPixel and change the return type to make a color clicker.

The SetCursorPos/GetCursorPos and Sleep lines shouldn't be in a finished application; those are there so the cursor can be used to indicate the path of the spiral. To check if you're finished in an application without those lines, compare curX/curY with the dimension.top/bottom/left/right values.
 
Thanks for sharing, SMR!
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
Haha, thanks :)
 
Runescape Gamblingrunescape gambling
Back
Top