Skip to content

Commit bee92e0

Browse files
committed
Just before adding vinyl
1 parent 104b7c9 commit bee92e0

File tree

2 files changed

+171
-28
lines changed

2 files changed

+171
-28
lines changed

lib/vinyl/exmaples/spring_playground.dart

Lines changed: 154 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'dart:math' as math;
3+
import 'dart:math';
34

45
class SpringAnimationsDemo extends StatelessWidget {
56
@override
@@ -12,30 +13,37 @@ class SpringAnimationsDemo extends StatelessWidget {
1213
child: Column(
1314
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
1415
children: [
16+
// SpringButton(
17+
// onPressed: () => _showAnimation(context, 'Springy'),
18+
// curve: SpringyCurve(),
19+
// child: Text('Springy', style: TextStyle(fontSize: 18)),
20+
// ),
21+
// SpringButton(
22+
// onPressed: () => _showAnimation(context, 'Shock Absorber'),
23+
// curve: ShockAbsorberCurve(),
24+
// child: Text('Shock Absorber', style: TextStyle(fontSize: 18)),
25+
// ),
26+
// SpringButton(
27+
// onPressed: () => _showAnimation(context, 'Quick Bounce'),
28+
// curve: QuickBounceCurve(),
29+
// child: Text('Quick Bounce', style: TextStyle(fontSize: 18)),
30+
// ),
31+
// SpringButton(
32+
// onPressed: () => _showAnimation(context, 'Snappy Spring'),
33+
// curve: SnappySpringCurve(),
34+
// child: Text('Snappy Spring', style: TextStyle(fontSize: 18)),
35+
// ),
36+
// SpringButton(
37+
// onPressed: () => _showAnimation(context, 'Elastic Snap'),
38+
// curve: ElasticSnapCurve(),
39+
// child: Text('Elastic Snap', style: TextStyle(fontSize: 18)),
40+
// ),
41+
1542
SpringButton(
16-
onPressed: () => _showAnimation(context, 'Springy'),
17-
curve: SpringyCurve(),
18-
child: Text('Springy', style: TextStyle(fontSize: 18)),
19-
),
20-
SpringButton(
21-
onPressed: () => _showAnimation(context, 'Shock Absorber'),
22-
curve: ShockAbsorberCurve(),
23-
child: Text('Shock Absorber', style: TextStyle(fontSize: 18)),
24-
),
25-
SpringButton(
26-
onPressed: () => _showAnimation(context, 'Quick Bounce'),
27-
curve: QuickBounceCurve(),
28-
child: Text('Quick Bounce', style: TextStyle(fontSize: 18)),
29-
),
30-
SpringButton(
31-
onPressed: () => _showAnimation(context, 'Snappy Spring'),
32-
curve: SnappySpringCurve(),
33-
child: Text('Snappy Spring', style: TextStyle(fontSize: 18)),
34-
),
35-
SpringButton(
36-
onPressed: () => _showAnimation(context, 'Elastic Snap'),
37-
curve: ElasticSnapCurve(),
38-
child: Text('Elastic Snap', style: TextStyle(fontSize: 18)),
43+
onPressed: () => _showAnimation(context, 'High Velocity Spring'),
44+
curve: HighVelocitySpringCurve(),
45+
child:
46+
Text('High Velocity Spring', style: TextStyle(fontSize: 18)),
3947
),
4048
],
4149
),
@@ -152,3 +160,126 @@ class ElasticSnapCurve extends Curve {
152160
return t * t * (3 - 2 * t) - math.sin(t * math.pi * 2) * 0.1 * (1 - t);
153161
}
154162
}
163+
164+
//----
165+
166+
// 2. Less springy version
167+
class LessSpringySnappyCurve extends Curve {
168+
@override
169+
double transform(double t) {
170+
return t * t * (3 - 2 * t) + sin(t * pi * 2) * 0.05 * (1 - t);
171+
}
172+
}
173+
174+
// 3. Heavier mass simulation
175+
class HeavyMassSnappyCurve extends Curve {
176+
@override
177+
double transform(double t) {
178+
return t * t * (3 - 2 * t) + sin(t * pi * 1.5) * 0.08 * (1 - t * t);
179+
}
180+
}
181+
182+
// 4. Quick start, slow end
183+
class QuickStartSlowEndCurve extends Curve {
184+
@override
185+
double transform(double t) {
186+
return t * t * (3 - 2 * t) + sin(t * pi) * 0.1 * (1 - pow(t, 3));
187+
}
188+
}
189+
190+
// 5. Damped oscillation
191+
class DampedOscillationCurve extends Curve {
192+
@override
193+
double transform(double t) {
194+
return t - sin(t * pi * 2) * 0.1 * exp(-2 * t);
195+
}
196+
}
197+
198+
// 6. Soft bounce
199+
class SoftBounceCurve extends Curve {
200+
@override
201+
double transform(double t) {
202+
return t * t * (3 - 2 * t) - sin(t * pi) * 0.05 * (1 - t);
203+
}
204+
}
205+
206+
// 7. Delayed snap
207+
class DelayedSnapCurve extends Curve {
208+
@override
209+
double transform(double t) {
210+
return t < 0.5
211+
? 2 * t * t
212+
: 1 - pow(-2 * t + 2, 2) / 2 + sin(t * pi) * 0.05;
213+
}
214+
}
215+
216+
// 8. Gradual acceleration
217+
class GradualAccelerationCurve extends Curve {
218+
@override
219+
double transform(double t) {
220+
return t * t * t + sin(t * pi * 2) * 0.03 * (1 - t);
221+
}
222+
}
223+
224+
// 9. Elastic-like with less oscillation
225+
class MildElasticCurve extends Curve {
226+
@override
227+
double transform(double t) {
228+
return pow(2, -8 * t) * sin((t - 0.1) * pi * 2) * 0.5 + 1;
229+
}
230+
}
231+
232+
// 10. Smooth overshoot
233+
234+
class HeavyMassBaseCurve extends Curve {
235+
@override
236+
double transform(double t) {
237+
return t * t * (3 - 2 * t) + sin(t * pi * 2) * 0.1 * (1 - t);
238+
}
239+
}
240+
241+
// Slow Start Heavy Mass
242+
class SlowStartHeavyMassCurve extends Curve {
243+
@override
244+
double transform(double t) {
245+
return pow(t, 3) + sin(t * pi) * 0.1 * (1 - t);
246+
}
247+
}
248+
249+
// Overshoot Heavy Mass
250+
class OvershootHeavyMassCurve extends Curve {
251+
@override
252+
double transform(double t) {
253+
return t < 0.6
254+
? 1.3 * t
255+
: 1 + sin((t - 0.6) * pi * 2.5) * 0.15 * pow(1 - t, 2);
256+
}
257+
}
258+
259+
// Bouncy Heavy Mass
260+
class BouncyHeavyMassCurve extends Curve {
261+
@override
262+
double transform(double t) {
263+
return t < 0.5
264+
? 4 * t * t * t
265+
: 1 - pow(-2 * t + 2, 3) / 2 + sin(t * pi * 3) * 0.1 * (1 - t);
266+
}
267+
}
268+
269+
class HighVelocitySpringCurve extends Curve {
270+
final double a;
271+
final double w;
272+
273+
HighVelocitySpringCurve({this.a = 0.3, this.w = 20});
274+
275+
@override
276+
double transform(double t) {
277+
// Rapid initial movement
278+
double initialMovement = (1 - pow(1 - t, 3)).toDouble();
279+
280+
// Small spring back effect
281+
double springBack = sin(t * w) * a * pow(1 - t, 2);
282+
283+
return initialMovement - springBack;
284+
}
285+
}

lib/vinyl/vinyl.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class VinylHomeWidget extends StatelessWidget {
2727

2828
// body: SpringAnimationsPage(),
2929
body: TransformApp(),
30-
// body: SpringAnimationsDemo()
30+
// body: SpringAnimationsDemo(),
3131
);
3232
}
3333
}
@@ -67,11 +67,22 @@ class _TransformAppState extends State<TransformApp>
6767
super.dispose();
6868
}
6969

70+
double _rotateX = 0;
71+
double _rotateY = 0;
72+
73+
void _onPanUpdate(DragUpdateDetails details) {
74+
setState(() {
75+
_rotateY += details.delta.dx / 100;
76+
_rotateX -= details.delta.dy / 100;
77+
});
78+
}
79+
7080
@override
7181
Widget build(BuildContext context) {
7282
final double baseRotationX = 355 * pi / 180;
7383
return Scaffold(
7484
body: GestureDetector(
85+
onPanUpdate: _onPanUpdate,
7586
onTap: () => _changeStackOrder(),
7687
child: Expanded(
7788
child: Stack(
@@ -95,7 +106,8 @@ class _TransformAppState extends State<TransformApp>
95106
sin(_headBowForwardAnimation.value * pi) *
96107
5 *
97108
pi /
98-
180) // vertical
109+
180 +
110+
_rotateX) // vertical
99111
..rotateZ(6 * pi / 180) //z : 32
100112
..scale(1.0),
101113
alignment: Alignment.center,
@@ -286,17 +298,17 @@ class _TransformAppState extends State<TransformApp>
286298
TweenSequenceItem(
287299
tween: Tween<double>(begin: 0.0, end: -100)
288300
.chain(CurveTween(curve: SnappySpringCurve())),
289-
weight: 30.0,
301+
weight: 40.0,
290302
),
291303
TweenSequenceItem(
292304
tween: Tween<double>(begin: -100, end: -100)
293305
.chain(CurveTween(curve: Curves.linear)),
294-
weight: 40.0,
306+
weight: 30.0,
295307
),
296308
TweenSequenceItem(
297309
tween: Tween<double>(begin: -100, end: 0.0)
298310
.chain(CurveTween(curve: SnappySpringCurve())),
299-
weight: 30.0,
311+
weight: 40.0,
300312
),
301313
]).animate(animController);
302314

0 commit comments

Comments
 (0)