5

In latex, I can mix two colours like RoyalBlue!25!white. In asymptote I want to use the same color. How do I do this?

MWE where I would like to replace the RoyalBlue color of the material by the above one:

size(700);
import solids;
import texcolors;
import three;

currentprojection=orthographic (
    camera=(8,4,4),
    up=(0,0,1),
    target=(2,2,2),
    zoom=1.0
);

// save predefined 2D orientation vectors
pair NN=N;
pair SS=S;
pair EE=E;
pair WW=W;

triple Atom1 = (-1.1547, -2., 3.26599);

material m  = material(gray(0.5), black, RoyalBlue, black);

draw(surface(sphere(Atom1,0.5)),m);
1
  • 4
    interp(RoyalBlue, white, 0.75), where interp stands for "interpolate", will give you 75% of the way from RoyalBlue to white. Jul 31, 2015 at 17:10

2 Answers 2

4

Use the binary operator * to scale the colors/pens, and the binary operator + to add colors/pens together.

Therefore, replacing RoyalBlue with RoyalBlue*0.25 + white*0.75 (25 % RoyalBlue mixed with 75 % white) should yield the output you want.

size(700);
import solids;
import texcolors;
import three;

currentprojection=orthographic (
    camera=(8,4,4),
    up=(0,0,1),
    target=(2,2,2),
    zoom=1.0
);

// save predefined 2D orientation vectors
pair NN=N;
pair SS=S;
pair EE=E;
pair WW=W;

triple Atom1 = (-1.1547, -2., 3.26599);

material m  = material(gray(0.5), black, RoyalBlue*0.25 + white*0.75, black);

draw(surface(sphere(Atom1,0.5)),m);

This gives the output Output

5

You can combine colors like in the following example.

unitsize(3inch);
for (real fred = 0.0; fred <= 1.0; fred += 0.1) {
    for (real fblue = 0.0; fblue <= 1.0; fblue += 0.1) {
        fill(shift(fred,fblue)*scale(0.1)*unitsquare, fred*red+fblue*blue);
    }
}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .