Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by danielmxli · May 29, 2015 at 05:14 PM · particlesloopvisualization

Creating fractals images with particles, but getting weird image

I'm trying to create fractal images with the following equation :

alt text And it should look something like this (but in 3D) :

alt text

But I'm getting a very strange output. See the green particles are the 40 particles that are emitted. Even trying with 4000 or 400000 particles, it still forms a very similar shape: alt text

This is my code:

 #pragma strict
 
 function Start () {
     var myParticleSystem : ParticleSystem; 
     var myParticles: ParticleSystem.Particle[];
     
      myParticleSystem = GetComponent( ParticleSystem );
      myParticleSystem.Emit(40);
      var num_particles = myParticleSystem.particleCount; 
      myParticles = new ParticleSystem.Particle[num_particles+1];
      
 
      var a = -55;
      var b = -1  ;
      var c = -42;
      
      var x : float; 
      var y : float; 
      var z : float; 
      
     var particlePosition : Vector3;
           
     for (var i = 0; i < num_particles; i++){ // Generalization of Barry Martin's original 
         particlePosition = myParticles[i].position;  
         x = Random.value * -1 ; 
         y = Random.value * 10;
         // HERE I FOLLOW THE EQUATION EXACTLY HOW IT'S GIVEN
             // 
     var x1 = y- x / Mathf.Abs(x) * Mathf.Sqrt(Mathf.Abs(b * x + c));
         var y1 = a - x;
         var newposition = new Vector3(x1,y1,Random.value);
         
         myParticleSystem.GetParticles(myParticles);         
         myParticles[i].position = newposition; 
         myParticleSystem.SetParticles(myParticles, num_particles);         
     }
     
     
 }
 
 
 
 
 
 


screen-shot-2015-05-28-at-63703-pm.png (194.7 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ByteSheep · May 29, 2015 at 05:33 PM 0
Share

It looks to me like that equation is calculating the position of the next particle based on the current particles location. Xi is the current x position and Xi+1 is the next x position (I could be wrong).

Why are you assigning random values to x and y? That won't give you any kind of fractal structure I believe.. Try storing the previous x and y positions while going through the for loop.

avatar image tanoshimi · May 29, 2015 at 06:54 PM 0
Share

Your code comment states //HERE I FOLLOW THE EQUATION EXACTLY AS GIVEN yet, to me, the code looks different to the formula given at the top of your post?

In the equation, {x,y}[i+1] is defined in relation to {x,y}[i] yet, in your implementation you've substituted random values in place of x[i] and y[i] (and also provided a random z[i])..?

What is the particlePosition variable used for? And where do the a,b,c values come from?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ByteSheep · May 29, 2015 at 06:32 PM

Gave it a test and with some tweaks it looks quite nice:

 #pragma strict
 
 var particleCount : int;
 var a : int = 1;
 var b : int = 1;
 var c : int = 0;
 
 function Start ()
 {
     var myParticleSystem : ParticleSystem; 
     var myParticles: ParticleSystem.Particle[];
     
     myParticleSystem = GetComponent(ParticleSystem);
     myParticleSystem.Emit(particleCount);
     myParticles = new ParticleSystem.Particle[particleCount + 1];
     
     var x : float;
     var y : float;
     var prevPos : Vector3;
        
     for (var i = 0; i < particleCount; i++)
     {
         // Get previous particle position
         prevPos = (i < 1) ? Vector3.one : myParticles[i - 1].position;
         
         x = prevPos.x;
         y = prevPos.y;
         
         var x1 = y - x / Mathf.Abs(x) * Mathf.Sqrt(Mathf.Abs(b * x + c));
         var y1 = a - x;
         
         var newPosition = new Vector3(x1, y1, 0);
         
         myParticleSystem.GetParticles(myParticles);
         myParticles[i].position = newPosition;
         myParticleSystem.SetParticles(myParticles, particleCount);
     }
 }

Yay fractals!

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image danielmxli · May 29, 2015 at 08:05 PM 0
Share

Thanks! I did something similar, and it fixed the result. In your code, though, you didn't specify what particleCount was. I tweaked yours so that particleCount = 400; and only one particle was emitted.... How did you get yours to work? Did you have emission enabled for the ParticleSystem in Inspector?

avatar image ByteSheep · May 29, 2015 at 08:27 PM 0
Share

particleCount is just the amount of particles you would like to spawn. $$anonymous$$ake sure that in the inspector none of the values are 0 (the c variable is 0 by default) otherwise all the particles will be spawned on the same spot.
The emission rate of the particle system is set to 0.

avatar image danielmxli · May 29, 2015 at 08:50 PM 0
Share

Oh I see! Thanks very much! A design question: If I wanted to have say seven of these fractals flow at the camera at a time, one after another, would it be best if I made: a) seven different particle systems in the Hierarchy, and start at increasing delays? b) created a prefab out of this one here, and then in the update script instantiate 6 more? or is there a better option? Both of these options seem rather loopy

avatar image ByteSheep · May 29, 2015 at 09:08 PM 0
Share

Both of those options sound like viable approaches. Depending on the effect you are trying to get you could also put the above code in a separate function so you can easily create new fractals from the same particle system. You would simply clear the particle list and then call the function again to generate new particles / fractals.
But if you need the fractals to move independently of one another it would probably be easiest to have a separate particle emitter for each.

avatar image danielmxli · May 29, 2015 at 09:46 PM 0
Share

Sounds good. Thanks again. Also, if I'm trying to have the ParticleSystem loop, I have myParticleSystem.loop = true; but it only runs once still. How can I enable infinite loops? EDIT: Just read about FixedUpdate. Woo!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Trying to create fractals images with particles, but getting weird pattern instead 0 Answers

Camera.Render() & DockArea:OnGUI() seemingly random & unrelated errors after particles launch 0 Answers

Need tips for optimizing main func that loops through thousands of particles 0 Answers

particles emitter loop 1 Answer

Custom particle system loop optimization 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges