Is it a Manim bug or am I doing something wrong such that simple square fill_color fails? - manim

Here is my code. I would expect both squares to be filled GREEN but only square1 is correct. Running Windows 10 and manim community v0.15.2. Is this a manim bug?
The comment for square2 shows how to circumvent the bug.
from manim import *
class MovingTriangle(Scene):
def construct(self):
square1 = Square(side_length=1,color=RED,fill_color=RED, fill_opacity=1)
square1.color = GREEN
square1.fill_color = GREEN
square1.fill_opacity = 1
square1.stroke_color = GREEN
square2 = Square(side_length=1) # if parms for any color added in this constructor then square2 would work (fill green)
square2.color = GREEN
square2.fill_color = GREEN
square2.fill_opacity = 1
square2.stroke_color = GREEN
square2.next_to(square1, RIGHT)
self.add(square1, square2)
self.wait()

I wouldn't really call it a bug, but I agree that the behavior is somewhat unexpected. Setting the color of a mobject just by setting the fill_color attribute is not supported; there is some additional stuff going on (see for example the implementation of VMobject.set_fill) before the color of the mobject is actually changed when rendering (most notably, the call to update_rgbas_array).
For now it is best to set the colors in the constructor, or to use the dedicated set_color, set_fill, set_stroke, or set_style methods.

Found a solution. You need to explicitly set opacity = 1.0 since by default most VMobjects have no fill opacity.

Related

Blob Detection in openCV works well, but for some reason it fails for a specific image

I have managed to find circles quite easily thank to the built-in functionality of SimpleBlobDetector_create in openCV (4.2.0.34), I made sure the background would be white for easy recognition.
In the following image, 3 circles were found as I would expect:
But for some reason strangely when I apply the same code on the image below,
This perfect circle doesn't get recognized. how come??
here below is my short code.
img = cv2.imread(filename='img1.png')
cv2.imshow(winname="Original", mat=img)
cv2.waitKey(0)
params = cv2.SimpleBlobDetector_Params()
# set Circularity filtering parameters:
params.filterByCircularity = True
# 1 being perfect circle, 0 the opposite
params.minCircularity = 0.8
# create a detector with parameters
detector = cv2.SimpleBlobDetector_create(parameters=params)
keypoints = detector.detect(img)
print("Number of circular Blobs: " + str(len(keypoints)))
Thank you all for any help!
I tested your code here and got the same results. But adding
params.filterByArea = False
before params.filterByCircularity = True fixed the problem. This is kind of strange because I would expect that all the other attributes from SimpleBlobDetector would start with False as default. Also, after the change the code started to respond with 4 circles (which seems correct to me) and not 3 as previously.

Direct2D Border Around Text

For better visual appearance want to draw a black border around my text.
Currently i am drawing the same text 5 times.
If i want to draw the text on x = 5, y = 10 i would draw the text one time on the actual position.
Then i would draw the same text in black color with slightly other positions.
x = 4, y = 10
x = 5, y = 9
...
I can only imagine that this is bad performance wise. Or is this the correct way?
I never did it the correct way myself, but it seems here they did it: http://www.codeproject.com/Articles/376597/Outline-Text-With-DirectWrite
I do that too. But I suddenly realise there might be a better way (have not tried it yet): first draw in black with a slightly bigger size, and draw again in white with preferred size. Worth a try? Let me know how that goes.

How to draw an effect (Gloss with metallic lustre) on concentric circle such as following?

I referred to following article. What I actually need to draw is concentric/ Concrete circles with an effect as shown in image below.
I am finding it difficult to a) Draw the white streaks radially b) Find some key terms to search for related articles to proceed further on this.
Any hint or link to read about this will be of great help.
Try these
Metallic Knob
Metallic Knob 2
http://maniacdev.com/2012/06/ios-source-code-example-making-reflective-metallic-buttons-like-the-music-app
This is a tutorial on making reflective metal buttons. You can apply the techniques from the source code to whatever object you're trying to make. The source code is found here on github. I just googled "ios objective c metal effect" because that's what you're trying to do, right? The metal effect appears in concentric circles and changes as you tilt your phone, just as the iOS6 music slider does.
I don't have any code for you but the idea is actually quite simple. You're drawing a number of lines radiating from a single, central point (say 50,50) to four different sets of points. First set is for x = 0 to 100, y = 0. Second set is for y = 0 to 100, x = 0. Third set is for x = 0 to 100, y = 100. Fourth set is for y = 0 to 100, x = 100. And for each step you need to either change the colour from white to black or white to grey in increments or use a look up table with your colour values in it.

Is there any way to set Gradient with different Colors in Shinobi Controls for iOS

I have 4 SChartLineSeries (different line colors say Read, Green, Yellow, Blue). These all 4 may cross each others at any point. I have to fill it with Gradient also. My Points are :
If we have Yellow line at lowest place along with x-axis, we can manage the Gradient according to Yellow.
series.style.showFill = YES;
series.style.areaColor = [UIColor colorWithRed:65.0 / 255.0 green:165.0 / 255.0 blue:65.0 / 255.0 alpha:1];
series.style.areaColorLowGradient = [UIColor colorWithRed:35.0 / 255.0 green:75.0 / 255.0 blue:35.0 / 255.0 alpha:1];
BUT, if Red line crosses Yellow line at any point ( Yellow line is no longer at bottom place) and become the most bottom line. Now I have to make gradient effect in such a manner that Yellow Line will be having Gradient with Yellow effect under it and Red line will be having Gradient with Red effect under it. and so on.
AND, same for the line just above the most bottom line. we have to make gradient effect for it. and if other line crosses this then color for gradient should be change. and if third line cut the second one, again color is to be changed. and so on. BUT gradient effect should NOT go to bottom, it should be stopped where it meets to next line.
I have to show these effect for all lines.
So, any idea please.
Thanks for response.
It sounds like you'll need to stack your series and split your series into smaller series:
To stack your series, set the stackIndex property of each to the same NSNumber - for example:
lineSeries.stackIndex = #0;
This will mean that your line fills draw in bands, the 'lowest' up to the next lowest, and so on. You'll also need to provide the yValues for each datapoint as an offset from the previous (lower) series yValue for the same xValue.
This alone won't fix your issue with the lines overlapping though - to address this you can split your data into different sections (different series) at each point where the ordering of the series changes (whenever two lines cross). This approach means that your datasource will have to do a fair amount of work before you pass your data to the chart - and you may end up with lots of series - but it should produce the effect you're after. Hope this helps! =)
Disclaimer: I work on ShinobiCharts.

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