-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* BREAKING CHANGE: MArrayElement & MArray & MVariable play animations by themselves + MArrayPointer added (#5) * perf: MArrayElement automatically plays animations on update calls * perf: MArray can now play animations + refactored functions to improve readability * perf: MVaraible can now play animations * fix: deepcopy implemented for MArrayElement & MArray + MArray label for even elements resolved * docs: updated docs according to recent changes * feat: MArrayPointer added * fix: MArrayPointer spawn & shift error resolved * docs: added docs for MArrayPointer & Example Gallery * docs: updated changelog for release 0.1.6
- Loading branch information
Showing
9 changed files
with
1,147 additions
and
160 deletions.
There are no files selected for viewing
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,45 @@ | ||
Example Gallery | ||
=============== | ||
|
||
.. currentmodule:: manim_data_structures.m_array | ||
|
||
Find Pair Sum In Sorted MArray | ||
------------------------------ | ||
|
||
The code snippet below uses the famous two pointer technique to find the pair sum ``17`` in the sorted array ``[2, 3, 5, 8, 9, 10, 11]``. | ||
|
||
.. manim:: MainScene | ||
:quality: low | ||
|
||
from manim_data_structures import * | ||
|
||
class MainScene(Scene): | ||
def isPairSumAnim(self, arr, n, val): | ||
p_i = MArrayPointer(self, arr, 0, 'i', mob_arrow_args={'color': GREEN}, mob_label_args={'color': GREEN}) | ||
p_j = MArrayPointer(self, arr, n - 1, 'j', mob_arrow_args={'color': YELLOW}, mob_label_args={'color': YELLOW}) | ||
pair_sum = MVariable(self, 0, label='Sum') | ||
pair_sum.shift(DOWN * 2) | ||
|
||
self.play(Create(pair_sum)) | ||
self.play(Create(p_i), Create(p_j)) | ||
|
||
while (p_i.fetch_index() < p_j.fetch_index()): | ||
pair_sum.update_value(arr.fetch_arr()[p_i.fetch_index()] + arr.fetch_arr()[p_j.fetch_index()]) | ||
|
||
if (pair_sum.fetch_value() == val): | ||
pair_sum.fetch_mob_square().set(fill_color=GREEN) | ||
return True | ||
elif(pair_sum.fetch_value() < val): | ||
p_i.shift_to_elem(p_i.fetch_index() + 1) | ||
else: | ||
p_j.shift_to_elem(p_j.fetch_index() - 1) | ||
|
||
pair_sum.fetch_mob_square().set(fill_color=RED) | ||
return False | ||
|
||
def construct(self): | ||
arr = MArray(self, [2, 3, 5, 8, 9, 10, 11], label='Array') | ||
arr.shift(UP + LEFT * 2) | ||
self.add(arr) | ||
self.isPairSumAnim(arr, 7, 17) | ||
self.wait(1) |
Oops, something went wrong.