Jump by percentages (10%, 20%, 30%...) in MPV player, like on YouTube? - mpv

I'd like to reproduce this behavior:
Pressing the number keys 1-9 would automatically skip ahead in the current video to the corresponding percentage of time. So pressing "4" would jump to the 40% mark of the video, regardless of specific time length of the video. Basically similar to how this works on YouTube.
It seems there's no built-in method for this (and number keys are already assigned other tasks by default) but is there any sort of Lua Script that could achieve this?
Thank you

It was more simple than I anticipated. There is already a percentage command native to MPV. So to produce the desired behavior, I just added this to my input.conf file:
1 seek 10 absolute-percent
2 seek 20 absolute-percent
3 seek 30 absolute-percent
4 seek 40 absolute-percent
5 seek 50 absolute-percent
6 seek 60 absolute-percent
7 seek 70 absolute-percent
8 seek 80 absolute-percent
9 seek 90 absolute-percent

Related

How to look back a certain number of days for an indicator and how to only calculate logic upto the last complete bar (i.e. not the current bar)

I'm relatively new to Pine and was having trouble with a couple of things.
So I've got a indicator that I want to look back for the last 5 full days of activity, however not each stock trades in the premarket/afterhours so I want to be able to look back say 5 days and then calculate the number of bars on the time frame (i.e. for a 5 min or hourly resolution). That way I can calculate the number of bars present on the current ticker for that time frame and adjust my indicator length (instead of just having a constant figure of 80 bars or whatever).
The second thing I want to do is only have the indicator update on the completion of a full bar (for example the hourly resolution). So I want it to only calculate up to x-1 bars. Right now I'm finding that it's updating on each new tick. ( I was able to figure this one out, just changed it from i= 0 to length -1 to i=1 to length).
Any help is greatly appreciated.
Thanks,
A

Animation in LOGO

I have created a nice pattern using the following one line code
repeat 36 [repeat 10[fd 10 rt 36] rt 10]
Now I want this to appear as if it is rotating. I have tried to clear the screen and then rotate the turtle a at a specific angle and then print the pattern again. But there is something completely wrong in my logic. Can anybody help?
In order to accomplish animation, you need an interpreter which supports it. The interpreter must be one which renders the entire output before displaying it (doesn't show the turtle movement during drawing), and it also must support the wait command (or something similar to it). An example of an interpreter that meets these qualifications would be the one at www.logointerpreter.com. Here's an example which spins your wheel a full rotation and works with that interpreter:
ht
repeat 360
[
clean
repeat 36 [repeat 10[fd 10 rt 36] rt 10]
wait 10
rt 1
]
As you can see, the outer loop draws 360 separate frames. After drawing each frame, it waits 10 milliseconds, so you can see the frame. It then rotates the turtle one degree before clearing the screen and beginning the drawing of the next frame. If you need a little more control, you could also store the starting angle for each frame in a variable, like this:
ht
make "start 0
repeat 360
[
cs
rt :start
repeat 36 [repeat 10[fd 10 rt 36] rt 10]
wait 10
make "start (:start + 1)
]

Saving movement/path to database

I am creating a football simulation game and I would like to make a 2D view of match. My match is 90 minutes long and there are 22 players on the field. How could I save a movements/path for players so that it wouldn't take lots of space. I know I could save it something like
Minute: min,
Player: id,
X: xCoord,
Y: yCoord
and then just move objects with jQuery from point A to point B, but I am sure it isn't the best solution, because it would require lots of space and database entries.
I am using MongoDB, but all suggestions are welcome.
How do the players move? They move a little in each step of the main loop? Or they go in long straight lines and then make sudden turns and go in other straight lines? In the first case you would probably need to save each milisecond or so (each step of the main loop), or you could save their positions every ten steps or every second, etc. And the replay could interpolate the saved points (thought the replay would look "gross" like that, it could save a lot of space in your db). In the second case (straight lines), you could just save the points where the players turn in another direction. In this case you'll save their position, angle and speed (along with time, obviously).
The first table could be (the intervals could be more than 1ms, depending on the power of the machine):
PLAYER TIME(ms) X Y
1 0 0 0
1 1 0 2
1 2 0 4
1 3 0 7
1 4 0 10
1 5 4 13
While the second table would be:
PLAYER TIME(ms) X Y Dir Speed
1 0 0 0 90 2
1 2 0 4 90 3
1 4 0 10 60 5
or something like that. Dir is the direction in degrees. Hope that helps!

Highcharts zooming on x-axis with specific labelling

I've been searching through the highchart API and was unable to find a way to allow max zoom out to be (say) January, follow by the next tick is 7 months later which is July and so on. And at the same time to have the max zoom in to be 1 day only.
Example:
***Referring to above picture, at max zoom out (no zooming in) ==> x-axis label displaying Jan/2005 at the first tick, second tick is July/2005, third tick is Jan/2006, fourth tick is July/2006... and so on.
***Referring to above picture, user can at the same time zoom in to one day only max. (For this, i've done it with "minTickInterval: 24 * 3600 * 1000")
So I was able to set minimum tick interval is 1 day. However, i could not control the interval when zoom out to the max. I tried using "tickInterval" and it starts giving me 365 ticks each year on my x-axis at max zoom out. I also tried "minRange: 210 * 24 * 3600 * 1000 // 210 is # of days for 7 months", still no luck with no ticks down to days after zooming in. Currently for the max zoom out, the datetime label is auto scaled based on (i suppose) my chart or screen size.
Anyone got an idea how to do it or did i not use those api properly? I've been on this for almost a week already. Hope someone can help. Thanks.
You can use tickPositioner to define your own function which will set ticks positions.
http://api.highcharts.com/highcharts#xAxis.tickPositioner

Two jQuery Mobile sliders working together

I want to have 2 sliders in a JQM site which affect each other.
Slider 1 will change the number of months
Slider 2 will change the cost
Behind the scenes, there will be an amount, say $3600
By default, the number of months slider will be 36, therefore the cost slider would be $10
If the user changes the months slider to be 18, the cost slider should auto-change to $20 (since 20 * 18 = £3600)
Likewise, if the user changes the cost slider to $20, the months slider should move to 18 months.
I added a bind("onchange") to both sliders but ended up with a "Maximum callsize stack exceeded" error.
I have tried using event.originalEvent and event.preventDefault but to no avail.
How would I go about getting these 2 to work with each other so that if 1 is updated, the other also recalculates and vice versa?
Thanks
The refresh seems to be the thing that triggers the change event so now I die() the event before calling refresh, then create it again
$("#Months").val(42);
// remove binding
$("#Months").die("change");
$("#Months").slider("refresh");
$("#Months").live("change", ChangeMonths);
Seems to work, maybe not pretty but oh well

Resources