Skip to content

Instantly share code, notes, and snippets.

@pathakcodes
Created March 15, 2020 07:49
Show Gist options
  • Save pathakcodes/6f2905f171fc009284452b30eccac69c to your computer and use it in GitHub Desktop.
Save pathakcodes/6f2905f171fc009284452b30eccac69c to your computer and use it in GitHub Desktop.
from manimlib.imports import *
def set_background(self):
background = Rectangle(
width = FRAME_WIDTH,
height = FRAME_HEIGHT,
stroke_width = 0,
fill_color = "#145963",
fill_opacity = 1)
self.add(background)
class Grid(VGroup):
CONFIG = {
"height": 6.0,
"width": 6.0,
}
def __init__(self, rows, columns, **kwargs):
digest_config(self, kwargs, locals())
super().__init__(**kwargs)
x_step = self.width / self.columns
y_step = self.height / self.rows
for x in np.arange(0, self.width + x_step, x_step):
self.add(Line(
[x - self.width / 2., -self.height / 2., 0],
[x - self.width / 2., self.height / 2., 0],
))
for y in np.arange(0, self.height + y_step, y_step):
self.add(Line(
[-self.width / 2., y - self.height / 2., 0],
[self.width / 2., y - self.height / 2., 0]
))
class ScreenGrid(VGroup):
CONFIG = {
"rows":40 ,
"columns": 50,
"height": FRAME_Y_RADIUS * 2,
"width": 14,
"grid_stroke": 0.5,
"grid_color": "#091517",
"axis_color": RED,
"axis_stroke": 0,
"labels_scale": 0.25,
"labels_buff": 0,
"number_decimals": 2
}
def __init__(self, **kwargs):
super().__init__(**kwargs)
rows = self.rows
columns = self.columns
grid = Grid(width=self.width, height=self.height, rows=rows, columns=columns)
grid.set_stroke(self.grid_color, self.grid_stroke)
vector_ii = ORIGIN + np.array((- self.width / 2, - self.height / 2, 0))
vector_si = ORIGIN + np.array((- self.width / 2, self.height / 2, 0))
vector_sd = ORIGIN + np.array((self.width / 2, self.height / 2, 0))
axes_x = Line(LEFT * self.width / 2, RIGHT * self.width / 2)
axes_y = Line(DOWN * self.height / 2, UP * self.height / 2)
axes = VGroup(axes_x, axes_y).set_stroke(self.axis_color, self.axis_stroke)
divisions_x = self.width / columns
divisions_y = self.height / rows
directions_buff_x = [UP, DOWN]
directions_buff_y = [RIGHT, LEFT]
dd_buff = [directions_buff_x, directions_buff_y]
vectors_init_x = [vector_ii, vector_si]
vectors_init_y = [vector_si, vector_sd]
vectors_init = [vectors_init_x, vectors_init_y]
divisions = [divisions_x, divisions_y]
orientations = [RIGHT, DOWN]
labels = VGroup()
set_changes = zip([columns, rows], divisions, orientations, [0, 1], vectors_init, dd_buff)
# for c_and_r, division, orientation, coord, vi_c, d_buff in set_changes:
# for i in range(1, c_and_r):
# for v_i, directions_buff in zip(vi_c, d_buff):
# ubication = v_i + orientation * division * i
# coord_point = round(ubication[coord], self.number_decimals)
# label = Text(f"{coord_point}",font="Arial",stroke_width=0).scale(self.labels_scale)
# label.next_to(ubication, directions_buff, buff=self.labels_buff)
# labels.add(label)
self.add(grid, axes, labels)
def image(o,a,b,c,d):
text = TextMobject(a)
text.scale(2)
text.shift(3*LEFT)
img = ImageMobject(b)
img.scale(d) # Resize to be twice as big
img.shift(2 * RIGHT) # Move the image
o.play(FadeIn(img))
o.add_sound(c)
o.play(FadeIn(text)) # Display the image
o.remove(img)
o.remove(text)
def text(o,a,b):
text = TextMobject(a)
o.add(text.scale(2))
o.add(text)
o.add_sound(b)
o.play(FadeOut(text))
class WhatCanDo(Scene):
def construct(self):
set_background(self)
grid = ScreenGrid()
self.add(grid)
text(self,"There are eight","1.mp3")
image(self,"planets","planets.jpg","2.mp3",2)
text(self,"in our","3.mp3")
image(self,"solar system.","ss.png","4.mp3",1.4)
text(self,"In order of their","5.mp3")
image(self,"distance","distance.png","6.mp3",2)
image(self,"from the sun","sun.jpg","7.mp3",1.5)
text(self,"they are:","8.mp3")
image(self,"Mercury","mercury.jpg","9.mp3",2)
image(self,"Venus","venus.jpg","10.mp3",2)
image(self,"Earth","earth.jpg","11.mp3",2)
image(self,"Mars","mars.jpeg","12.mp3",2)
image(self,"Jupiter","jupiter.png","13.mp3",2)
image(self,"Saturn","saturn.png","14.mp3",2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment