Toy project to learn Flutter/Dart.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.4 KiB

import 'dart:math';
import 'package:flutter/material.dart';
// random generator for particles
var rng = Random();
// status of the pokemon
enum Status {
undefined,
visited,
accepted,
rejected,
favorite,
}
// convert status to byte
int statusToByte(Status status) {
switch(status) {
case Status.undefined: {return 0;}
case Status.visited: {return 1;}
case Status.accepted: {return 2;}
case Status.rejected: {return 3;}
case Status.favorite: {return 4;}
}
}
// convert byte to status
Status byteToStatus(int byte) {
switch(byte) {
case 0: {return Status.undefined;}
case 1: {return Status.visited;}
case 2: {return Status.accepted;}
case 3: {return Status.rejected;}
case 4: {return Status.favorite;}
default: {return Status.undefined;} // should not happen
}
}
// colors used to reprent these status
const undefinedColor = Color.fromARGB(255, 0, 0, 0); // black
const visitedColor = Color.fromARGB(255, 150, 150, 150); // gray
const acceptedColor = Color.fromARGB(255, 100, 255, 100); // green
const rejectedColor = Color.fromARGB(255, 255, 100, 100); // red
const favoriteColor = Color.fromARGB(255, 255, 222, 0); // yellow
// a function to get the color corresponding to a status
Color statusColor(Status status) {
switch(status) {
case Status.undefined: {return undefinedColor;}
case Status.visited: {return visitedColor;}
case Status.accepted: {return acceptedColor;}
case Status.rejected: {return rejectedColor;}
case Status.favorite: {return favoriteColor;}
}
}
// emojis of particles related to this status
String animEmoji(Status status) {
switch(status) {
case Status.accepted: {return "❤️";}
case Status.rejected: {return "🤢";}
case Status.favorite: {return "⭐️";}
default: {return "";}
}
}
// represent an integer on three digits
String padint(int n) {
return n.toString().padLeft(3, '0');
}
// clip widget to star shape using no complex dependencies because they look like shit
class StarClipper extends CustomClipper<Path> {
Path _getStarPath(double size) {
Path p = Path();
double outerRadius = size/2;
double innerRadius = outerRadius * 0.5;
double angle = 5/4 - 0.5;
List<double> inner = [0.0-angle,1.0-angle,2.0-angle,3.0-angle,4.0-angle,];
List<double> outer = [0.5-angle,1.5-angle,2.5-angle,3.5-angle,4.5-angle,];
p.addPolygon([
Offset(innerRadius*cos(2*pi*inner[0]/5)+size/2, innerRadius*sin(2*pi*inner[0]/5)+size/2),
Offset(outerRadius*cos(2*pi*outer[0]/5)+size/2, outerRadius*sin(2*pi*outer[0]/5)+size/2),
Offset(innerRadius*cos(2*pi*inner[1]/5)+size/2, innerRadius*sin(2*pi*inner[1]/5)+size/2),
Offset(outerRadius*cos(2*pi*outer[1]/5)+size/2, outerRadius*sin(2*pi*outer[1]/5)+size/2),
Offset(innerRadius*cos(2*pi*inner[2]/5)+size/2, innerRadius*sin(2*pi*inner[2]/5)+size/2),
Offset(outerRadius*cos(2*pi*outer[2]/5)+size/2, outerRadius*sin(2*pi*outer[2]/5)+size/2),
Offset(innerRadius*cos(2*pi*inner[3]/5)+size/2, innerRadius*sin(2*pi*inner[3]/5)+size/2),
Offset(outerRadius*cos(2*pi*outer[3]/5)+size/2, outerRadius*sin(2*pi*outer[3]/5)+size/2),
Offset(innerRadius*cos(2*pi*inner[4]/5)+size/2, innerRadius*sin(2*pi*inner[4]/5)+size/2),
Offset(outerRadius*cos(2*pi*outer[4]/5)+size/2, outerRadius*sin(2*pi*outer[4]/5)+size/2),
], true);
return p;
}
@override
Path getClip(Size size) => _getStarPath(size.height);
@override
bool shouldReclip(oldClipper) => false;
}