A Dunfermline teenager was arrested after causing trouble in Aberdour where a large group of youths had been drinking at Silver Sands beach.
He was removed from a bus, shouted and swore at police then got himself into further trouble at the police station.
Raivis Burkevics, 18, of Lomond Crescent, appeared for sentencing at Dunfermline Sheriff Court.
He previously admitted that on May 19 at Station Place, Aberdour, and Dunfermline police station he behaved in a threatening or abusive manner by repeatedly shouting, swearing, struggling violently with police officers and made offensive remarks.
He also admitted that at Dunfermline police station, he resisted, obstructed or hindered a police officer by lashing out with his legs and struck him on the body.
Defence solicitor Peter Robertson previously said his client had got himself arrested because of his “petulant” behaviour and he later lashed out when at the police station during a strip search.
Depute fiscal Azrah Yousaf told the court police had been called to an incident at the Silver Sands beach where a group of young people had gathered.
The youths were moved away from the beach to a bus stop. They were told to get on a bus and the police followed behind in their vehicle.
At a bus stop in Station Place the accused got on and the driver then indicated for the police to come over.
“He told them that the accused had not shown a valid ticket and had been cheeky to him,” said the depute.
Burkevics started shouting and swearing at the officers then sat in the police car refusing to leave.
Residents in the area became concerned about the shouting and swearing being heard by children in their own homes.
Eventually, Burkevics was arrested and began to struggle, complaining that the officers were “bullies”.
Other comments included: “You’re racists. You’re only doing this because I’m black.”
Mr Robertson said: “It perhaps shows he needs to grow up. He’d been with friends and had been drinking. When he was ejected from the bus he was stranded and didn’t know how to get home.”
Sheriff Alison McKay imposed a community payback order with 75 hours of unpaid work.