Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91125987
hexagonPainter.Dart
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 8, 04:28
Size
1 KB
Mime Type
text/x-c++
Expires
Sun, Nov 10, 04:28 (2 d)
Engine
blob
Format
Raw Data
Handle
22199690
Attached To
R10646 Orchestration
hexagonPainter.Dart
View Options
import 'package:flutter/material.dart';
import 'dart:math' as math;
class HexagonPainter extends CustomPainter {
static const int SIDES_OF_HEXAGON = 6;
final double radius;
final Offset center;
final Color colorHexagon;
HexagonPainter(this.center, this.radius, this.colorHexagon);
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()..color = colorHexagon;
Path path = createHexagonPath();
canvas.drawPath(path, paint);
}
Path createHexagonPath() {
final path = Path();
var angle = (math.pi * 2) / SIDES_OF_HEXAGON;
Offset firstPoint = Offset(radius * math.cos(0.0), radius * math.sin(0.0));
path.moveTo(firstPoint.dx + center.dx, firstPoint.dy + center.dy);
for (int i = 1; i <= SIDES_OF_HEXAGON; i++) {
double x = radius * math.cos(angle * i) + center.dx;
double y = radius * math.sin(angle * i) + center.dy;
path.lineTo(x, y);
}
path.close();
return path;
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
Event Timeline
Log In to Comment