Math problem
Displaying 1-4 of 4 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
RageCage

My goal is to be able to check at least once every 8 pixels of space from the center of the screen to radius 'size'.
so far I've gotten this:

int multi=8;
int max=360*size/multi;
i=0;
while(i<max){
i+=max*2/(max-i);
x = multi * sin(i) * (max-i /360) /65535;
y = multi * cos(i) * (max-i /360) /65535;
setPixel(x+(imageWidth(screen)/2),y+(imageHeight(screen)/2),rgb(255,255,255),screen);
}


This works perfectly. The problem is, I need to have the system start from the center and spiral outwards whereas right now it's going from the outside in. The obvious solution, to me, would be:


int multi=8;
int max=360*size/multi;
i=max;
while(i>0){
i-=max*2/(max-i);
x = multi * sin(i) * (max-i /360) /65535;
y = multi * cos(i) * (max-i /360) /65535;
setPixel(x+(imageWidth(screen)/2),y+(imageHeight(screen)/2),rgb(255,255,255),screen);
}


I just set 'i' to max and told 'i' to subtract rather than add. Buuuut this doesn't work.
By doing a log of the first version and seeing what 'i' finished on, I got 9097. If I set i to 9097 instead of max, it works perfectly. I need to be able to change the 'size' variable though so this isnt going to be a good option.
I need to know the equation for what to set 'i' to.

Can anyone help?

EDIT: I should also add that when I do set it to 9097, and set wth while condition to i>0, it will never finish because i increases regardless of it being subtracted from. so there's really two things I need: the condition and the initial set.

Posted on 2005-01-03 01:53:51 (last edited on 2005-01-03 10:00:04)

RageCage

nevermind! I figured it out. I ended up taking a different approach, for those interested:


int size=200;
int ang;
for(i=1;i<size;i+=8){
for(ang=0;ang<360;ang+=size*2/i){
x = sin(ang) * i / 65535;
y = cos(ang) * i / 65535;
setPixel(x+(imageWidth(screen)/2),y+(imageHeight(screen)/2),RGB(255,255,255),screen);
showpage();
}
}

Posted on 2005-01-03 17:03:37

Omni

Excellent. Though I'm not quite sure what the purpose of this code is. I assumed it would check every eight pixels on a line segment at the given angle from the center of the screen, but according to your code the angle is actually incremented, so it seems to spiral out, I think...



er...or, are you trying to create something of an electron cloud-style check? That is, it checks every eight pixels of space in that area, not just along a certain ray? I think that's what you're talking about and I just missed it. Seems good code though.

Posted on 2005-01-04 10:33:48

RageCage

It roughly checks every 8 pixels, it gets the job done anyway. It's is essential that it spiral though.

Posted on 2005-01-04 11:52:04


Displaying 1-4 of 4 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.