# Circle

Comments in 'Plugin Development' started by Primus, Jul 19, 2015.

1. Offline

### PrimusNotable Member

Joined:
Apr 7, 2015
Posts:
1,465
Minecraft User:
I want to make a particle circle in sky so i need a function that will return only X n Z coordinates for next point on circle
CraftYourBukkit likes this.
2. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
PHP:
``` \$center = new Vector3(1, 1, 1);\$radius = 0.5;\$count = 100;\$particle = new WhateverParticle(\$center);for(\$i = 0; \$i < \$count; \$i++){  \$pitch = (mt_rand() / mt_getrandmax() - 0.5) * M_PI;  \$yaw = mt_rand() / mt_getrandmax() * 2 * M_PI;  \$y = -sin(\$pitch);  \$delta = cos(\$pitch);  \$x = -sin(\$yaw) * \$delta;  \$z = cos(\$yaw) * \$delta;  \$v = new Vector3(\$x, \$y, \$z);  \$p = \$center->add(\$v->normalize()->multiply(\$radius));  \$particle->setComponents(\$p->x, \$p->y, \$p->z);  \$level->addParticle(\$particle);} ```
AndrewBit, rvachvg, iJoshuaHD and 2 others like this.
3. Offline

### PrimusNotable Member

Joined:
Apr 7, 2015
Posts:
1,465
Minecraft User:
Thanks
4. Offline

### PixelGuy75Notable MemberPlugin Developer

Joined:
Feb 9, 2014
Posts:
315
Plugins:
2
Minecraft User:
Could you make the \$center the coordinates of a player?
5. Offline

### PrimusNotable Member

Joined:
Apr 7, 2015
Posts:
1,465
Minecraft User:
What player? I'm using it with Timer , you can go ahead use PlayerMoveEvent, but thats not pretty good idea
6. Offline

### PixelGuy75Notable MemberPlugin Developer

Joined:
Feb 9, 2014
Posts:
315
Plugins:
2
Minecraft User:
Why isn't it a good idea? It would look awesome!
Legoboy0215 likes this.
7. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
Yes. Simply replace \$center with \$player.
BlackJIeB and PixelGuy75 like this.
8. Offline

### BlackJIeBNew Member

Joined:
Oct 12, 2014
Posts:
28
Minecraft User:
can you tell me how to make a spiral of particles?
9. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
The following code makes one round per meter height, and makes up to two rounds (two meter high), spawning one particle per 1/20 meter:
PHP:
``` // \$yaw is in radiansfor(\$yaw = 0, \$y = \$center->y; \$y < \$center->y + 2; \$yaw += (M_PI * 2) / 20; \$y += 1 / 20){  \$x = -sin(\$yaw);  \$z = cos(\$yaw);  \$particle->setComponents(\$x, \$y, \$z);  \$level->addParticle(\$particle);} ```
jojoe77777, rvachvg and BlackJIeB like this.
10. Offline

### BlackJIeBNew Member

Joined:
Oct 12, 2014
Posts:
28
Minecraft User:
Oh my God you are the perfect person who does not speak in riddles, and immediately writes the code.
Thank you! :3
11. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,722
Minecraft User:
He isn't. He rarely does it like this... lol
jojoe77777, RekkuzaRage, LDX and 2 others like this.
12. Offline

### BlackJIeBNew Member

Joined:
Oct 12, 2014
Posts:
28
Minecraft User:
However, however, a syntax error (in the for loop)
PEMapModder likes this.
13. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,722
Minecraft User:
lol
jojoe77777 likes this.
14. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
Right, the last semicolon should be replaced into a comma. My wrong.
Because it's the first time I'm writing it, and I had time, and I found it interesting to write it

Riddle example:
Iterate from the starting height Y coordinate to the ending height. Regarding your desired spiral density, increase your yaw (in radians) by a little bit every time y increases. Using a similar algorithm to the center code above, use trigonometry to calculate the X and Z position of the particle. Adding the iterating Y, you get the XYZ to spawn the particle at.
15. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
I just got a new idea. What about making a plugin that plots a graph with particles? XD
E.g. /particlegraph lavadrip "x^3 - x^2" -5 5 -5 5 0.1 0.1
Plots a graph of y = x^3 - x^2 {-5 <= x <= 5, -5 <= x <= 5} in the scale 0.1 meter = 1 unit.
Last edited: Jul 21, 2015
LDX, Xenturio and BlackJIeB like this.
16. Offline

### BlackJIeBNew Member

Joined:
Oct 12, 2014
Posts:
28
Minecraft User:
Still not working
Anyway the previous code in a complete circle cool
17. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
How does it not work?
BlackJIeB likes this.
18. Offline

### BlackJIeBNew Member

Joined:
Oct 12, 2014
Posts:
28
Minecraft User:
Code:
```    public function spiral(PlayerMoveEvent \$event) {
\$player = \$event->getPlayer();
if (\$player instanceof Player) {
if (\$player->getInventory()->getItemInHand()->getId() == 351) {
\$sender = \$event->getPlayer();
\$level = \$sender->getLevel();
\$x = \$player->getX();
\$y = \$player->getY();
\$z = \$player->getZ();
\$center = new Vector3(\$x, \$y, \$z);
\$count = 100;
\$particle = new HeartParticle(\$center);
for (\$yaw = 0, \$y = \$center->y; \$y < \$center->y + 2; \$yaw += (M_PI * 2) / 20, \$y += 1 / 20) {
\$x = -sin(\$yaw);
\$z = cos(\$yaw);
\$particle->setComponents(\$x, \$y, \$z);
}
}
}
}```
nothing happens when holding item id 351
19. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
(Irrelevant) Why \$sender? Just keep using \$player.
BlackJIeB likes this.
20. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
Oops, it should be like this:
PHP:
``` // \$yaw is in radiansfor(\$yaw = 0, \$y = \$center->y; \$y < \$center->y + 2; \$yaw += (M_PI * 2) / 20, \$y += 1 / 20){  \$x = -sin(\$yaw) + \$center->x;  \$z = cos(\$yaw) + \$center->z;  \$particle->setComponents(\$x, \$y, \$z);  \$level->addParticle(\$particle);} ```
BlackJIeB likes this.