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
def toRoman(i:int)->str: | |
sym = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"] | |
num = [1000,900,500,400,100,90,50,40,10,9,5,4,1] | |
result = "" | |
while i > 0: | |
for j in range(len(num)): | |
m = i // num[j] | |
result += sym[j] * m | |
i = i % num[j] | |
return result |
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 'dart:core'; | |
import 'dart:math'; | |
class Vector { | |
List<num> vec; | |
Vector(List<num> el) { | |
vec = el; | |
} | |
operator [](index) => vec[index]; |
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 'dart:async'; | |
import 'package:flutter/material.dart'; | |
class Test extends StatefulWidget { | |
@override | |
_TestState createState() => _TestState(); | |
} | |
class _TestState extends State<Test> { |
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
class DataItem { | |
final double value; | |
final String label; | |
final Color color; | |
DataItem(this.value, this.label, this.color); | |
} |
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
void main() { | |
runApp(MyApp()); | |
} | |
const pal = [0xFFF2387C, 0xFF05C7F2, 0xFF04D9C4, 0xFFF2B705, 0xFFF26241]; | |
class MyApp extends StatelessWidget { | |
final List<DataItem> dataset = [ | |
DataItem(0.2, "Comedy", Color(pal[0])), | |
DataItem(0.25, "Action", Color(pal[1])), |
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
class DonutChartWidget extends StatefulWidget { | |
final List<DataItem> dataset; | |
DonutChartWidget(this.dataset); | |
@override | |
_DonutChartWidgetState createState() => _DonutChartWidgetState(); | |
} | |
class _DonutChartWidgetState extends State<DonutChartWidget> { | |
@override | |
Widget build(BuildContext context) { |
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
class DonutChartPainter extends CustomPainter { | |
final List<DataItem> dataset; | |
DonutChartPainter(this.dataset); | |
@override | |
void paint(Canvas canvas, Size size) { | |
final c = Offset(size.width / 2.0, size.height / 2.0); | |
final radius = size.width * 0.9; | |
final rect = Rect.fromCenter(center: c, width: radius, height: radius); | |
final fullAngle = 360.0; |
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
void drawSector(Canvas canvas, DataItem di, Rect rect, double startAngle, | |
double sweepAngle) { | |
final paint = Paint() | |
..style = PaintingStyle.fill | |
..color = di.color; | |
canvas.drawArc(rect, startAngle, sweepAngle, true, paint); | |
} |
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
TextPainter measureText( | |
String s, TextStyle style, double maxWidth, TextAlign align) { | |
final span = TextSpan(text: s, style: style); | |
final tp = TextPainter( | |
text: span, textAlign: align, textDirection: TextDirection.ltr); | |
// ellipsis: "..."); | |
tp.layout(minWidth: 0, maxWidth: maxWidth); | |
return tp; | |
} |
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
void drawLabels(Canvas canvas, Offset c, double radius, double startAngle, | |
double sweepAngle, String label) { | |
final r = radius * 0.4; | |
final dx = r * cos(startAngle + sweepAngle / 2.0); | |
final dy = r * sin(startAngle + sweepAngle / 2.0); | |
final position = c + Offset(dx, dy); | |
drawTextCentered(canvas, position, label, labelStyle, 100.0, (Size sz) { | |
final rect = Rect.fromCenter( | |
center: position, width: sz.width + 5, height: sz.height + 5); | |
final rrect = RRect.fromRectAndRadius(rect, Radius.circular(5)); |