PDA

View Full Version : DrawCircle



mixster
02-13-2008, 07:12 PM
After seeing a game (linerider) I quickly got addicted. The only problem I came across with it though was that it was very hard to make circles - thus DrawCircle was born. I do plan on adding a start and end angle, but since I'm using pythagorus instead of sine etc. it makes it hard since I'm lazy and it would involve some hard work ;).
Now, to present it:
procedure DrawCircle(cx,cy,r: Integer);
var
x,y,y2,i: Integer;
first: boolean;
begin
first:= true;
for i:= 0 to 1 do
begin
for y:= -r to r do
begin
x:= Round(Sqrt(Sqr(r)-(Sqr(y))));
if(first) then
begin
first:= false;
Sleep(10);
HoldMouse(cx+x,cy+y,True)
Sleep(10);
end;
if(i=1) then
begin
x:=-x;
y2:= -y
end
else
y2:= y;
MoveMouse(cx+x,cy+y2);
Sleep(1);
end;
end;
ReleaseMouse(cx+x,cy+y2,True);
end;

You just have to give it a place to start (cx and cy) then how big you want the circle to be (radius). A good example is to use it in paint - do be warned though that it goes slower as the circle gets bigger.
Have fun

Cazax
02-13-2008, 07:18 PM
Really good i tried it in paint.

Negaal
02-13-2008, 07:23 PM
You are really smartass:D
This is better, though I made it, but don't understand sin,cos,tan

program New;

var
i,x,y,midx,midy,h,w : integer;
angle, add, rad : extended;


begin
GetClientDimensions(w,h)
midx := w / 2;
midy := h / 2;
rad := round((w + h) / 6);
repeat
angle := angle + 0.5;
X := MidX + Round(rad * Cos(Radians(Angle - 90)));
Y := MidY + Round(rad * Sin(Radians(Angle - 90)));
wait(1);
movemouse(x,y);
until angle >= 360;
end.

mixster
02-13-2008, 07:40 PM
My one is smexier though ;)
Anyway, mine is more or less the same length (minus the holdmouse/releasemouse stuff and probably the semi-circle checker) and I know how it works.
I'm guessing that your method makes a 'virtual triangle' outwards from the midpoint then gets the length of the across and up, only problem is I barely grasp regular trigonometry and scar's slightly different results confuse me. Ahwell, all is fair in love and scar.

munk
02-17-2008, 03:37 AM
ha! I did that once! It was pointless until beta2 introduced speed lines and you can make him go around in a circle forever. I used basically what negaal had only finished with holdmouse n stuff :p sry mix

now for linerider gloating...

BETA video (http://www.headweight.net/?i=videoplayer.php?id=227&v=viewfile.php?id=227)

BETA 2 (http://headweight.net/videos/trackB.avi)

:D

also, gratz useful poster cup!

mixster
02-17-2008, 11:50 AM
procedure Circle(MidX,MidY,rad,sAngle,eAngle: Integer; accuracy,xOffset,yOffset: Extended);
// Extra credit love to n3ss3s for the heart of the script (as posted by Negaal)
var
x,y,dloop,eloop: Integer;
angle: Extended;
begin
angle := sAngle;
X := MidX + Round(xOffset * (rad * Cos(Radians(angle -90))));
Y := MidY + Round(yOffset * (rad * Sin(Radians(angle -90))));
HoldMouse(x,y,True);
Sleep(500);
if(sAngle > eAngle) then
eloop := Round((sAngle - eAngle) * (1/accuracy))
else
eloop := Round((eAngle - sAngle) * (1/accuracy));
repeat
if(sAngle < eAngle) then
angle := angle + accuracy
else
angle := angle - accuracy;
Inc(dloop);
X := MidX + Round(xOffset * (rad * Cos(Radians(angle -90))));
Y := MidY + Round(yOffset * (rad * Sin(Radians(angle -90))));
wait(5);
movemouse(x,y);
until (dloop >= eloop);
ReleaseMouse(x,y,True);
end;


Adapted from n3sses trigonometry tutorial for pure linerider pwnage :p
It includes a start angle, end angle, accuracy (higher = faster, generally 1 or under), and an x and y offset (changes the shape of it, with xmod making the widest point xmod*radius and same with ymod).
Mine even supports circles going in opposite direction and angle starting bigger than 360 (e.g. from 180 to 450 to go from the bottom to the right but clockwise)

Edit: Thanks for the thanks and those are some awesome videos - I never seem to get past making a few curves... I really do need to get some follow through with something i do ><

n3ss3s
02-17-2008, 12:26 PM
I haven't tested that function in the above post, but you do understand that if offset was 2, it doubles the radius, if its 3, it triples, etc, like what's the meaning of it?

mixster
02-17-2008, 01:38 PM
That's pretty much it, all I wanted it to do was to alter the shape of the circle to make it look cooler. Also noticed that no matter what the start/end angle is, it'll always come up as the same shape when using the Offset's. I only used Offset because it was first thing that came to mind when making it, but using xMod and yMod would have probably made it clearer - ahwell.
Edit: There are the 2 offsets so it can make the widest x point twice (to whatever it's set to) the radius, but the y offset can change aswell - e.g. xOffset of 2 and yOffset of 1 means the that circle is distorted to twice the radius when y is equal to MidY but the highest point is still equal to the radius.