Skip to content

Commit

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

class RightAnimation 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 the scroll offset to move from left to right
int scrollOffset = animationIndex % (newWidth + badgeWidth);

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

// If sourceCol is within bounds of the new grid, display it, else blank space
if (sourceCol >= 0 && sourceCol < newWidth) {
grid[i][j] =
validMarquee || flashLEDOn && newGrid[i % newHeight][sourceCol] == 1;
} else {
validMarquee ? grid[i][j] = true : grid[i][j] = false;
}
}
}
21 changes: 11 additions & 10 deletions lib/badge_animation/anim_left.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ class LeftAnimation extends BadgeAnimation {
// 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;
}
// 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] =
validMarquee || flashLEDOn && newGrid[i % newHeight][sourceCol] == 1;
} else {
validMarquee ? grid[i][j] = true : grid[i][j] = false;
}
}
}
5 changes: 3 additions & 2 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/ani_right.dart';
import 'package:badgemagic/badge_animation/anim_left.dart';
import 'package:badgemagic/badge_animation/animation_abstract.dart';
import 'package:badgemagic/constants.dart';
Expand Down Expand Up @@ -62,7 +63,7 @@ class DrawBadgeProvider extends ChangeNotifier {

//function to calculate duration for the animation
void calculateDuration() {
int newSpeed = aniSpeedStrategy(cardData.getOuterValue()-1);
int newSpeed = aniSpeedStrategy(cardData.getOuterValue() - 1);
if (newSpeed != animationSpeed) {
animationSpeed = newSpeed;
timer?.cancel();
Expand Down Expand Up @@ -119,7 +120,7 @@ class DrawBadgeProvider extends ChangeNotifier {
currentAnimation = LeftAnimation();
break;
case 1:
// currentAnimation = RightAnimation();
currentAnimation = RightAnimation();
break;
case 2:
// currentAnimation = UpAnimation();
Expand Down

0 comments on commit ac4f9a6

Please sign in to comment.