martastain

Blender text scrambler

Feb 27th, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # ##### BEGIN GPL LICENSE BLOCK #####
  5. #
  6. #  This program is free software; you can redistribute it and/or
  7. #  modify it under the terms of the GNU General Public License
  8. #  as published by the Free Software Foundation; either version 2
  9. #  of the License, or (at your option) any later version.
  10. #
  11. #  This program is distributed in the hope that it will be useful,
  12. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #  GNU General Public License for more details.
  15. #
  16. #  You should have received a copy of the GNU General Public License
  17. #  along with this program; if not, write to the Free Software Foundation,
  18. #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. #
  20. # ##### END GPL LICENSE BLOCK #####
  21.  
  22. import bpy, string, random
  23. from bpy.app.handlers import persistent
  24.  
  25.  
  26. bl_info = {
  27.     'name': 'Text scrambler',
  28.     'author': 'Martin Wacker',
  29.     'version': '0.1',
  30.     'blender': (2, 6, 5),
  31.     'location': 'Properties Editor, Text Context',
  32.     'description': 'Text scrambler effect. Based on Bassam Kurdali\'s Typewriter Text effect',
  33.     'url': 'mailto:[email protected]',
  34.     'category': 'Text'}
  35.  
  36. __bpydoc__ = """
  37. Text scrambler For Font Objects
  38. """
  39.  
  40. def uptext(text):
  41.     source = text.source_text
  42.     if source in bpy.data.texts:
  43.         r = bpy.data.texts[source].as_string()
  44.     else:
  45.         r = source
  46.  
  47.     base = len(r)
  48.     prog = text.scrambler_progress / 100.0
  49.  
  50.     c = int(base * prog)
  51.  
  52.     clean     = r[:base-c]
  53.     scrambled = ""
  54.     for i in range(c):
  55.         scrambled += random.choice(text.characters)
  56.     text.body = clean+scrambled
  57.  
  58.  
  59. @persistent  
  60. def textscrambler_update_frame(scene):
  61.     for text in scene.objects:
  62.         if text.type == 'FONT' and text.data.use_text_scrambler:
  63.             uptext(text.data)
  64.  
  65. def update_func(self, context):
  66.     uptext(self)
  67.    
  68.    
  69. class TEXT_PT_Textscrambler(bpy.types.Panel):
  70.     bl_label       = "Text scrambler"
  71.     bl_idname      = "TEXT_PT_Textscrambler"
  72.     bl_space_type  = 'PROPERTIES'
  73.     bl_region_type = 'WINDOW'
  74.     bl_context     = 'data'
  75.  
  76.     @classmethod
  77.     def poll(cls, context):
  78.         return context.active_object and context.active_object.type == 'FONT'
  79.  
  80.     def draw_header(self, context):
  81.         text = context.active_object.data
  82.         layout = self.layout
  83.         layout.prop(text, 'use_text_scrambler', text="")
  84.  
  85.     def draw(self, context):
  86.         text   = context.active_object.data
  87.         layout = self.layout
  88.         layout.prop(text,'scrambler_progress', text="Progress")
  89.         layout.prop(text,'source_text', text="Source text")
  90.         layout.prop(text,'characters', text="Characters")
  91.  
  92. def register():
  93.     bpy.types.TextCurve.scrambler_progress = bpy.props.IntProperty    (name="scrambler_progress",update=update_func, min=0, max=100, options={'ANIMATABLE'})
  94.     bpy.types.TextCurve.use_text_scrambler = bpy.props.BoolProperty   (name="use_text_scrambler", default=False)
  95.     bpy.types.TextCurve.source_text        = bpy.props.StringProperty (name="source_text")
  96.     bpy.types.TextCurve.characters         = bpy.props.StringProperty (name="characters",default="ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghjklmnopqrstuvwxyz")
  97.     bpy.utils.register_module(__name__)
  98.     bpy.app.handlers.frame_change_pre.append(textscrambler_update_frame)
  99.  
  100. def unregister():
  101.     bpy.app.handlers.frame_change_pre.remove(textscrambler_update_frame)
  102.     bpy.utils.unregister_module(__name__)
  103.  
  104. if __name__ == "__main__":
  105.     register()
Advertisement
Add Comment
Please, Sign In to add comment