Author Topic: Make cherry move in Archimedian spiral with constant speed?  (Read 3413 times)

zaphod77

  • Wannabe
  • Posts: 33
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Make cherry move in Archimedian spiral with constant speed?
« on: January 20, 2016, 04:14:09 PM »
an archimedian spiral means with each revolution the item has moved a set distance from the spawn point.

I wish two variations.

1) use spawn point as the inside of the spiral, and spiral outwords, with it getting a fixed distance out form the center with each revolution.
2) use spawn point as the outside of the spiral, and spiral inwards. Same thing, but it vanishes when it reaches the center.

it has to do it's magic by adjusting the direction without changing the speed.

how the heck do i do this? 

lawatson

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #1 on: January 20, 2016, 04:40:59 PM »
Two ways really: Trig functions/rotation matrix, or a ratio.

Trig functions method, step event:

angle+=(speed);
radius+=1;
x=centerx+(radius*sin(degtorad(angle)));
y=centery+(radius*cos(degtorad(angle)));

Ratio method (uses speed/direction):

direction=constant/max distance*current distance.

constant is just a value to speed things up, max distance is as far away as it will be, and current distance is point_distance(x,y,centerx,centery).


EDIT: wow why did it quote my message i wanted to edit it stupid ass me lol
« Last Edit: January 20, 2016, 04:47:43 PM by lawatson »
(click to show/hide)

smoke weed everyday

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Unknown Unknown
  • Browser:
  • Chrome 46.0.2490.71 Chrome 46.0.2490.71
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #2 on: January 20, 2016, 04:56:11 PM »
I can only help with the first one, and hopefully it's what you're looking for.


Code: (scrOrbit) [Select]
argument0=centerX;
argument1=centerY;
argument2=radius;
argument3=position; //the position of where the cherry will spawn (in degrees)
argument4=radiusSpeed; //the speed of the cherry's movement - moves away from its centerX and centerY
argument5=spinSpeed; //the speed of the cherry's revolution
x=centerX+lengthdir_x(radius+rad,position+pos);
y=centerY+lengthdir_y(radius+rad,position+pos);
rad+=radiusSpeed;
pos+=spinSpeed;


//Note that I used position instead of direction here, as I've had problems with the cherries jumping forward a certain angle when they spawn another object with an incremented direction


and to spawn them, set an alarm and do the following:


Code: (spawningObject) [Select]
for(i=0;i<360;i+=360/num1){ //this is only for if you want more than one cherry spawned at the same time, and set num1 to however many cherries you want spawned at a time
  a=instance_create(room_width/2,room_height/2,objCherry); //using the center of the room as an example
  a.centerX=a.xstart;
  a.centerY=a.ystart;
  a.radius=0;
  a.position=i; //replace i with whatever direction you want if you only want one cherry spawned at a time
  a.radiusSpeed=num2; //set num2 to how fast you want the cherry to move away from it's centerX and centerY
  a.spinSpeed=num3; //set num3 to how fast you want the cherry to revolve
}
alarm[0]=num4; //set num4 to how frequently you want the cherries to spawn


If you want the direction (or, with the way I made it, the position) of the cherries to change whenever a new one is spawned, add this:


Code: (spawningObject) [Select]
~
  a.position=i+dir;
~
dir+=num5; //set num5 to how much you want the cherries' direction (position) to change


and that's it, hopefully this can be of use for you :3




EDIT: tfw watson replied before me

zaphod77

  • Wannabe
  • Posts: 33
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #3 on: January 20, 2016, 05:11:54 PM »
Two ways really: Trig functions/rotation matrix, or a ratio.

Trig functions method, step event:

angle+=(speed);
radius+=1;
x=centerx+(radius*sin(degtorad(angle)));
y=centery+(radius*cos(degtorad(angle)));
won't work. my plan is to only adjust direction, and have it move at whatever speed is set.
Quote
Ratio method (uses speed/direction):

direction=constant/max distance*current distance.

constant is just a value to speed things up, max distance is as far away as it will be, and current distance is point_distance(x,y,centerx,centery).
Looks like that's for an outward spiral. i tested it, and it seems to work simply using   
direction=spiral_factor*current distance.
where spiral_factor is larger for a tighter spiral.

that's counterclockwise. i can multiply that by negative 1 for clockwise.

but now how do i make it spiral IN instead?
« Last Edit: January 20, 2016, 05:15:12 PM by zaphod77 »

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Unknown Unknown
  • Browser:
  • Chrome 46.0.2490.71 Chrome 46.0.2490.71
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #4 on: January 20, 2016, 05:17:55 PM »
Actually, thinking about it, you could technically do the inwards spiral with my script, although I'm sure there are much more practical ways to do it; nevertheless:


I would set the radius to have every cherry be spawned outside the view of the room (which you would have to either calculate or do a few experiments to tweak the starting distance), and set the radiusSpeed to be negative so that the cherries move inward; after a period, have an alarm be set off in the cherries that decrease the image_alpha until it's zero, upon which the cherries destroy themselves.

zaphod77

  • Wannabe
  • Posts: 33
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #5 on: January 20, 2016, 05:20:39 PM »
The radiuspeed script wont' work. the cherry doesn't move at a constant speed.

the ratio one above does the trick for spiraling out.

but i want to also be able to spiral IN, starting at the spawn point.
« Last Edit: January 20, 2016, 05:40:43 PM by zaphod77 »

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Unknown Unknown
  • Browser:
  • Chrome 46.0.2490.71 Chrome 46.0.2490.71
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #6 on: January 20, 2016, 05:34:01 PM »
I'm not sure what you mean by that then. With what I did, you create a cherry with a radius of, say, 800 pixels, from a central point that you define, meaning the cherry is 800 pixels away from it's central point; the cherry will always move into where you set it's centerX and centerY (the central point), which, with what I did, is where it spawned from originally, and the cherry will also rotate around the central point without making the cherry go off its path toward its central point.

If that's not what you want then I have no idea what you want.

zaphod77

  • Wannabe
  • Posts: 33
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #7 on: January 20, 2016, 05:42:47 PM »
No i want it to start at the spawn point, and based on the spiral factor, work out where the center point should be and spiral in towards that.

infern0man1

  • ~(=^・ω・^)ψ
  • Global Moderator
  • Oatmeal Killer
  • Posts: 1.021
  • Dear sir stroke madam, fire exclamation point
  • OS:
  • Unknown Unknown
  • Browser:
  • Chrome 46.0.2490.71 Chrome 46.0.2490.71
    • View Profile
    • Twitter
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #8 on: January 20, 2016, 05:46:01 PM »
The radiuspeed script wont' work. the cherry doesn't move at a constant speed.


I'm thinking you might have done something wrong in setting it up, because that's not what is supposed to happen. Whatever though, that isn't what you want so I'll stop posting in here.

zaphod77

  • Wannabe
  • Posts: 33
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #9 on: January 20, 2016, 06:35:33 PM »
Yeah i probably screwed something up.

your approach uses a function to spawn the object and then control it.

My approach is to spawn the object, then change the variables inside it to make it go.

a=instance_create(x,y,objSpiralCherry);
a.direction=0;
a.spiral_factor=10; // variable defined to 0 by default in create event.
a.speed=5;

and off it goes.

this DOES work with the ratio formula fine as i posted above, but i've only been able to get outward spirals. i've tried to make it move the opposite direction by adding 180, but all that does is rotate the outward spiral itself.

Okay i'm completely puzzled.

I've tried manually setting the center, and no matter WHAT i do, it somehow snaps onto a spiral, and then spirals outwards! i've tried negative speed (that just rotates the spiral 180), i've tried adding 180 to the directions (whihc does the same thing), but absolutely nothing works.  the object always snaps onto a spiral going out. if i multiply the direction by negative 1, i get clockwise instead of counter clockwise.

if the spiral factor is too big for the speed (higher speeds need smaller spiral factors), it starts jittering, but still overall follows an outward spiral.
« Last Edit: January 20, 2016, 08:10:01 PM by zaphod77 »

kilgour22

  • Cherry Eater
  • Posts: 82
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #10 on: January 20, 2016, 10:14:34 PM »
If you want your spiral to go inwards, than you need your radius to be constantly reducing. This is achievable by multiplying with a spiral factor of 0 < spiral_factor < 1. Choosing a negative value will simply reverse the direction, but the radius is still increasing due to the factor being greater than 1.
Don't let a spike ruin your day.

zaphod77

  • Wannabe
  • Posts: 33
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #11 on: January 21, 2016, 12:42:32 AM »
That does not do what you think it does.

That just makes a wider outward spiral. one wayyyyy too big to even try to put.

here's what I"m doing

current_distance=point_distance(x,y,originx,originy);
reverse=1;
if (spiral_direction==1)
{
reverse=-1;
}
direction=spiral_factor*current_distance*reverse;

No amout of tweaking prevents it from either wiggling around like crazy if the factor is too high for the speed, or making it's way to and the following an outward spiral.

zaphod77

  • Wannabe
  • Posts: 33
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #12 on: January 21, 2016, 12:51:52 AM »
I'm not sure what you mean by that then. With what I did, you create a cherry with a radius of, say, 800 pixels, from a central point that you define, meaning the cherry is 800 pixels away from it's central point; the cherry will always move into where you set it's centerX and centerY ...

You have the distance from center increasing or decreasing at a constant rate. that means the speed gets faster as it goes farther form the center, and slows down as it gets closer to the center.

That's exactly the opposite of what i want. i want the speed builtin variable of the object to remain constant, and only it's direction to be changed. this means as it goes farther from center, the radius will increase slower, because it will take longer to loop around each time.

The ratio method does this fine, but only for outward spirals.

L4Vo5

  • Cherry Eater
  • Posts: 59
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 48.0.2564.116 Chrome 48.0.2564.116
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #13 on: March 12, 2016, 06:13:48 PM »
i THINK this is what you want. Tough this doesn't use the direction so if you truly need that i think there's a simple way to calculate it.
Also make sure to not start the instance at centerx and centery or it will be destroyed (making it 0.00001 pixels away should do)

create event:
spd = 2 //set to negative to move clockwise
move = 10 //ammount of pixels moved per revolution, negative value means that it moves inwards
len= distance_to_point(centerx,centery)
dir = point_direction(centerx,centery,x,y)

step event :
if len <= 0 instance_destroy()
chng = 360*(spd/(len*pi))
dir += chng
len += move/(360/chng)
x = centerx+lengthdir_x(len,dir)
y = centery+lengthdir_y(len,dir)
I have to admit, i still haven't beaten IWBTG

L4Vo5

  • Cherry Eater
  • Posts: 59
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 48.0.2564.116 Chrome 48.0.2564.116
    • View Profile
  • Playstyle: Keyboard
Re: Make cherry move in Archimedian spiral with constant speed?
« Reply #14 on: March 13, 2016, 11:05:37 PM »
If you want direction, change

x = centerx+lengthdir_x(len,dir)
y = centery+lengthdir_y(len,dir)

to

direction = point_direction(x,y,centerx+lengthdir_x(len,dir),centery+lengthdir_y(len,dir))

And make sure to change spd to speed anywhere that it's used
I have to admit, i still haven't beaten IWBTG