Skip to content

Commit

Permalink
SOF-7354: set slightly different color for atoms with labels
Browse files Browse the repository at this point in the history
  • Loading branch information
pranabdas committed May 9, 2024
1 parent a507f56 commit 7eaaadd
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/mixins/atoms.js
Expand Up @@ -88,12 +88,30 @@ export const AtomsMixin = (superclass) =>
createAtomsGroup(basis, atomRadiiScale) {
const atomsGroup = new THREE.Group();
atomsGroup.name = ATOM_GROUP_NAME;
const { elementsWithLabelsArray } = basis;
const { atomicLabelsArray, elementsWithLabelsArray } = basis;
basis.coordinates.forEach((atomicCoordinate, atomicIndex) => {
const element = basis.getElementByIndex(atomicIndex);
// set colors slightly different according to the labels
const color = this.getAtomColorByElement(element).toLowerCase();
const label = parseInt(atomicLabelsArray[atomicIndex], 10) || 0;

let newColor;
if (label === 0) {
newColor = color;
} else if (label % 2 === 0) {
newColor =
"#" +
new THREE.Color(color).lerp(new THREE.Color("red"), 0.2).getHexString();
} else {
newColor =
"#" +
new THREE.Color(color).lerp(new THREE.Color("green"), 0.2).getHexString();
}

const sphereMesh = this.getSphereMeshObject({
...this._getDefaultSettingsForElement(element, atomRadiiScale),
coordinate: atomicCoordinate.value,
color: newColor,
});
sphereMesh.name = `${element}-${atomicIndex}`;
sphereMesh.nameWithLabel = `${elementsWithLabelsArray[atomicIndex]}`;
Expand Down

0 comments on commit 7eaaadd

Please sign in to comment.