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.

Color in Java Scripts post and replies

Return to the Color in Java Scripts thread
Login to post to this thread

Java versus Java Script - February 21, 2015 at 11:08
Fernando Silva Fernandes
10 Posts

In Java, declaring a variable (x) as an object:

x = Color.RED;

it's OK.

The same thing in Java Script gives the error :"Color is not defined".

How to do it in EJsS?


Replies to Java versus Java Script

Re: Java versus Java Script - February 21 2015 11:36
Wolfgang
118 Posts

JavaSscript does not have a Color class but you can create a color variable using any of the standard color names;  For example:

var c="Red";

Known color names are listed here:
http://www.w3schools.com/cssref/css_colornames.asp

You can use the rgb function of you can create a function that returns a color from three integers:

function rgb(r, g, b){
  return "rgb("+r+","+g+","+b+")";
}



Re: Re: Java versus Java Script - February 21 2015 12:11
Fernando Silva Fernandes
10 Posts

Many thanks for your help.

I'll try it asap.

Fernando



The OSP Network:
Open Source Physics - Tracker - EJS Modeling
Physlet Physics
Physlet Quantum Physics