Show or hide components using Manipulate in Mathematica - graphics

How could I set a Controller to show or Hide a Graphic component of a Manipulate ?
Manipulate[Graphics[
{Pink, Disk[{1, 1}, r],
Green, Disk[{2, 2}, r]}],
{{r, 0.5, Style["Radius", Black, 16]}, 0.5, 5, 1,
Appearance -> "Labeled"}]
For example, in the above, How could I set a controller to Display or not the Green Circle ?
- Solution :
Manipulate[Graphics[{
If[thePink,
{Pink, Disk[{1, 1}, r]}],
If[theGreen,
{Green, Disk[{2, 2}, r]}]
}
],
{{r, 0.5, Style["Radius", Black, 16]}, 0.5, 5, 1,
Appearance -> "Labeled"},
{{thePink, True, "Pink"}, {True, False}},
{{theGreen, False, "Green"}, {True, False}}]

You can't really "hide" the green ball.
What is displayed is the result of the Manipulate expression evaluation. Manipulate works like this:
Manipulate[ expression, control_variables ]
When any control variable changes (dynamically), the expression is reevaluated and its results displayed. So, when you move the slider, you are changing a variable value, and hence the expression is being re-evaluated and its output displayed.
To "hide" anything, you then need to change the expression NOT to output the green ball. So, you need to add some control variable (say checkbox) and if set, then change the expression not to show the green ball. Simple logic test will do. For example
Manipulate[
Graphics[{Pink, Disk[{1, 1}, r], Green, If[show, Disk[{2, 2}, r]],
Sequence[]}], {{r, 0.5, "Radius"}, 0.5,
5}, {{show, True, "Show Green Circle?"}, {True, False}}]
EDIT:
WOw, thanks Simon, I was about to paste an example of doing just what you did when I saw your edit. thanks. It almost the same code as yours. Here it is might as well paste it :)
Manipulate[Graphics[
{ Pink,Disk[{1,1},r],
If[on,{Green,Disk[{2,2},r]}]
}] ,
{{r,0.5,"Radius"},0.5,5},
{{on,False,"show green ball"},{True,False}}
]

Perhaps:
Manipulate[
Graphics[{Pink, Disk[{1, 1}, r], Opacity[o],
Green, Disk[{2, 2}, r]}],
{{r, 0.5, "Radius"}, 0.5, 5},
{{o, 0.5, "Opacity"}, 0, 1}]

Related

how to get height of an entity in ursina?

I'm making a Brick Breaker Game using Ursina in python. I've created some entities which work as ball and bar.
bar = Entity(model='quad', color=color.blue, position=(4.5, -10, 0), scale=(3, 0.3), collider='box')
ball = Entity(model='sphere', color=color.red, position=(4.5, -9.5, 0), scale=0.25, collider='sphere')
I want the ball at the upper center of the bar without manually setting the x and y value. Like this:
For this I want the width and height of the bar. How can I get that? I tried bar.width. But it returns 'Entity' object has no attribute 'width'
Yes, it is possible. You can use bar.scale_x and bar.scale_y.
For more options you can check https://www.ursinaengine.org/api_reference and see Entity (https://www.ursinaengine.org/api_reference#Entity)

How to reduce size of customized scroll bar in Sublime Text 3

I have customized my scroll bar by referencing one answer from stackoverflow.
This is my Material-Theme-Darker.sublime-theme file
[
// More visible scrollbar
{
"class": "puck_control",
"layer0.texture": "User/theme_override/scroll_puck.png",
// Optional: set to your desired RGB color
"layer0.tint": [141, 234, 255],
"layer0.opacity": 1.0,
"layer1.opacity": 0.0,
"layer0.inner_margin": 2,
},
{
"class": "puck_control",
"attributes": ["horizontal"],
"layer0.texture": "User/theme_override/scroll_puck_horiz.png",
}
]
But the scroll bar is quite bold and I want it to be short in width so can anyone tell me how can I achieve it?
In order to make the scrollbar narrower, you need to edit User/theme_override/scroll_puck.png and scroll_puck_horiz.png so that it is narrower. Then, set "content_margin" to something like this:
"content_margin": [8, 12],
and play around with the first number until you get a width you like.

(fabric.js) Can I change a position of a character in iText for vertical writing?

I am Japanese, and I want to write Japanese words vertically in Fabric.js.
Japanese language has small letters, and the positions of the them are top-left corner in vertical writing.
So, I want to change the position of a small letter in iText.
I thought that I can change the position of a character by using "styles" parameter of iText, so I wrote as follows.
var iTextSample = new fabric.IText('h\ne\nl\nl\no', {
left: 50,
top: 50,
fontFamily: 'Helvetica',
fill: '#333',
lineHeight: 1.1,
styles: {
1: {
0: { textDecoration: 'underline', ←★ WORK
fontSize: 80, ←★ WORK
top:-10,  ←★ NOT WORK
transformMatrix: [ 1, 0, 0, 1, 18, -50 ] ←★ NOT WORK
},
},
}
});
https://jsfiddle.net/uemon/tLy9eqj6/77/
The 'textDecoration' and 'fontSize' worked, but the 'top' or 'transformMatrix' didn't work.
Can't I use 'top' or 'transformMatrix' in the "styles" parameter ?
How can I change the position of one character ?
Thank you in advance.
So from the use of textDecoration property i guess you are on the 1.7 or similar version.
You should really move to the 2.0 version that has integrated support for multibyte languages and composition.
Said that, there is no support for vertical text in fabricjs at all.
This may change in the future.
You should really go here:
https://github.com/kangax/fabric.js/issues/511
refresh the request and maybe add some detail about it, because the actual mantainer may have no clue on how vertical text should work regarding input, decorations, multiple columns and so on.

Hot to set line height in Sublime Text tab set control

I want to change the font size for a larger, but I can't change the line height, so that letters like g p q are "under cropped"
I haven't found solutions, seems than nobody has changed the labels line height on "tab set control" ¿?
I tried
"row_padding": [8, 3], // increase second value e.g. [8, 6]
"indent": 12,
and
"line_padding_bottom": 3,
"line_padding_top": 3
without success
Thanks
This is a known bug, with currently no workarounds (as at build 3126): https://github.com/SublimeTextIssues/Core/issues/694
EDIT: this has been fixed in build 3127.

How to fill a flot line graph without opacity?

How can i fill a flot line graph with no opacity?
lines: {
show: true,
fill: true,
lineWidth:1
}
I think you've mixed-up the terms 'opacity' and 'transparency'. It sounds like what you actually want is no transparency, i.e. a solid color that doesn't allow anything in the background to show through.
To control transparency in Flot, change the 'fill' option from 'true' to a number from 0 to 1, where 0 is fully-transparent and 1 is fully opaque. See customizing the data series in the API docs for more info.
Flot documentation agrees with DNS's answer, but at least in current stable version (0.8.1) I couldn't make it work.
Checking the Flot source I came up with this solution:
'bars': {
show: true,
fill: 1.0,
fillColor: 'rgba(255,230,230,0.5)',
lineWidth: 1,
}
I didn't test it for lines, but it should work with them too.
If you're using flotr2, you'll notice that none of these solutions work. Instead, try:
lines: {
fillOpacity:1.0,
show: true,
fill: true,
lineWidth:1
}

Resources