Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66045734
Ac4.dart
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jun 7, 22:16
Size
15 KB
Mime Type
text/x-c++
Expires
Sun, Jun 9, 22:16 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18164154
Attached To
R10646 Orchestration
Ac4.dart
View Options
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:student/widgets/onlineRobotMap.Dart';
import 'dart:async';
import 'dart:convert';
import 'package:student/Database.dart';
import 'package:student/model/Group.dart';
import 'package:student/model/Cellulo.dart';
import 'package:student/widgets/showAlertDialog.Dart';
import 'package:student/widgets/membersBar.Dart';
import 'package:student/widgets/inactivityDetector.Dart';
import 'package:flutter_appavailability/flutter_appavailability.dart';
import 'package:student/widgets/bezierCurvePainter.dart';
import 'package:bezier/bezier.dart';
import 'package:student/widgets/mapShapeMaker.dart';
import 'package:bezier/bezier.dart';
import "dart:math";
import "package:vector_math/vector_math.dart" as vector;
class Ac4 extends StatefulWidget {
Ac4({Key key}) : super(key: key);
@override
_Ac4State createState() => _Ac4State();
}
class _Ac4State extends State<Ac4> {
// Activity_Independent
int currentTurn = 1;
var elapseTimer = new Stopwatch();
AnimationController controllerRobotPath;
Animation<double> animationRobotPath;
Timer timerCelluloPosition;
// Celulo
var celluloxPosition = [0.0, 0.0];
var celluloyPosition = [0.0, 0.0];
var xHaptic;
var yHaptic;
// Learning
List<int> mistakesSlope = [0, 0, 0];
List<int> mistakesIntrepet = [0, 0, 0];
List<int> mistakesInitialPosition = [0, 0, 0];
int tapCounter = 0;
List<int> progress = [0, -2, -2];
List<int> progressElpasedTime = [0, 0, 0];
//Activity Dependent
final double mapSizeWidth = 860;
final double mapSizeHeight = 860;
static List<Offset> pointPosition = [
Offset(80, 80),
Offset(760, 80),
Offset(80, 760),
Offset(760, 760)
];
var midddlePoint1 = [Offset(291.1, 176.2), Offset(110.2, 232.8)];
var midddlePoint2 = [Offset(410.2, 532.8), Offset(0, 0)];
var mapShape = [
{
'numCircles': 0,
'originCircles': [Offset(0, 0)],
'radiuosCircles': [0.0],
'numRectangles': 0,
'originRectangles': [
Offset(300, 30),
Offset(100, 560),
Offset(600, 630),
Offset(780, 360),
Offset(300, 300),
Offset(500, 260),
Offset(300, 560)
],
'widthRectangles': [150.0, 100.0, 50.0, 80.0, 150.0, 100.0, 100.0],
'heightRectangles': [70.0, 100.0, 200.0, 300.0, 40.0, 300.0, 200.0],
'numPolygons': 0,
'sidesofPolygon': [0],
'radiusPolygon': [0.0],
'centerPolygon': [Offset(0, 0)],
'startCenter': pointPosition[2],
'endCenter': pointPosition[1]
},
{
'numCircles': 0,
'originCircles': [Offset(0, 0)],
'radiuosCircles': [0.0],
'numRectangles': 0,
'originRectangles': [
Offset(690, 430),
Offset(500, 560),
Offset(430, 130),
Offset(300, 760),
Offset(100, 230),
Offset(100, 460)
],
'widthRectangles': [150.0, 100.0, 200.0, 100.0, 210.0, 210.0],
'heightRectangles': [150.0, 250.0, 50.0, 250.0, 50.0, 300.0],
'numPolygons': 0,
'sidesofPolygon': [3, 3, 5, 4, 4],
'radiusPolygon': [30.0, 40.0, 40.0, 40.0, 50.0],
'centerPolygon': [
Offset(40, 130),
Offset(700, 90),
Offset(600, 200),
Offset(600, 500),
Offset(780, 400)
],
'startCenter': pointPosition[0],
'endCenter': pointPosition[3]
},
{
'numCircles': 0,
'originCircles': [Offset(0, 0)],
'radiuosCircles': [0.0],
'numRectangles': 0,
'originRectangles': [
Offset(300, 130),
Offset(500, 460),
Offset(750, 530),
Offset(600, 130),
Offset(600, 730),
Offset(100, 530),
Offset(350, 460)
],
'widthRectangles': [160.0, 90.0, 150.0, 100.0, 150.0, 300.0, 50.0],
'heightRectangles': [130.0, 270.0, 150.0, 250.0, 100.0, 70.0, 250.0],
'numPolygons': 0,
'sidesofPolygon': [0],
'radiusPolygon': [0.0],
'centerPolygon': [Offset(0, 0)],
'startCenter': pointPosition[2],
'endCenter': pointPosition[1]
},
];
void onDataSend() {
dbRef.child('attempts').push().set(json.encode({
"numAttempts": tapCounter,
"groupID": group.id,
"acID": "Ac4",
"elpasedTime": elapseTimer.elapsedMilliseconds -
progressElpasedTime[currentTurn - 1],
"progress": {
"turn1": progress[0],
"turn2": progress[1],
"turn3": progress[2]
},
"progressElpasedTime": {
"turn1": progressElpasedTime[0],
"turn2": progressElpasedTime[1],
"turn3": progressElpasedTime[2],
},
"currentTurn": currentTurn,
// "inactivity": inactivity,
"mistakes": {
"turn1": {
"slope": mistakesSlope[0],
"initialPoint": mistakesInitialPosition[0]
},
"turn2": {
"slope": mistakesSlope[1],
"initialPoint": mistakesInitialPosition[1]
},
"turn3": {
"slope": mistakesSlope[2],
"initialPoint": mistakesInitialPosition[2]
},
}
}));
}
void calcHaptic() {
Offset beginpath = mapShape[currentTurn - 1]['startCenter'];
Offset endpath = mapShape[currentTurn - 1]['endCenter'];
final curve = new CubicBezier([
new vector.Vector2(beginpath.dx, beginpath.dy),
new vector.Vector2(
midddlePoint1[currentTurn - 1].dx, midddlePoint1[currentTurn - 1].dy),
new vector.Vector2(
midddlePoint2[currentTurn - 1].dx, midddlePoint2[currentTurn - 1].dy),
new vector.Vector2(endpath.dx, endpath.dy)
]);
var tHaptic = curve.nearestTValue(new vector.Vector2(
(celluloxPosition[0] + celluloyPosition[0]) / 2,
(celluloxPosition[1] + celluloyPosition[1]) / 2));
var xyHaptic = curve.pointAt(tHaptic);
print('thaptic' + tHaptic.toString());
print('xyhaptic' + xyHaptic.toString());
cellulox.setGoalPosition(2 * xyHaptic[0].toDouble() - celluloyPosition[0],
celluloxPosition[1], 150);
celluloy.setGoalPosition(celluloyPosition[0],
2 * xyHaptic[1].toDouble() - celluloxPosition[1], 150);
/*
var slopeHaptic = -1 / linesSlope[currentTurn - 1];
var initialHaptic = (originCoordinates[1] - celluloyPosition[1]) / 100 -
slopeHaptic * (celluloxPosition[0] - originCoordinates[0]) / 100;
// print('initialhaptic' + initialHaptic.toString());
setState(() {
xHaptic = (initialHaptic - initialPoint[currentTurn - 1]) /
(linesSlope[currentTurn - 1] - slopeHaptic);
yHaptic = ((linesSlope[currentTurn - 1]) * xHaptic +
initialPoint[currentTurn - 1]);
});
// print('xcelluloy' + xcelluloy.toDouble().toString());
// print('yhaptic' + yHaptic.toString());
// print('xhaptic' + xHaptic.toString());
cellulox.setGoalPosition(
xHaptic * 100 + originCoordinates[0], xcelluloy.toDouble(), 150);
celluloy.setGoalPosition(
ycellulox.toDouble(), originCoordinates[1] - (100 * yHaptic), 150);
*/
}
@override
void initState() {
super.initState();
cellulox.setColor(0, 255, 0, 0, 0);
celluloy.setColor(0, 0, 255, 0, 0);
dbRef.child('groups').child(group.id).child('tabletStatus').set("YES");
dbRef.child('groups').child(group.id).child('currentActivity').set("Ac4");
timerCelluloPosition =
new Timer.periodic(new Duration(milliseconds: 500), (time) {
if (totalRobots() > 1) {
cellulox.getrobotx().then((val) => setState(() {
if (val != null) {
celluloxPosition[0] = val;
print('dddd' + celluloxPosition[0].toString());
// if (addtoprint == true) celluloxPositiontopaint.add(val);
}
// print(addtoprint.toString());
}));
cellulox.getroboty().then((val) => setState(() {
if (val != null) {
celluloxPosition[1] = val;
}
}));
celluloy.getrobotx().then((val) => setState(() {
if (val != null) {
celluloyPosition[0] = val;
}
}));
celluloy.getroboty().then((val) => setState(() {
if (val != null) {
celluloyPosition[1] = val;
// if (addtoprint == true) celluloyPositiontopaint.add(val);
}
}));
if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) {
cellulox.setVelocity(0, 0);
celluloy.setVelocity(0, 0);
}
}
//if (runHaptic == true) {
calcHaptic();
});
elapseTimer.start();
onDataSend();
}
@override
void dispose() {
elapseTimer.stop();
timerCelluloPosition.cancel(); //
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Follow the Line'),
),
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Column(children: <Widget>[
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
Container(
height: 100,
width: 600,
child: Stack(children: <Widget>[
Card(
child: ListTile(
title: Text('Try to follow the curve. '),
),
),
])),
SizedBox(
width: 15,
),
SizedBox(width: 20),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(100)),
color: Colors.blue),
child: FlatButton(
child: Text(
"Next Turn",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 18),
),
onPressed: () => {
tapCounter = 0,
if (currentTurn <= 2)
{
setState(() {
currentTurn = currentTurn + 1;
}),
progress[currentTurn - 2] = 1,
// controller.reset(),
progress[currentTurn - 1] = 0,
onDataSend(),
}
else
{
progress[2] = 1,
onDataSend(),
showAlertDialog(
context, 'Wait for teacher', 'Game has finished! '),
},
},
),
)
]),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.65,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(100)),
// color: Colors.blue
),
child: Stack(
children: <Widget>[
CustomPaint(
//size: Size(200, 200),
painter:
//LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint),
MapShapeMaker(
MediaQuery.of(context).size.width *
0.9 /
mapSizeWidth,
MediaQuery.of(context).size.height *
0.65 /
mapSizeHeight,
mapShape[currentTurn - 1]['numRectangles'],
mapShape[currentTurn - 1]['originRectangles'],
mapShape[currentTurn - 1]['widthRectangles'],
mapShape[currentTurn - 1]['heightRectangles'],
mapShape[currentTurn - 1]['numCircles'],
mapShape[currentTurn - 1]['originCircles'],
mapShape[currentTurn - 1]['radiuosCircles'],
mapShape[currentTurn - 1]['numPolygons'],
mapShape[currentTurn - 1]['sidesofPolygon'],
mapShape[currentTurn - 1]['radiusPolygon'],
mapShape[currentTurn - 1]['centerPolygon'],
mapShape[currentTurn - 1]['startCenter'],
mapShape[currentTurn - 1]['endCenter']),
),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.65,
child: Align(
alignment: Alignment(
2 *
((celluloxPosition[0] + celluloyPosition[0]) /
2 /
mapSizeWidth) -
1,
2 *
((celluloxPosition[1] + celluloyPosition[1]) /
2 /
mapSizeHeight) -
1),
child: Card(
child: SvgPicture.asset(
"assets/images/celluloPurple.svg",
height: 60,
width: 60),
),
),
),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.65,
child: Align(
alignment: Alignment(
2 * ((celluloxPosition[0]) / mapSizeWidth) - 1,
2 * ((celluloxPosition[1]) / mapSizeHeight) - 1),
child: Card(
child: SvgPicture.asset("assets/images/celluloRed.svg",
height: 60, width: 60),
),
),
),
Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.65,
child: Align(
alignment: Alignment(
2 * ((celluloyPosition[0]) / mapSizeWidth) - 1,
2 * ((celluloyPosition[1]) / mapSizeHeight) - 1),
child: Card(
child: SvgPicture.asset("assets/images/celluloBlue.svg",
height: 60, width: 60),
),
),
),
CustomPaint(
//size: Size(200, 200),
painter: BezierCurvePainter(
mapShape[currentTurn - 1]['startCenter'],
mapShape[currentTurn - 1]['endCenter'],
MediaQuery.of(context).size.width *
0.9 /
mapSizeWidth,
MediaQuery.of(context).size.height *
0.65 /
mapSizeHeight,
currentTurn)
//LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint),
),
],
)),
SizedBox(
height: 15,
),
MembersBar(),
])));
}
}
Event Timeline
Log In to Comment