Last active
June 13, 2024 13:30
-
-
Save nobuh/63c396c3695c99c0457ffddf6df62feb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
double width = 400; | |
double height = 400; | |
double thick = 4; | |
double side = 109; | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar(title: Text('Wallpaper')), | |
body: Center( | |
child: CustomPaint( | |
painter: MyCustomPainter(), | |
child: Container( | |
width: width, | |
height: height, | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class MyCustomPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
final paint = Paint() | |
..color = Colors.black | |
..strokeWidth = 1.0; | |
for (double i = 1; i <= 100; i++) { | |
for (double j = 1; j <= 100; j++) { | |
double x = i * side / 100; | |
double y = j * side / 100; | |
int c = (x * x + y * y).toInt(); | |
if (c % 2 == 0) { | |
plot(i, j, thick, paint, canvas); | |
} | |
} | |
} | |
} | |
void plot(double x, double y, double thick, Paint p, Canvas c) { | |
c.drawRect( | |
Rect.fromPoints( | |
Offset(x * thick, y * thick), | |
Offset((x + 1) * thick, (y + 1) * thick), | |
), | |
p); | |
} | |
@override | |
bool shouldRepaint(covariant CustomPainter oldDelegate) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment