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
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 -
178 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:

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 -
Fernando Silva Fernandes
10 Posts

Many thanks for your help.

I'll try it asap.


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