Welcome!
See the code for this example below.
Check out the Processing reference page for more ideas.