Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Outward Spiral Algorithm
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-30-2010, 08:39 PM
Govind's Avatar
Hero
Highly Respected Highly Trusted Sythe Verified User
 
Join Date: Apr 2005
Posts: 7,068
Default Outward Spiral Algorithm

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.

Last edited by SMR : 10-31-2010 at 02:27 AM.
Reply With Quote
  #2  
Old 11-04-2010, 10:47 AM
Guru
 
Join Date: Jun 2005
Location: Canada
Posts: 1,844
Default Re: Outward Spiral Algorithm

Thanks for sharing, SMR!
__________________

Reply With Quote
  #3  
Old 11-15-2010, 12:57 AM
Aeropsia's Avatar
Member
 
Join Date: May 2010
Posts: 27
Default Re: Outward Spiral Algorithm

I <3 you SMR!
Reply With Quote
  #4  
Old 11-15-2010, 01:39 AM
Govind's Avatar
Hero
Highly Respected Highly Trusted Sythe Verified User
 
Join Date: Apr 2005
Posts: 7,068
Default Re: Outward Spiral Algorithm

Haha, thanks
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 02:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1