How to color part of a fraction e.g. denominator - manim

txt11 = TexMobject(r"-7", color=BLACK)
txt12 = TexMobject(r"\frac{1}{7}", color=BLACK).next_to(txt11, RIGHT)
I wanna color the denominator of txt12, tried splitting txt12 to:
txt12 = TexMobject(r"\frac{1}", r"{7}", color=BLACK).next_to(txt11, RIGHT)
txt12.set_color_by_tex("{7}", BLUE)
but not work, then I create a new txt13 overlapped with txt12 but a null molecular:
txt13 = TexMobject(r"\frac{}{7}", color=BLUE).move_to(txt12.get_center())
also not work.
Is there feasible way to color part of equation like fraction? thanks!

Specifically for a fraction, you can use
TexMobject(r"1", r"\over", r"7").set_color_by_tex("7", BLUE)
set_color_by_tex("7", BLUE) sets the submobject with text 7 to BLUE.
The LaTeX {a \over b} command is a shorthand for \frac{a}{b}.
This is how Grant Sanderson sometimes do it, for example, in this recent video.

Related

Color contrast formula ? (ImageMagick)

I reduced an image to 12 colors, annotated with some text (here it's color saturation, sorted) :
The text color is %[pixel:p{10,10}*2] (background *2) (I made a little script that I can share if you're interested).
As you can see, text is not very readable (contrast) in all cases (colors). Is there a smarter formula than a simple linear scaling to make text pop in all/most cases ?
As per Fred's suggestion, using luminosity is much better. Using black & white text depending on luminosity > 56 or not :
And for a not colorful image :
The text represents L component of HSL value. Notice the change from black to white when value crosses 56.

Gnuplot filled curves adds unwanted "bottom" border

I am trying to visualize a time series data set on one plot as a pseudo 3d figure. However, I am having some trouble getting the filledcurves capability working properly. It seems to be adding an unwanted border at the "bottom" of my functions and I do not know how to fix this.
This is my current set up: I have nb_of_frames different files that I want to plot on one figure. Without the filledcurves option, I can do something like this
plot for [i=1:nb_of_frames] filename(i) u ($1):(50.0 * $2 + (11.0 - (i-1)*time_step)) w l linewidth 1.2 lt rgb "black" notitle
which produces a figure like this:
no fill options
Instead of doing this, I want to use the filledcurves option to bring my plots "forward" and highlight the function that is more "forward" which I try to do with:
plot for [i=1:nb_of_frames] filename(i) u ($1):(50. * $2 + (11. - (i-1)*time_step)) w filledcurves fc "white" fs solid 1.0 border lc "black" notitle
This produces a figure as follows:
This is very close to what I want, but it seems that the border option adds a line underneath the function which I do not want. I have tried several variants of with filledcurves y1=0.0 with different values of y1, but nothing seems to work.
Any help would be appreciated. Thank you for your time.
Here is another workaround for gnuplot 5.2.
Apparently, gnuplot closes the filled area from the last point back to the first point. Hence, if you specifiy border, then this line will also have a border which is undesired here (at least until gnuplot 5.4rc2 as #Ethan says).
A straightforward solution would be to plot the data with filledcurves without border and then again with lines. However, since this is a series of shifted data, this has to be plotted alternately. Unfortunately, gnuplot cannot switch plotting styles within a for loop (at least I don't know how). As a workaround for this, you have to build your plot command in a previous loop and use it with a macro # (check help macros) in the plot command. I hope you can adapt the example below to your needs.
Code:
### filledcurves without bottom border
reset session
set colorsequence classic
$Data <<EOD
1 0
2 1
3 2
4 1
5 4
6 5
7 2
8 1
9 0
EOD
myData(i) = sprintf('$Data u ($1-0.1*%d):($2+%d/5.)',i,i)
myFill = ' w filledcurves fc "0xffdddd" fs solid 1 notitle'
myLine = ' w l lc rgb "black" notitle'
myPlotCmd = ''
do for [i=11:1:-1] {
myPlotCmd = myPlotCmd.myData(i).myFill.", ".myData(i).myLine.", "
}
plot #myPlotCmd
### end of code
Result:
I can reproduce this in gnuplot 5.2.8 but not in the output from the release candidate for version 5.4. So I think that some bug-fix or change was applied during the past year or so. I realize that doesn't help while you are using verion 5.2, but if you can download and build from source for the 5.4 release candidate that would take care of it.
Update
I thought of a work-around, although it may be too complicated to be worth it.
You can treat this as a 2D projection of a 3D fence plot constructed using plot style with zerrorfill. In this projection the y coordinate is the visual depth. X is X. Three quantities are needed on z: the bounding line, the bottom, and the top. I.e. 5 fields in the using clause: x depth zline zbase ztop.
unset key
set view 90, 180
set xyplane at 0
unset ytics
set title "3D projection into the xz plane\nplot with zerrorfill" offset 0,-2
set xlabel "X axis" offset 0,-1
set zlabel "Z"
splot for [i=1:25] 'foo.dat' using ($1+i):(i/100.):($2-i):(-i):($2-i) \
with zerrorfill fc "light-cyan" lc "black" lw 2

how to differentiate the same color objects with different intensity?

There are 3 leather pieces of Brown color.Among them one is dark brown in color.I have to highlight that odd piece(dark brown piece).The procedure which I followed in my code is:
converted given image to HSV.
checked the saturation range(S value) as well as the brightness range (V value) of the odd piece and other two light intensity pieces.
But the problem is, The odd piece values(both s and v value ranges) overlaps with the other two pieces(light intensity) values.
So,which color model best suits for this problem ?
If, Illumination changes the values gets changed again,How should I tackle this problem?
What type of Camera should I use ?

LaTeX stretching tabular/array to fill page width

I recently have had the need to make a math array or a tabular expand to fill the page width.
The effect I am trying to achieve is that for one line on the page, half is aligned at the left, and the other at the right.
For instance, just now, the following has been giving be problems...
$$
\begin{array}{l r}
\phi_{CJ}^* = \Sum_{SV} \psi_{CSJV} = P(S) P(S|V,C,S,J) & \text{(no summation on S or V which are in evidence.)}
\end{array}
$$
The desired effect is that the first cell is aligned on the left margin, and the second is aligned on the right margin. Instead, the array is centred, with no space between the cells.
Many thanks
I wonder if instead of l and r you might consider trying p{width} for your alignment. This works okay for me:
\begin{tabular}{p{0.45\textwidth} p{0.5\textwidth}}
$\phi$$_{\mathrm{CJ}}$^* = \Sum$_{\mathrm{SV}}$ $\psi$$_{\mathrm{CSJV}}$ = P(S) P(S \& V,C,S,J) & (no summation on S or V which are in evidence.) \\
\end{tabular}
p{width} allows you to set the column width and try to fill your page, whereas I think l and r have some other (perhaps goofy) method of deciding how wide to make things.
In your equation you have P(S) P(S & V,C,S,J) and I needed to change that & to a \& to stop it from thinking it was the beginning of another column...
There's a ditty on \eqmakebox on the LaTeX/Tables Wikibook site that sounds like it might help as well, though it's a bit esoteric compared to something common like \tabular... (LINK).

Changing Colours Dynamically in AS1

I can't get this to work in my AS1 application. I am using the Color.setTransform method.
Am I correct in thinking the following object creation should result in transforming a colour to white?
var AColorTransform = {ra:100, rb:255, ga:100, gb:255, ba:100, bb:255, aa:100, ab:255};
And this one to black?
AColorTransform = {ra:100, rb:-255, ga:100, gb:-255, ba:100, bb:-255, aa:100, ab:-255};
I read on some websites that calling setRGB or setTransform may not result in actually changing the display colour when the object you're performing the operation on has some kind of dynamic behaviour. Does anyone know more about these situations? And how to change the colour under all circumstances?
Regards.
Been a long time since I've had to do anything is AS1, but I'll do my best.
The basic code for a color.setTransform() looks like this...
var AColorTransform = {ra:100, rb:255, ga:100, gb:255, ba:100, bb:255, aa:100, ab:255};
var myColor = new Color(mc);
myColor.setTransform(AColorTransform);
...where mc is a MovieClip on the stage somewhere.
Remember that you're asking about transform, which by its nature is intended to transform colors from what they are to something else. If you want to reliably paint in a specific color (such as black or white), you're usually far better off using setRGB, which would look like this:
var myColor = new Color(mc);
//set to black
myColor.setRGB(0x000000);
//or set to white
myColor.setRGB(0xFFFFFF);
These work reliably, though there can be some gotchas. Generally, just remember that the color is attached to the specific MovieClip...so if that MovieClip falls out of scope (ie, it disappears from the timeline) your color will be deleted with it.
Read further only if you want to understand color transform better:
Let's look at the components of that color transform.
a (multiplier 0 > 100%) b(offset -255 > 255)
r ra rb
g ga gb
b ba bb
a aa bb
There are four channels (r, g, b, and a). The first three are for red, green and blue, and the last one for alpha (transparency). Each channel has an 'a' component and a 'b' component, thus ra, rb, ga, gb, etc. The 'a' component is a percentage multiplier. That is, it will multiply any existing channel by the percent in that value. The 'b' component is an offset. So 'ra' multiplies the existing red channel. 'rb' offsets it. If your red channel starts as 'FF' (full on red), setting ra:100 will have no effect, since multiplying FF by 100% results in no change. Similarly, if red starts at '00' (no red at all), no value of 'ra' will have any effect, since (if you recall your Shakespeare) twice nothing is still nothing. Things in-between will multiply as you'd expect.
Offsets are added after multiplication. So you can multiply by some value, then offset it:
r (result red color) = (RR * ra%) + rb
g (result green color) = (GG * ga%) + gb
b (result blue color) = (BB * ba%) + bb
a (result alpha) = (AA * aa%) + ab
example: RR = 128 (hex 0x80), ra = 50 (50% or .5), rb = -20
resulting red channel: (128 * .5) + (-20) = 44 (hex 0x2C)
Frankly, this all gets so confusing that I tend to prefer the simple sanity of avoiding transforms altogether and go with the much simpler setRGB().

Resources