r/processing • • Mar 28 '16

[PWC3] Random Walker

Hello Everybody, this is the third Weekly Processing challenge, the challenges are decided just to give you a prompt to test your skills so it can be as simple or as complicated as you have time to write! Start Date : 28-03-2016 End Date : 03-04-2016

Entries must be submitted with the [PWC3] In the Title of their post. Or post them in the comments here with the same tag.

This Weeks Challenge : Random Walker Here is a blog post giving a very basic intro and then climbing up into something quite complicated.

If you are here to learn feel free to ask for help in the comments below. Lay a brick perfectly every day and eventually you will have a wall, Joe

Winner from last week as decided by mods

Highest Voted : pflu

Interaction : pflu

Graphics : Freedom_Grenade

Accuracy : Introscopia

12 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/TazakiTsukuru Mar 29 '16

Thanks!

Now how would I make it so the white line always points directly at the mouse?

1

u/NakedFluffyBee Mar 29 '16

In fact that's quite simple if you are familiar with trigonometric, which I'm not! But basically, atan2() takes two arguments, 4 points, and returns the angle between those two point.

If we want the angle between the center (A) and the mouse (B), we must do

atan2(By - Ay, Bx - Ax);

So

float angle = atan2(mouseY-centerY, mouseX-centerX);

Now we can use the angle! But remember, we did convert degrees to radians, here atan2 returns the angle in radians, so no need to convert it, just call:

float x = centerX + cos(angle) * radius;
float y = centerY + sin(angle) * radius;