-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added the Fixed animation code #1002
Closed
Jhalakupadhyay
wants to merge
6
commits into
fossasia:flutter_app
from
Jhalakupadhyay:feature/ani_fixed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bcdb92c
feat: Added the logic to display the clipart and text on the virtual …
Jhalakupadhyay 85da751
feat:Added the base structure for the animations with speed controll.
Jhalakupadhyay 4be7e17
chore: update flutter version to 3.24.2 from 3.22.2.
Jhalakupadhyay 297dba7
feat: Added the left animation.
Jhalakupadhyay ac4f9a6
feat: Updated the code and created the right animation.
Jhalakupadhyay 35e69e8
Added the fixed animation.
Jhalakupadhyay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:badgemagic/badge_animation/animation_abstract.dart'; | ||
|
||
class FixedAnimation 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) { | ||
if (newWidth <= badgeWidth + 4) { | ||
grid[i][j] = validMarquee || | ||
i >= 0 && | ||
i < newHeight && | ||
j >= 0 && | ||
j < newWidth && | ||
(flashLEDOn && newGrid[i][j] == 1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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] = | ||
validMarquee || flashLEDOn && newGrid[i % newHeight][sourceCol] == 1; | ||
} else { | ||
validMarquee ? grid[i][j] = true : grid[i][j] = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
abstract class BadgeAnimation { | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,15 @@ const String aniRight = 'assets/animations/ic_anim_right.gif'; | |
const String effFlash = 'assets/effects/ic_effect_flash.gif'; | ||
const String effInvert = 'assets/effects/ic_effect_invert.gif'; | ||
const String effMarque = 'assets/effects/ic_effect_marquee.gif'; | ||
|
||
//constants for the animation speed | ||
const Duration aniBaseSpeed = Duration(microseconds: 200000); // in uS | ||
const Duration aniMarqueSpeed = Duration(microseconds: 100000); // in uS | ||
const Duration aniFlashSpeed = Duration(microseconds: 500000); // in uS | ||
|
||
// Function to calculate animation speed based on speed level | ||
int aniSpeedStrategy(int speedLevel) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider using an enum for speed levels Using an enum for speed levels instead of raw integers would make the code more type-safe and self-documenting. This can help prevent errors and improve code readability.
|
||
int speedInMicroseconds = aniBaseSpeed.inMicroseconds - | ||
(speedLevel * aniBaseSpeed.inMicroseconds ~/ 8); | ||
return speedInMicroseconds; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider making the output array size dynamic
The function uses a fixed size of 11 for the outer list. This might cause issues if the input doesn't align with this expectation. Consider making the size dynamic based on the input or adding input validation.