Skip to content

Commit

Permalink
feat: Added the left animation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhalakupadhyay committed Sep 9, 2024
1 parent 4be7e17 commit 297dba7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
32 changes: 32 additions & 0 deletions lib/badge_animation/anim_left.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:badgemagic/badge_animation/animation_abstract.dart';

class LeftAnimation extends BadgeAnimation {
@override
void animation(
List<List<bool>> grid,
List<List<int>> newGrid,
int animationIndex,
bool validMarquee,
bool flashLEDOn,
int currentcountFrame,
int i,
int j,
int newHeight,
int newWidth,
int badgeHeight,
int badgeWidth) {
// Calculate how much of the new grid is currently visible in the grid
int scrollOffset = animationIndex % (newWidth + badgeWidth);

// Get the corresponding column in the new grid based on the scroll position
int sourceCol = j + scrollOffset - badgeWidth;

// If sourceCol is negative, display blank space (off-screen part of the grid)
if (sourceCol >= 0 && sourceCol < newWidth) {
// Ensure flashLEDOn and validMarquee effects are applied
grid[i][j] = flashLEDOn && newGrid[i % newHeight][sourceCol] == 1;
} else {
grid[i][j] = false;
}
}
}
9 changes: 5 additions & 4 deletions lib/providers/badgeview_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:badgemagic/bademagic_module/utils/byte_array_utils.dart';
import 'package:badgemagic/badge_animation/anim_left.dart';
import 'package:badgemagic/badge_animation/animation_abstract.dart';
import 'package:badgemagic/constants.dart';
import 'package:badgemagic/providers/cardsprovider.dart';
Expand Down Expand Up @@ -61,7 +62,7 @@ class DrawBadgeProvider extends ChangeNotifier {

//function to calculate duration for the animation
void calculateDuration() {
int newSpeed = aniSpeedStrategy(cardData.getOuterValue());
int newSpeed = aniSpeedStrategy(cardData.getOuterValue()-1);
if (newSpeed != animationSpeed) {
animationSpeed = newSpeed;
timer?.cancel();
Expand All @@ -87,7 +88,7 @@ class DrawBadgeProvider extends ChangeNotifier {
void initializeAnimation(TickerProvider vsync) {
_controller = AnimationController(
vsync: vsync,
duration: const Duration(seconds: 1000),
duration: const Duration(days: 1000),
)..addListener(() {
setAnimationMode();
changeGridValue(newGrid);
Expand Down Expand Up @@ -115,7 +116,7 @@ class DrawBadgeProvider extends ChangeNotifier {
switch (cardData.getAnimationIndex()) {
//add cases from 0 to 8
case 0:
currentAnimation = null;
currentAnimation = LeftAnimation();
break;
case 1:
// currentAnimation = RightAnimation();
Expand All @@ -142,7 +143,7 @@ class DrawBadgeProvider extends ChangeNotifier {
currentAnimation = null;
break;
default:
currentAnimation = null;
currentAnimation = LeftAnimation();
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/virtualbadge/view/badge_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class BadgePainter extends CustomPainter {
for (int row = 0; row < grid.length; row++) {
for (int col = 0; col < grid[row].length; col++) {
final Paint paint = Paint()
..color = grid[row][col] ? Colors.red : Colors.grey.shade600
..color = grid[row][col]
? const Color.fromARGB(255, 255, 0, 0)
: Colors.grey.shade900
..style = PaintingStyle.fill;

final Path path = Path()
Expand Down

0 comments on commit 297dba7

Please sign in to comment.