Skip to content

Commit

Permalink
Interpolate colors in Oklab space i/o HSV
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Dec 30, 2023
1 parent cbce2a5 commit 65f2a5d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
42 changes: 37 additions & 5 deletions example/pubspec.lock
Expand Up @@ -105,6 +105,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
color_models:
dependency: transitive
description:
name: color_models
sha256: "3683f0a461570161ca22b7d3e1765b2ce2bce3534db14e00d5ee458d0287abac"
url: "https://pub.dev"
source: hosted
version: "1.3.3"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -215,6 +223,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_color_models:
dependency: transitive
description:
name: flutter_color_models
sha256: "8454198ba9a82e533452d0764f1df3d6c3ccc2b33e18eb1f2fedc7ae4a5c43be"
url: "https://pub.dev"
source: hosted
version: "1.3.3+2"
flutter_lints:
dependency: transitive
description:
Expand Down Expand Up @@ -307,10 +323,18 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
num_utilities:
dependency: transitive
description:
name: num_utilities
sha256: "170695bcafd17a19ee3a060325e7e10fb35bb878c8bcb3e6f5691dde1462c0ae"
url: "https://pub.dev"
source: hosted
version: "1.0.5"
oxidized:
dependency: transitive
description:
Expand Down Expand Up @@ -359,6 +383,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.2.2"
powers:
dependency: transitive
description:
name: powers
sha256: "389ba222d4264655ecd3ffa461921bc707a07e4597b98831d21dd516eed6f496"
url: "https://pub.dev"
source: hosted
version: "1.0.0+2"
pub_semver:
dependency: transitive
description:
Expand Down Expand Up @@ -505,10 +537,10 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand All @@ -534,5 +566,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.10.0"
9 changes: 7 additions & 2 deletions lib/src/app_bar/state.dart
Expand Up @@ -3,6 +3,7 @@ import 'dart:ui';
import 'package:black_hole_flutter/black_hole_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_color_models/flutter_color_models.dart';

import 'leading.dart';

Expand Down Expand Up @@ -55,8 +56,12 @@ class MorphingState {
SystemUiOverlayStyle get systemOverlayStyle =>
t < 0.5 ? parent.systemOverlayStyle : child.systemOverlayStyle;

static Color _lerpColor(Color a, Color b, double t) =>
HSVColor.lerp(HSVColor.fromColor(a), HSVColor.fromColor(b), t)!.toColor();
/// Interpolate between colors in Oklab space.
static Color _lerpColor(Color a, Color b, double t) {
return OklabColor.fromColor(a)
.interpolate(OklabColor.fromColor(b), t)
.toColor();
}
}

@immutable
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Expand Up @@ -15,6 +15,7 @@ dependencies:
collection: ^1.15.0
flutter:
sdk: flutter
flutter_color_models: ^1.3.3+2
list_diff: ^2.0.0

dev_dependencies:
Expand Down

0 comments on commit 65f2a5d

Please sign in to comment.