The coordinates of the k-th center will be (rcos kx, rsin kx) where r is the radius, and x = 2*pi/n where n is the number of circles you need.
Here is the example how to do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import 'dart:math'; import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: CustomPaint( foregroundPainter: CustomCirclesPainter(), ), ), ), ); } } class CustomCirclesPainter extends CustomPainter { var myPaint = Paint() ..color = Colors.black ..style = PaintingStyle.stroke ..strokeWidth = 5.0; double radius = 80; @override void paint(Canvas canvas, Size size) { int n = 10; var range = List<int>.generate(n, (i) => i + 1); for (int i in range) { double x = 2 * pi / n; double dx = radius * cos(i * x); double dy = radius * sin(i * x); canvas.drawCircle(Offset(dx, dy), radius, myPaint); } } @override bool shouldRepaint(CustomPainter oldDelegate) { return true; } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.