Skip to content

Commit

Permalink
2.7
Browse files Browse the repository at this point in the history
2.7
  • Loading branch information
kerem3338 authored Sep 18, 2022
1 parent f64ee80 commit 9d90a53
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 78 deletions.
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2021 Zoda

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2021 Zoda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
## Türkçe
**Boip ile artık Metin tabanlı animasyonlar yapabilirsiniz. Boip hem hızlı hemde kullanımı basittir**

## English
**With Boip you can now make Text based animations. Boip is both fast and simple to use.**

# Example / Örnek

```python
import animator
app=animator.Animator()
app.scene("->")
app.scene("-->")
app.scene("--->")
app.scene("---->")
app.play()
```
![boip simple example](assets/boip.png)
## Türkçe
**Boip ile artık Metin tabanlı animasyonlar yapabilirsiniz. Boip hem hızlı hemde kullanımı basittir**

## English
**With Boip you can now make Text based animations. Boip is both fast and simple to use.**

# Example / Örnek
<br>

![Boip simple example](assets/example.gif)<br><br>
**[Source code](examples/arrow.py)**

122 changes: 82 additions & 40 deletions animator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Boip Animator is a python library for creating text-based animations.
sample
import animator
app = animator.Animator()
app.scene("<")
Expand All @@ -11,12 +12,14 @@
app.scene("<<<<")
app.play()
"""

import os
import sys
import time
import locale
import glob
import getpass
import threading

config = {
"err-show": True
Expand All @@ -35,9 +38,20 @@



class Frame:
"""Frame class for creating frames."""
def __init__(self,content:str):
self.content=content


def change(self,content:str):
self.content=content

def __str__(self):
return self.content

class Animator:
def __init__(self, sleep_mode=True, sleep:int or float or double=1.0):
def __init__(self, sleep_mode=True, sleep:int or float=1.0):
self.sleep_mode=sleep_mode
self.system_lang = locale.getdefaultlocale()[0]

Expand All @@ -50,7 +64,8 @@ def __init__(self, sleep_mode=True, sleep:int or float or double=1.0):
self.scenes = []

self.sleep = sleep
self.version = "2.6"
self.nmode_char="\n"
self.version = "2.7"


self.animation_info = {"author": getpass.getuser(), "usr_lang": self.system_lang, "sleep_mode": self.sleep_mode, "sleep": self.sleep, "scene_count": self.scenes_count, "boip_ver": self.version}
Expand All @@ -64,8 +79,6 @@ def lenght(self):
return int(self.scenes_count)*int(self.sleep)
elif type(self.sleep) == float:
return float(self.scenes_count)*self.sleep
elif type(self.sleep) == double:
return double(self.scenes_count)*self.sleep
else:
print(self.sleep_error)

Expand All @@ -80,24 +93,32 @@ def scene_from_file(self, file, encoding="utf8"):
self.scene_count += 1

def scenes_from_file(self,filename,encoding="utf8"):
"""adds new scenes from file"""
with open(filename,"r",encoding=encoding) as f:
scenes_count=f.read().split(",")
for i in range(len(scenes_count)-1):
self.scenes.append(scenes_count[i])

def scenes_from_dir(self, dir, fileextension="txt"):
"""adds new scenes from dir
Example
test_directory/
0.txt
1.txt
"""
for i in range(len(glob.glob(f"{dir}\\*.{fileextension}"))):
with open(f"{dir}\\{i}.{fileextension}", "r") as file:
self.scenes.append(file.read())
self.scenes_count += 1

def scene(self, scene):
"""add new scene"""

self.scenes.append(scene)
self.scenes_count += 1

def shape(self, shape, position=None):
"""return shape"""
"""returns a shape"""
square = "##\n##"
if shape == "square":
return square
Expand Down Expand Up @@ -139,7 +160,7 @@ def scenes_count(self):
"""NOT:Sahne içinde kullanılırsa bulunduğu sahneyi eklemez örnek: eğer projenizde 6 sahne varsa 5 sahne gösterecektir eğer sahnenin içinde kullanmazsanız sahne sayınızı normal bir şekilde gösterecektir"""
return self.scenes_count

def set_sleep(self, sleep:int or float or double):
def set_sleep(self, sleep:int or float):
if self.sleep_mode is True:
self.sleep = sleep
else:
Expand All @@ -148,14 +169,17 @@ def set_sleep(self, sleep:int or float or double):



def clear(self):
def clear(self,nmode=False,scenelenght=None,lastlenght=None):
"""clear screen"""
if os.name == "nt":
os.system("cls")
if nmode == False:
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
else:
os.system("clear")
print(self.nmode_char*(scenelenght*os.get_terminal_size().columns))

def play(self):
def play(self,nmode=False):
"""Starts Animation"""
try:
cursor.hide()
Expand All @@ -167,68 +191,86 @@ def play(self):
for i in range(len(self.scenes)):
try:
playing_scene=i
self.clear()
scene_lenght=len(self.scenes[i].splitlines())
last_lenght=len(self.scenes[i].splitlines())
self.clear(nmode=nmode,scenelenght=scene_lenght,lastlenght=last_lenght)
print(self.scenes[i])
time.sleep(self.sleep)
self.clear()
self.clear(nmode=nmode,scenelenght=scene_lenght,lastlenght=last_lenght)
except KeyboardInterrupt:
self.clear()
print(f"Exited... Last scene: {playing_scene}")
sys.exit()
cursor.show()
sys.exit()

else:
for i in range(len(self.scenes)):
try:
scene_lenght=len(self.scenes[i].splitlines())
last_lenght=len(self.scenes[i].splitlines())
playing_scene=i
self.clear()
self.clear(nmode=nmode,scenelenght=scene_lenght,lastlenght=last_lenght)
print(self.scenes[i])
self.clear()
self.clear(nmode=nmode,scenelenght=scene_lenght,lastlenght=last_lenght)
except KeyboardInterrupt:
self.clear()
print(f"Exited... Last scene: {playing_scene}")
sys.exit()
cursor.show()
sys.exit()












def export_scenes_dir(self, dir, fileextension="txt"):
"""Exports All scenes to directory"""
_ok=None
if self.system_lang == "tr_TR":
print("Yapmak istediğiniz işlem Kritik bir işlemdir\nEğer sahne sayısı fazla bir animasyonun çıktısını almak istiyorsanız bu yöntem öenerilmez\nBilgisayarınızın hızını düşürebilir ayrıca diskte baya yer kaplar")
print("Yapmak istediğiniz işlem Kritik bir işlemdir\nEğer sahne sayısı fazla bir animasyonun çıktısını almak istiyorsanız bu yöntem önerilmez\nBilgisayarınızın hızını düşürebilir ayrıca diskte büyük miktarda yer kaplar")
onayla = input("Onaylıyormusunuz (evet/hayır/hayir)")
if onayla == "evet":
pass
_ok=True
elif onayla == "hayır" or "hayir":
sys.exit()
pass
else:
print("The operation you want to do is a critical operation\nIf you want to output an animation with a large number of scenes, this method is not recommended\nIt may reduce the speed of your computer, and it also takes up a lot of space on the disk.")
onayla = input("Do you confirm (yes/no)")
if onayla == "yes":
pass
_ok=True
elif onayla == "no":
sys.exit()

if os.path.isdir(dir):
for i in range(len(self.scenes)):
with open(f"{dir}\\{i}.{fileextension}", "w") as file:
file.write(self.scenes[i])
else:
if self.system_lang == "tr_TR":
print(f"{dir} Dosya yolu bulunamadı")
pass
if _ok:
if os.path.isdir(dir):
for i in range(len(self.scenes)):
with open(f"{dir}\\{i}.{fileextension}", "w") as file:
file.write(self.scenes[i])
else:
print("f{dir} File path not found")
if self.system_lang == "tr_TR":
print(f"{dir} Dosya yolu bulunamadı")
else:
print("f{dir} File path not found")

def export_scenes(self, exportfile, encoding="utf8"):
def export_scenes(self, exportfile, encoding="utf8",type="normal",x=30,y=30):
"""export all scenes"""
with open(exportfile, "w", encoding=encoding) as exportfile:

if self.system_lang == "tr_TR":
exportfile.write(f"Boip Animator Kullanılarak yapıldı versiyon:{self.version}\n")
else:
exportfile.write(f"Created using Boip Animator version:{self.version}\n")
for i in range(len(self.scenes)):
exportfile.write(",")
exportfile.write(self.scenes[i])
if type=="asciimation":
exportfile.write(f"x:{x}\ny:{y}\nBEGIN\n")
for i in range(len(self.scenes)):
if i==0:
pass
else:exportfile.write("\nEND\n")
scene=self.scenes[i]
scene=scene.replace("END","end")
exportfile.write(scene)

if type=="normal":
for i in range(len(self.scenes)):
exportfile.write(",")
exportfile.write(self.scenes[i])
Binary file added assets/boip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# V2.7


* changes.md dosyası eklendi.
* Çeşitli Hata düzeltmeleri.
* Yazım hataları düzeltildi.
* `export_scenes_dir` fonksiyonu artık çıktı işlemini onaylarken işlemi iptal ederseniz programı sonlandırmayacak.
* `export_scenes` fonksiyonu ile artık animasyonlarınızı (asciimation)[https://github.com/octobanana/asciimation] animasyonu olarakta dışa aktarabilirsiniz!
* Animasyon yaratmayı kolaylaştıran Grafik sahne arayüz programı hazırlanıyor.
8 changes: 8 additions & 0 deletions examples/arrow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import animator
app=animator.Animator()
app.scene("->")
app.scene("-->")
app.scene(" -->")
app.scene(" -->")
app.scene(" -->")
app.play()

0 comments on commit 9d90a53

Please sign in to comment.