1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/experimental/varfont_shader_puzzle/lib/components/wonky_anim_palette.dart
Brian James 057728c5d2 added Type Jam puzzle app for review (#1554)
* added Type Jam puzzle app for review

* pr round 2 prep

* updated ci scripts for varfont_shader_puzzle

* resolved unused and minor variable naming issues

* rotator tiles row and col are final vars now

* removed unused import and print from production

* made constructors const where needed

* pages_flow export refactored to directly come from that file

* removed old api commented out section from FragmentShaded

* updated pubspec yaml to correct project name

* dart min version updated; removed unnecessary commented out dependencies from pubspec.yaml

* updated pubspec.yaml min flutter version to ensure FragmentShader support

* added/edited comments for explanation, esp on var fonts; removed obsolete comments

* trailing newline added to pubspec.yaml eof
2023-01-13 10:40:47 +10:00

335 lines
7.5 KiB
Dart

// Copyright 2023 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math';
import 'package:flutter/material.dart';
import '../components/components.dart';
// WonkyAnimPalette class is meant to be used with WonkyChar
// to create animations based on variable font settings (aka 'axes'),
// and a few basic settings like scale, rotation, etc.
// The choice of variable font axes to implement in this class and
// default min/max values for variable font axes are hard-coded
// for Amstelvar font, packaged and used in this project.
// Other variable fonts will have different available axes and min/max values.
//
// See articles on variable fonts at https://fonts.google.com/knowledge/topics/variable_fonts
// See a list of variable fonts in the Google Fonts lineup, along with
// an enumeration of variable font axes at https://fonts.google.com/variablefonts
class WonkyAnimPalette {
const WonkyAnimPalette({
Key? key,
});
static const Curve defaultCurve = Curves.easeInOut;
// basic (settings unrelated to variable font)
static WonkyAnimSetting scale({
double from = 1,
double to = 2,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'basic',
property: 'scale',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting offsetX({
double from = -50,
double to = 50,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'basic',
property: 'offsetX',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting offsetY({
double from = -50,
double to = 50,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'basic',
property: 'offsetY',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting rotation({
double from = -pi,
double to = pi,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'basic',
property: 'rotation',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting color({
Color from = Colors.blue,
Color to = Colors.red,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'basic',
property: 'color',
fromTo: RangeColor(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
// font variants (variable font settings)
static WonkyAnimSetting opticalSize({
double from = 8,
double to = 144,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'opsz',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting weight({
double from = 100,
double to = 1000,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'wght',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting grade({
double from = -300,
double to = 500,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'GRAD',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting slant({
double from = -10,
double to = 0,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'slnt',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting width({
double from = 50,
double to = 125,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'wdth',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting thickStroke({
double from = 18,
double to = 263,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'XOPQ',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting thinStroke({
double from = 15,
double to = 132,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'YOPQ',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting counterWd({
double from = 324,
double to = 640,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'XTRA',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting upperCaseHt({
double from = 500,
double to = 1000,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'YTUC',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting lowerCaseHt({
double from = 420,
double to = 570,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'YTLC',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting ascenderHt({
double from = 500,
double to = 983,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'YTAS',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting descenderDepth({
double from = -500,
double to = -138,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'YTDE',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
static WonkyAnimSetting figureHt({
double from = 425,
double to = 1000,
double startAt = 0,
double endAt = 1,
Curve curve = defaultCurve,
}) {
return WonkyAnimSetting(
type: 'fv',
property: 'YTFI',
fromTo: RangeDbl(from: from, to: to),
startAt: startAt,
endAt: endAt,
curve: curve,
);
}
}