APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

I want to color set of particles depend on its velocity. post and replies

Return to the I want to color set of particles depend on its velocity. thread
Login to post to this thread

Set Group of particle color.
Natthawin Cho
6 Posts

I have a set of particle and I want to set its color based on velocity.

Could I do that? if yes, how?

Thanks


Replies to Set Group of particle color.

Re: Set Group of particle color. -
Francisco Esquembre
237 Posts

Sure.

The color properties can be linked (as any other property) to variable. Changing the variable, changes the color.

You need to define an array of colors. In Java the correct type can be either int or java.awt.Color.
In Javascript you need an array of either int or String.

Paco



Re: Set Group of particle color. -
MuckrakerW M
1 Posts

Sorry can't help. I am a beginner with Ejs.



Re: Re: Set Group of particle color. -
lookang Avatar
lookang
245 Posts

u could try this for EJSS models

for (i=0; i < N ; i + + ) {
// color change lookang
    if (v[i] <0.5) { // v[i] is the array of the velocities of i number of particles
     color[i] = "rgba(50,0,250,255)"; // low velocity blue color
            }
       else if ( v[i]<1){
        color[i] = "rgba(100,0,200,255)";
         }
       else if ( v[i]<1.5){
        color[i] = "rgba(150,0,150,255)";
         }
         else if ( v[i]<2){
        color[i] = "rgba(200,0,100,255)";
         }
         else {
           color[i] = "rgba(250,0,50,255)"; // high velocity red color
           }
}

Post edited October 22, 2014 at 10:33 PM EST.

Post edited October 22, 2014 at 10:33 PM EST.

Attached File: ejss_src_MolecularDynamicsJSPerformancewee.zip


OSP@SG blog
OSP@SG Digital Library


Re: Set Group of particle color. -
Natthawin Cho
6 Posts

Thanks all of you. But I still cannot set color I want because I don't know how to set array of int which can use for set color. Now I am using just one integer to set color.


I use Java so I can't use lookang's suggestion.

Thanks all of you again.



Re: Set Group of particle color. -
lookang Avatar
lookang
245 Posts

try this

for (int i=0; i < n /* Iterations */ ; i++) {
red[i] = (int)(Math.min(speed[i]*50,255));
green[i] = 0;
blue[i] = (int)(Math.min(speed[i]*40,255));
color[i] = new java.awt.Color(red[i],green[i],(255-blue[i]),255);
//colorlines[i] = new java.awt.Color(red,green,blue,255);
}
https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejs_model_brownianmotionwee.jar
https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejs_src_brownianmotionwee.zip

Attached File: ejs_src_brownianmotionwee.zip


OSP@SG blog
OSP@SG Digital Library


Re: Re: Set Group of particle color. -
Natthawin Cho
6 Posts

Thanks a lot!!!



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book