Skip to content

Commit d60e057

Browse files
feat: completed the dynamic fractal flow
1 parent 09766ec commit d60e057

File tree

1 file changed

+140
-136
lines changed

1 file changed

+140
-136
lines changed

lib/src/features/greatwall/presentation/pages/dynamic_fractal_derivation_level_page.dart

Lines changed: 140 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
55
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
66
import 'package:go_router/go_router.dart';
77

8-
98
import '../../../../common/settings/presentation/pages/settings_page.dart';
109
import '../blocs/blocs.dart';
1110
import 'derivation_result_page.dart';
@@ -23,7 +22,7 @@ class DynamicFractalDerivationLevelPage extends StatefulWidget {
2322

2423
class _DynamicFractalDerivationLevelPageState
2524
extends State<DynamicFractalDerivationLevelPage> {
26-
final Offset exponent = const Offset(2.0, 0.0);
25+
Offset exponent = const Offset(2.0, 0.0);
2726
FragmentShader? _shader; // Nullable until initialized
2827
double _zoom = 2.00000000;
2928
Offset _offset = const Offset(0.00000000, 0.00000000);
@@ -56,146 +55,151 @@ class _DynamicFractalDerivationLevelPageState
5655
@override
5756
Widget build(BuildContext context) {
5857
return Scaffold(
59-
appBar: AppBar(
60-
title: Text(AppLocalizations.of(context)!.derivationLevelPageTitle),
61-
leading: IconButton(
62-
icon: const Icon(Icons.arrow_back),
58+
appBar: AppBar(
59+
title: Text(AppLocalizations.of(context)!.derivationLevelPageTitle),
60+
leading: IconButton(
61+
icon: const Icon(Icons.arrow_back),
62+
onPressed: () {
63+
context.read<GreatWallBloc>().add(GreatWallReset());
64+
Navigator.of(context).pop();
65+
},
66+
),
67+
actions: [
68+
IconButton(
69+
icon: const Icon(Icons.settings),
6370
onPressed: () {
64-
context.read<GreatWallBloc>().add(GreatWallReset());
65-
Navigator.of(context).pop();
71+
context.go('/${SettingsPage.routeName}');
6672
},
6773
),
68-
actions: [
69-
IconButton(
70-
icon: const Icon(Icons.settings),
71-
onPressed: () {
72-
context.go('/${SettingsPage.routeName}');
73-
},
74-
),
75-
],
76-
),
77-
body: Center(
78-
child: BlocBuilder<GreatWallBloc, GreatWallState>(
79-
builder: (context, state) {
80-
if (state is GreatWallDeriveInProgress) {
81-
return const Center(
82-
child: CircularProgressIndicator(),
83-
);
84-
} else if (state is GreatWallDeriveStepSuccess) {
85-
return _shader == null
86-
? const Center(
87-
child: CircularProgressIndicator()) // Show a loading indicator
88-
: Listener(
89-
onPointerSignal: (PointerSignalEvent event) {
90-
// this just changes the zoom, do not change offset here
91-
if (event is PointerScrollEvent) {
92-
setState(() {
93-
// Adjust zoom level based on scroll delta
94-
var zoomFactor = event.scrollDelta.dy > 0 ? 1.1 : 0.9;
95-
96-
var zoomDelta = zoomFactor *
97-
zoomFactor *
98-
(event.scrollDelta.dy > 0 ? 1 : -1);
99-
_zoom *= zoomFactor;
100-
print("position ${event.position}");
101-
102-
print(_zoom);
103-
});
104-
}
105-
},
106-
child: GestureDetector(
107-
onTapDown: (details) {
108-
setState(() {
109-
var aspectRatio = MediaQuery.of(context).size.width /
110-
MediaQuery.of(context).size.height;
111-
var mouseX = details.localPosition.dx /
112-
MediaQuery.of(context).size.width;
113-
var mouseY = details.localPosition.dy /
114-
MediaQuery.of(context).size.height;
115-
var posX = mouseX * _zoom * aspectRatio +
116-
_offset.dx +
117-
0.5 * _gridSize;
118-
var posY = mouseY * _zoom + _offset.dy + 0.5 * _gridSize;
119-
posX = double.parse(posX.toStringAsFixed(5)) -
120-
0.5 * _gridSize;
121-
posY = double.parse(posY.toStringAsFixed(5)) -
122-
0.5 * _gridSize;
123-
posX = double.parse(posX.toStringAsFixed(6));
124-
posY = double.parse(posY.toStringAsFixed(6));
125-
print(details.localPosition);
126-
_selectedPosition = Offset(posX, posY);
127-
print('${_selectedPosition.dx}, ${_selectedPosition.dy}');
128-
});
129-
},
130-
onScaleUpdate: (details) {
131-
setState(() {
132-
// this changes the zoom and offset
133-
134-
if (details.scale != 1.0) {
135-
var zoomFactor = details.scale < 1.0 ? 1.01 : 0.99;
136-
//
137-
_zoom *= zoomFactor * details.scale;
138-
print("scale ${details.scale.clamp(0.9999, 1.0001)}");
139-
print("zoom $_zoom");
74+
],
75+
),
76+
body: Center(
77+
child: BlocBuilder<GreatWallBloc, GreatWallState>(
78+
builder: (context, state) {
79+
if (state is GreatWallDeriveInProgress) {
80+
return const Center(
81+
child: CircularProgressIndicator(),
82+
);
83+
} else if (state is GreatWallDeriveStepSuccess) {
84+
exponent = Offset((state.knowledgePalettes[0].knowledge).x, (state.knowledgePalettes[0].knowledge).y);
85+
return _shader == null
86+
? const Center(
87+
child:
88+
CircularProgressIndicator()) // Show a loading indicator
89+
: Listener(
90+
onPointerSignal: (PointerSignalEvent event) {
91+
// this just changes the zoom, do not change offset here
92+
if (event is PointerScrollEvent) {
93+
setState(() {
94+
// Adjust zoom level based on scroll delta
95+
var zoomFactor = event.scrollDelta.dy > 0 ? 1.1 : 0.9;
96+
97+
var zoomDelta = zoomFactor *
98+
zoomFactor *
99+
(event.scrollDelta.dy > 0 ? 1 : -1);
100+
_zoom *= zoomFactor;
101+
print("position ${event.position}");
102+
103+
print(_zoom);
104+
});
140105
}
141-
// handle pan
142-
143-
_offset =
144-
_offset - details.focalPointDelta * _zoom * 0.001;
145-
});
146-
},
147-
child: Scaffold(
148-
body: CustomPaint(
149-
painter: _BurningShipAdvFractalPainter(
150-
shader: _shader!,
151-
zoom: _zoom,
152-
offset: _offset,
153-
maxIterations: _maxIterations,
154-
gridSize: _gridSize,
155-
selectedPosition: _selectedPosition,
156-
exponent: exponent,
157-
),
158-
size: Size.infinite,
159-
),
160-
floatingActionButton: FloatingActionButton(
161-
onPressed: () {
162-
Future.delayed(
163-
const Duration(seconds: 1),
106+
},
107+
child: GestureDetector(
108+
onTapDown: (details) {
109+
setState(() {
110+
var aspectRatio = MediaQuery.of(context).size.width /
111+
MediaQuery.of(context).size.height;
112+
var mouseX = details.localPosition.dx /
113+
MediaQuery.of(context).size.width;
114+
var mouseY = details.localPosition.dy /
115+
MediaQuery.of(context).size.height;
116+
var posX = mouseX * _zoom * aspectRatio +
117+
_offset.dx +
118+
0.5 * _gridSize;
119+
var posY =
120+
mouseY * _zoom + _offset.dy + 0.5 * _gridSize;
121+
posX = double.parse(posX.toStringAsFixed(5)) -
122+
0.5 * _gridSize;
123+
posY = double.parse(posY.toStringAsFixed(5)) -
124+
0.5 * _gridSize;
125+
posX = double.parse(posX.toStringAsFixed(6));
126+
posY = double.parse(posY.toStringAsFixed(6));
127+
print(details.localPosition);
128+
_selectedPosition = Offset(posX, posY);
129+
print(
130+
'${_selectedPosition.dx}, ${_selectedPosition.dy}');
131+
});
132+
},
133+
onScaleUpdate: (details) {
134+
setState(() {
135+
// this changes the zoom and offset
136+
137+
if (details.scale != 1.0) {
138+
var zoomFactor = details.scale < 1.0 ? 1.01 : 0.99;
139+
//
140+
_zoom *= zoomFactor * details.scale;
141+
print(
142+
"scale ${details.scale.clamp(0.9999, 1.0001)}");
143+
print("zoom $_zoom");
144+
}
145+
// handle pan
146+
147+
_offset =
148+
_offset - details.focalPointDelta * _zoom * 0.001;
149+
});
150+
},
151+
child: Scaffold(
152+
body: CustomPaint(
153+
painter: _BurningShipAdvFractalPainter(
154+
shader: _shader!,
155+
zoom: _zoom,
156+
offset: _offset,
157+
maxIterations: _maxIterations,
158+
gridSize: _gridSize,
159+
selectedPosition: _selectedPosition,
160+
exponent: exponent
161+
),
162+
size: Size.infinite,
163+
),
164+
floatingActionButton: FloatingActionButton(
165+
onPressed: () {
166+
Future.delayed(
167+
const Duration(seconds: 1),
164168
() {
165-
if (!context.mounted) return;
166-
if (state.currentLevel < state.treeDepth) {
167-
print("x: ${_selectedPosition.dx}, y: ${_selectedPosition.dy} submitted");
168-
context
169-
.read<GreatWallBloc>()
170-
.add(GreatWallDerivationStepMade("x: ${_selectedPosition.dx}, y: ${_selectedPosition.dy}"));
171-
context.go('/${DynamicFractalDerivationLevelPage.routeName}');
172-
} else {
173-
print("process completed");
174-
context
175-
.read<GreatWallBloc>()
176-
.add(GreatWallDerivationFinished());
177-
context.go(
178-
'/${DerivationResultPage.routeName}',
179-
);
180-
}
169+
if (!context.mounted) return;
170+
print(
171+
"x: ${_selectedPosition.dx}, y: ${_selectedPosition.dy} submitted");
172+
context.read<GreatWallBloc>().add(
173+
GreatWallDerivationStepMade(
174+
"x: ${_selectedPosition.dx}, y: ${_selectedPosition.dy}"));
175+
if (state.currentLevel < state.treeDepth) {
176+
context.go(
177+
'/${DynamicFractalDerivationLevelPage.routeName}');
178+
} else {
179+
print("process completed");
180+
context
181+
.read<GreatWallBloc>()
182+
.add(GreatWallDerivationFinished());
183+
context.go(
184+
'/${DerivationResultPage.routeName}',
185+
);
186+
}
187+
},
188+
);
189+
190+
// widget.onSubmit(_selectedPosition);
181191
},
182-
);
183-
184-
// widget.onSubmit(_selectedPosition);
185-
},
186-
child: const Icon(Icons.check),
187-
),
188-
),
189-
)
190-
);
191-
} else {
192-
return Center(
193-
child: Text(AppLocalizations.of(context)!.noLevel),
194-
);
195-
}
196-
}
197-
),
198-
),
192+
child: const Icon(Icons.check),
193+
),
194+
),
195+
));
196+
} else {
197+
return Center(
198+
child: Text(AppLocalizations.of(context)!.noLevel),
199+
);
200+
}
201+
}),
202+
),
199203
);
200204
}
201205
}

0 commit comments

Comments
 (0)