Carmelo Anthony calls Bernard King his idol. The two are a couple of shooting stars from Brooklyn, separated only by basketball generations.

Melo did his best Bernard imitation yesterday at the Garden as he scorched the Pistons, hitting his first six shots, scoring 21 points in the first half from every angle, including a glorious Bernard-like baseline jumper. He finished with 29 points in 31 minutes as the Knicks rolled to an easy 121-100 victory over the Pistons.

This game was a glorified shoot-around in preparation for tonight’s Brooklyn Battle between the Nets and Knicks, the game The City has been waiting for all season.

The Knicks needed to get some things right yesterday after two terrible losses in Texas and they did. In the locker room, Mike Woodson made sure priorities were listed, including this: “Be aggressive from the start.’’

Anthony personified that aggressiveness and will need to bring the same game to Brooklyn that he brought against the Pistons, the quick starts he has been bringing all season to the Knicks.

This was the perfect tune-up and when Anthony was asked what would be on his mind as he walks onto the floor at Barclays Center, he did not pull up, he went strong to the hoop.

“Just to step on that court and to see the Brooklyn logo on that basketball court I’ll feel like I’m home,’’ said Anthony, who spent his early years in Brooklyn.

It’s all about being “home’’ in the NBA.

Then as Anthony walked out of the locker room I mentioned Bernard King’s name to him. He smiled and said, “That’s my man. That’s Brooklyn, too.’’

Yes, it is.

King played for the Nets and Knicks, making his greatest mark as a Knick. Anthony is going to have to continue his King-like scoring for these Knicks to get where they want to go. He’s going to have to carry the offense and be a leader.

This was a good test as the Knicks had to bounce back from back-to-back beat-downs in Texas, allowing 131 points to the Rockets and 111 to the Mavericks. The Knicks had to win this game to put their confidence at a high level again, and Anthony got them rolling to 5-0 at home.

“He’s been playing at a high level and we’ve kind of come to expect it,’’ Woodson said.

Carmelo was 4-for-5 from 3-point range as the Knicks buried 17-of-33 three-point attempts. That is who they are. They took 39 3-pointers against the Rockets, hitting 17, and 31 against the Mavs, sinking 15. You can be sure tonight they will be hoisting up the threes against the Nets.

“Shoot, the rim is the same height,’’ Woodson said of shooting 3-pointers on the road. “It’s a different floor. You’ve got to think you can make it.’’

Steve Novak produced 18 points off the bench, draining five of seven three-pointers and pointed to Anthony as the key.

Raymond Felton said it all: “Carmelo has just been a great leader, on the court, off the court, just sacrificing whatever for us to win. He’s been giving up his body, he’s been playing defense. Everybody knows he can score, but he’s been doing all the little things to help this team win.’’

Anthony did that yesterday at the Garden and tonight must do it all over again in Brooklyn against a much tougher team.