Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New animation(s) #135

Merged
merged 8 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions funvas_gallery/lib/factories/animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ final funvasFactories = <int, FunvasFactory<FunvasTweetMixin>>{
18: FunvasFactory(() => Eighteen()),
19: FunvasFactory(() => Nineteen()),
22: FunvasFactory(() => TwentyTwo()),
34: FunvasFactory(() => ThirtyFour()),
35: FunvasFactory(() => ThirtyFive()),
};

/// Funvas factory for a WIP funvas that does not need to have an associated
Expand Down
4 changes: 2 additions & 2 deletions funvas_tweets/export/export_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import 'package:funvas_tweets/funvas_tweets.dart';

void main() {
const fps = 50;
const animationDuration = Duration(seconds: 6);
const animationDuration = Duration(milliseconds: 6700);
const dimensions = Size(750, 750);
// If you use a different animation name, you will have to also consider that
// when exporting to GIF.
const animationName = 'animation';
// Using a callback so that the constructor is run inside of the test.
Funvas funvasFactory() => ThirtyFour();
Funvas funvasFactory() => ThirtyFive();

late final ValueNotifier<double> time;

Expand Down
1 change: 1 addition & 0 deletions funvas_tweets/lib/funvas_tweets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export 'package:funvas_tweets/src/31.dart';
export 'package:funvas_tweets/src/32.dart';
export 'package:funvas_tweets/src/33.dart';
export 'package:funvas_tweets/src/34.dart';
export 'package:funvas_tweets/src/35.dart';
export 'package:funvas_tweets/src/tweet_mixin.dart';

/// This package contains funvas animations from @creativemaybeno's tweets.
Expand Down
9 changes: 7 additions & 2 deletions funvas_tweets/lib/src/34.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import 'dart:math';
import 'dart:ui';

import 'package:funvas/funvas.dart';
import 'package:funvas_tweets/src/tweet_mixin.dart';
import 'package:open_simplex_2/open_simplex_2.dart';

class ThirtyFour extends Funvas {
class ThirtyFour extends Funvas with FunvasTweetMixin {
@override
String get tweet =>
'https://twitter.com/creativemaybeno/status/1417424043934818305?s=20';

/// Base precision for the paths being drawn.
///
/// A value of `2` will result in twice as many path segments per circle
Expand All @@ -29,7 +34,7 @@ class ThirtyFour extends Funvas {

static const _dimension = 750.0, _period = 6, _n = 21, _seed = 42;

final _noise = OpenSimplex2S(_seed);
final _noise = OpenSimplex2F(_seed);

@override
void u(double t) {
Expand Down
91 changes: 91 additions & 0 deletions funvas_tweets/lib/src/35.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import 'dart:math';
import 'dart:ui';

import 'package:funvas/funvas.dart';
import 'package:funvas_tweets/src/34.dart';
import 'package:funvas_tweets/src/tweet_mixin.dart';
import 'package:open_simplex_2/open_simplex_2.dart';

/// Based on [ThirtyFour] with some slight adjustments.
class ThirtyFive extends Funvas with FunvasTweetMixin {
@override
String get tweet => 'https://twitter.com/creativemaybeno';

/// Base precision for the paths being drawn.
///
/// A value of `2` will result in twice as many path segments per circle
/// as `1`.
static const _precision = 250;

/// Disturbance for the roundness of the circles drawn (= how much the noise
/// distorts the circle paths).
static const _disturbance = 424.24;

/// How much the circles should be distorted over time.
///
/// This is similar to [_disturbance] but only affects the relative speed of
/// the distortions, where bigger is faster.
static const _wobbliness = 1 / 8;

/// How many times a circle should reappear (from the center) within the
/// [_period].
///
/// The larger the faster the circles grow.
static const _revolutions = 4;

static const _dimension = 750.0, _period = 16, _n = 30, _seed = 42;

final _noise = OpenSimplex2F(_seed);

@override
void u(double t) {
c.drawColor(const Color(0xff000000), BlendMode.srcOver);
final s = s2q(_dimension);
c.translate(s.width / 2, s.height / 2);
c.scale(2 + sin(t * 4 * pi / _period));
for (var i = 0; i < _n; i++) {
_drawStep(i, t);
}
}

void _drawStep(int i, double t) {
const di = sqrt2 * _dimension / 1.5;
const dr = di / _n;
const tsr = _period / (_revolutions * _n);
final ts = ((t - tsr * i) % (_period / _revolutions)) / tsr * dr;
final ta = t * 2 * pi / _period;
final so = Offset(i * 20, i * 42);
_drawCircle(ta, di - ts, so);
}

void _drawCircle(double ta, double r, Offset so) {
const to = 0.7;
const precision = 2 * pi / _precision;
final tx = sin(ta) * _wobbliness, ty = cos(ta) * _wobbliness;

final path = Path();
for (var a = 0.0; a < 2 * pi; a += precision) {
final dx = sin(a), dy = cos(a);
final nr = r +
_noise.noise4XYBeforeZW(dx + so.dx, dy + so.dy, tx, ty) *
_disturbance *
r /
sqrt2 /
_dimension;
final x = dx * nr, y = dy * nr;
if (a == 0) {
path.moveTo(x, y);
} else {
path.lineTo(x, y);
}
}
final o = (to * r / _dimension * sqrt2 * 8).clamp(0.0, to);
c.drawPath(
path..close(),
Paint()
..color = const Color(0xffffffff).withOpacity(o)
..strokeWidth = 4.2
..style = PaintingStyle.stroke,
);
}
}