Octave: Change color in drawArrow - plot

I found this answer
[Octave : How to change line color and width in drawRect
how to change the color in drawRect.
When I try the same for drawArrow, I get:
h=drawArrow(0,0,3,1,1,1,1,1);
h =
scalar structure containing the fields:
body = -12.469
head = -11.925
set(h,'color','r');
error: octave_base_value::array_value():
wrong type argument 'scalar struct'
error: set: H must be a graphics handle
What I am doing wrong here? For me it looks the same.
Thanks
Karl

You really should mention that you are using the octave-forge geometry package. drawArrow returns a struct with handles for the arrow body and head (as shown by your code) so you can and have to set them separately:
pkg load geometry
h = drawArrow (0,0,3,1,1,1,1,1);
set (h.body, "color", "r")
set (h.head, "facecolor", get(h.body, "color"))
You can also set a border around the head with "edgecolor"

Related

In Godot the path returned by get_simple_path() seems offset by something

Just learning Godot, so maybe missing something obvious
I am trying to have the player navigate towards a point clicked on the map.
The path is calculated with some sort of offset I can't figure out.
Any pointers appreciated!
There is a very minimal replication of the problem here
https://github.com/kender99/Godot_path_finding_problem_demo
On the image the white dot is the mouse click and the red is the path generated
The likely offending code is:
extends Node2D
var path : = PoolVector2Array()
func _unhandled_input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
path = $Navigation2D.get_simple_path($Player.position, event.position)
$Player.path = path
$Line2D.points = path
print(path.size(), ' Path:',path, ' Player:', $Player.position, ' Target:', event.position)
update() # so line and circles get drawn
func _draw():
for p in path:
draw_circle(p, 5, Color(200, 200, 200))
event.position is the local position regards the current respondent, you should convert the event position to the local one of Navigation2D instead, like this:
path = $Navigation2D.get_simple_path($Player.position, $Navigation2D.to_local(event.position))
or use get_global_mouse_position() method like this:
path = $Navigation2D.get_simple_path($Player.position, $Navigation2D.to_local(get_global_mouse_position()))

Scilab plot with many lines: automatic cycling trough 'LineSpec' styles

I am plotting around 10 Lines in the same plot and use the built-in option of plot to cycle through colors. Sadly, this option only has 7 colors and then starts with the first color again. Is there an option like in Matlab to get a different line type, when the colors cycled through once?
I know I can change the color and line style manually for every line, but I would prefer an automatic solution.
I do not know a built-in way to do this, but reading the Linespec man page, you could create a function to cycle trough all specifiers.
The simplest of them being :
function Linespec=CycleSpec(n)
// n : from 0 to N
Linestyle =['-';'--';':';'-.']
Linecolor = ['r';'g';'b';'c';'m';'y';'k';'w']
Linemarker =['';'+';'o';'*';'.';'x';'s';'d';'^';'v';'>';'<';'p']
i = modulo(n,size(Linecolor,'*'))+1
j = modulo(floor(n/size(Linecolor,'*')),size(Linestyle,'*'))+1
k = modulo(floor(n/size(Linecolor,'*')/size(Linestyle,'*')),size(Linemarker,'*'))+1
Linespec = Linestyle(j)+Linecolor(i)+Linemarker(k)
endfunction
Which could be use as
figure(1)
for n=0:40
plot(x,x+n,CycleSpec(n))
end
And if you really want something simple, we can add a global variable storing the counter so you only need to call the function, no need for parameter
function Linespec=CycleSpec()
// n : from 0 to N
global CycleSpecCounter
if CycleSpecCounter==[] then
CycleSpecCounter = 0
end
n=CycleSpecCounter
[...] same code as before [...]
CycleSpecCounter=CycleSpecCounter+1
endfunction
and you'd only need to type
plot(x,x+n,CycleSpec())

sunburst.R total frequency count is incorrect

I am plotting a sunburst donut and I cannot figure out why the total is incorrect.
library(sunburstR)
reports <- data.frame(
sequence = c("SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-No VP-Dir-end","SVP-No VP-Dir-end","SVP-No VP-Dir-end"),
freq = as.numeric(c("167","60","51","32","5","1","1")))
sunburst(reports, count = TRUE)
It is supposed to be 100% 317 of 317 . Anyone know how to fix this? There is not much documentation on this great package.
Also, I would like it to have a default value in the center of donut.
If there is another way to create an interactive donut using R, please let me know.
Thanks you in advance.
It looks like the default function generating the message in the center of the donut rounds the total value to the nearest ten.
But you can customize this function using the explanation argument of sunburst. Oddly, the customized function (in javascript) must be provided as a string.
Try the following function:
custom.message = "function (d) {
root = d;
while (root.parent) {
root = root.parent
}
p = (100*d.value/root.value).toPrecision(3);
msg = p+' %<br/>'+d.value+' of '+root.value;
return msg;
}"
Now:
sunburst(reports, explanation = custom.message )
will generate the donut displaying exact total values. The count argument is no longer needed, as it is used by the default explanation function.
The value returned by custom.message is html code. As you can see, I've just inserted a line break (<br/>). You can modify the msg return value to further customize the look and feel.

unable to get tredns in twitteR argument "woeid" is missing, with no default

I would like to get trends, using packages"twitteR". When I type searchTwitter(""0, it works. However, when I type getTrends(period=""), it shows: Error in getTrends(period = "weekly") :
argument "woeid" is missing, with no default
How can I fix this problem?
The woeid specifies the the location in order to pull the trends for a given place/country. To get the global Trends you can use getTrends(1)
To find a desired woeid you can use the function:
a_trends = availableTrendLocations()
head(a_trends)
Or:
closeTrends = closestTrendLocations(your_lon, your_lat)
head(closeTrends)

Height required for UILabel dependent on string length (Swift, iOS 8)

I am struggling to get the height that is required for a UILabel based on variable sized text that it could accept. From hours of research, I have not yet discovered a viable way of achieving this. Currently my code is as follows:
func getHeightForTitle(postTitle: NSString) -> CGFloat {
// Get the height of the font
let constraintSize = CGSizeMake(self.cellTextWidth, CGFloat.max)
let attributes = [NSFontAttributeName: [UIFont.systemFontOfSize(16.0)]]
let labelSize = postTitle.boundingRectWithSize(constraintSize,
options: NSStringDrawingOptions.UsesLineFragmentOrigin,
attributes: attributes,
context: nil)
return labelSize.height
}
This however throws the following error:
2014-08-02 12:09:37.370 Testing App[8365:351906] - [_TtCSs23_ContiguousArrayStorage00007FD26C15F708 pointSize]: unrecognized selector sent to instance 0x11e640050
This is always thrown at the let labelSize = postTitle... method and I believe it is down to the attributes variable. I however maybe wrong. Any help is appreciated, and much thanked!
Please note: This is for an iOS 8, Swift development project.
Two observations. First, what's wrong with your code is that this line is not Swift:
let attributes = [NSFontAttributeName: [UIFont.systemFontOfSize(16.0)]]
The stuff after the equals sign is Objective-C, and Swift is having trouble interpreting it. Remove the square brackets from around the UIFont call; you have turned this into an array, which is the source of the error you're seeing.
Second, and more important, there are many much simpler ways to do this, by letting the label tell you its size for the desired text:
Put the text into the label and call sizeToFit() on the label.
Put the text into the label and call sizeThatFits() on the label with the desired width and large height.
Under auto layout, set the label's preferredMaxLayoutWidth to the desired width and put the text into the label; it will size itself.
However, I would urge you not to do this if you don't have to. A label is already self-sizing under auto layout, and in iOS 8 there's a new feature where a table cell will self-adjust its height to its contents, so there is now very rarely a need to pre-measure a label's dimensions.
Put the text into the label and call sizeThatFits() on the label with the desired width and large height.
sub_label=UILabel(frame: CGRectMake(0, 0, self.view.bounds.width, 50))
sub_label.numberOfLines=0;
sub_label.textAlignment=NSTextAlignment.Left
sub_label.lineBreakMode=NSLineBreakMode.ByWordWrapping
let subfont = UIFont(name: "Helvetica", size: 20.0)
sub_label.font=subfont
sub_label.text="his is just a load of texthis is just a load of texthis is just a load of texthis is just a load of texthis is just a load of texthis is just a load of text"
sub_label.backgroundColor=UIColor.clearColor()
var textViewSizesub=sub_label.sizeThatFits(CGSizeMake(self.view.bounds.width, CGFloat.max))
sub_label.frame=CGRectMake(0, textViewSize.height, self.view.bounds.width-5, textViewSizesub.height)

Resources