There are few code available regarding this subject.
If you are interested in the learning aspect, this article is good:
Learning Vision-based Flight in Drone Swarms by Imitation
IEEE ROBOTICS AND AUTOMATION LETTERS. PREPRINT VERSION. ACCEPTED JULY, 2019
Another very good article - WITH CODE (at least should be released soon): a drone is following a target with an AprilTag - the target can be the considered as the leader.
Fast-Tracker: A Robust Aerial System for Tracking Agile Target in Cluttered Environments
https://arxiv.org/pdf/2011.03968v1.pdf
code:https://github.com/ZJU-FAST-Lab/Fast-tracker
Regarding source code, another place to look at is:
Multi-robot Systems (MRS) group at Czech Technical University in Prague
https://github.com/ctu-mrs
Please look at the video that may fit your need: https://www.youtube.com/watch?v=Ax3ONfo1hMA