Skip to content
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

Trying to randomize students creatures in TeacherStudentsScene but it shows same students every time when i render #30

Closed
NavpreetDevpuri opened this issue Apr 25, 2020 · 2 comments

Comments

@NavpreetDevpuri
Copy link

NavpreetDevpuri commented Apr 25, 2020

I created new creatures named

  • PlusCreature
  • MinusCreature
  • MultiCreature
  • DivCreature
  • RemCreature
  • AndCreature
  • EqualCreature
  • RoundBracketsCreature
  • CurlyBracketsCreature
  • SquareBracketsCreature
  • AngleBracketsCreature
  • HashCreature
  • QuestionCreature
    Creatures are looks like
    Ceatures

and added this creatures to the file c_creature (renamed pi_creature) for example this one

class PlusCreature(CCreature):
    CONFIG = {
        "file_name_prefix": "PlusCreatures"
    }

and i changed method 'create_c_creatures()' in class TeacherStudentsScene in file c_creature_scene.py (renamed pi_creature_scene.py)

    def create_c_creatures(self):
        self.teacher = CCreature(color=self.teacher_color)
        self.teacher.to_corner(DOWN + RIGHT)
        self.teacher.look(DOWN + LEFT)
        '''From that
        self.students = VGroup(*[
            Randolph(color=c)
            for c in self.student_colors
        ])
        '''
        # To this
        print("yessssss its runing, we are creating students.")
        self.students = VGroup(*[
            random.choice([PlusCreature,
                          MinusCreature,
                          MultiCreature,
                          DivCreature,
                          RemCreature,
                          AndCreature,
                          EqualCreature,
                          RoundBracketsCreature,
                          CurlyBracketsCreature,
                          SquareBracketsCreature,
                          AngleBracketsCreature,
                          HashCreature,
                          QuestionCreature])(color=c)
            for c in self.student_colors
        ])
        self.students.arrange(RIGHT)
        self.students.scale(self.student_scale_factor)
        self.students.to_corner(DOWN + LEFT)
        self.teacher.look_at(self.students[-1].eyes)
        for student in self.students:
            student.look_at(self.teacher.eyes)
        return [self.teacher] + list(self.students)

i created file manimlib.imports_with_c that imports c_creatures instead of pi_creatures
when i run following code ( i tried self.setup() and self.c_creatures = VGroup(*self.create_c_creatures()) but this lines just create another creatures onto previouse ones)

from manimlib.imports_with_c import *
class ts(TeacherStudentsScene):
    def construct(self):
        #self.setup()
        #self.c_creatures = VGroup(*self.create_c_creatures())
        self.teacher_says( 
            "Something different today!",
            run_time = 2
        )

Output always shows same students with two EqualCreatures and one QuestionCreature even when rendering code again and again but according to changes in method 'create_c_creatures()' in class TeacherStudentsScene in file c_creature_scene.py it should be create random creatures everytimes i run the code

same output is following
output

it always print the output from line print("yessssss its runing, we are creating students.") in create_c_creatures() method that means it runs every time between multiple renders. this mean may be there is something wrong with random.choice() method
but i tried following code.

import random
def a1():
    return "1"
def a2():
    return "2"
def a3():
    return "3"
def a4():
    return "4"
def a5():
    return "5"
numbers = [*[random.choice([a1,a2,a3,a4,a5])() for i in range(0,20)]]
print(numbers)

it allways print random numbers.

but when i put this code inside create_c_creatures() like follow

 print("yessssss its runing, we are creating students.")
        self.students = VGroup(*[
            random.choice([PlusCreature,
                          MinusCreature,
                          MultiCreature,
                          DivCreature,
                          RemCreature,
                          AndCreature,
                          EqualCreature,
                          RoundBracketsCreature,
                          CurlyBracketsCreature,
                          SquareBracketsCreature,
                          AngleBracketsCreature,
                          HashCreature,
                          QuestionCreature])(color=c)
            for c in self.student_colors
        ])
        def a1():
            return "1"
        def a2():
            return "2"
        def a3():
            return "3"
        def a4():
            return "4"
        def a5():
            return "5"
        numbers = [*[random.choice([a1, a2, a3, a4, a5])() for i in range(0, 20)]]
        print(numbers)

now it always shows same numbers.

then whats wrong with my code ? why always same students ?

@NavpreetDevpuri NavpreetDevpuri changed the title Trying to randomize students creatures in TeacherStudentsScene but it shows same students every time i render Trying to randomize students creatures in TeacherStudentsScene but it shows same students every time when i render Apr 25, 2020
@NavpreetDevpuri
Copy link
Author

it solved by putting random.seed()

random.seed()
self.students = VGroup(*[
            random.choice([PlusCreature,
                          MinusCreature,
                          MultiCreature,
                          DivCreature,
                          RemCreature,
                          AndCreature,
                          EqualCreature,
                          RoundBracketsCreature,
                          CurlyBracketsCreature,
                          SquareBracketsCreature,
                          AngleBracketsCreature,
                          HashCreature,
                          QuestionCreature])(color=c)
            for c in self.student_colors
        ])

@NavpreetDevpuri
Copy link
Author

following code is for selecting creatures without repetition

random.seed()
        temp = random.sample(
            [PlusCreature,
             MinusCreature,
             MultiCreature,
             DivCreature,
             RemCreature,
             AndCreature,
             EqualCreature,
             RoundBracketsCreature,
             CurlyBracketsCreature,
             SquareBracketsCreature,
             AngleBracketsCreature,
             HashCreature,
             QuestionCreature], len(self.student_colors)
        )
        self.students = VGroup(*[
            i(color=c)
            for c,i in zip(self.student_colors,temp)
        ])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant