What you are asking is a variation of
Both are quite complex to achieve. I am gonna close this FR and suggest you post in the FR above.
There are also some narrower FRs in this vein, like: