gpt4 book ai didi

flutter - 如何绘制重叠的圆圈

转载 作者:IT老高 更新时间:2023-10-28 12:37:30 26 4
gpt4 key购买 nike

我需要对这些白色交织的圆圈(不是背景)进行编码:

enter image description here

我知道如何画一个圆圈。让我难以理解的是数学。

注意:是的,三角学是高中的东西,我很清楚。

最佳答案

正如bereal所说:

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.

这里是如何做到这一点的例子:

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;
}
}

关于flutter - 如何绘制重叠的圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55316829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com