This coding segment takes an image and converts it into a certain number of rectangles that can rapidly appear on the screen like a distorted, fuzzy effect. I got one of my friends to get this segment working for me as I struggled to get it working. Luckily he could do it within a few minutes because he can solve these python dilemmas. Unfortunately, his effort was slightly wasted as I decided not to use this piece of coding. I felt that this type of effect was out of place.
#These are three displayables (m_rectstatic, m_rectstatic2, m_rectstatic3) and
#one displayable effect RectStatic() that make a bunch of little boxes on the screen
#that blink on and off.
#Little black squares
image m_rectstatic:
RectStatic(Solid("#000"), 320, 32, 32).sm
pos (0, 0)
size (32, 32)
#Little squares with a part of the logo
image m_rectstatic2:
RectStatic(im.FactorScale(im.Crop("gui/Horror.png", (100, 100, 128, 128)), 0.5), 10, 32, 32).sm
#Little squares with a part of the menu
image m_rectstatic3:
RectStatic(im.FactorScale(im.Crop("gui/FatherDeath.jpg", (100, 100, 64, 64)), 0.75), 10, 32, 32).sm
init python:
import math
#This effect takes a displayable, a number of rectangles to show concurrently,
#and a size for the rectangles, then makes them randomly show up on the screen
#RectStatic(Solid("#000"), 32, 32, 32) would make 32 32x32 black squares
#That show up randomly on the screen
class RectStatic(object):
def __init__(self, theDisplayable, numRects=12, rectWidth = 30, rectHeight = 30):
self.sm = SpriteManager(update=self.update)
self.rects = [ ]
self.timers = [ ]
self.displayable = theDisplayable
self.numRects = numRects
self.rectWidth = rectWidth
self.rectHeight = rectHeight
#Make copies of the displayables
for i in range(self.numRects):
self.add(self.displayable)
self.timers.append(random.random() * 0.1 + 0.1)
#Rectangles show up on a grid
def add(self, d):
s = self.sm.create(d)
s.x = random.randint(0, 40) * 32
s.y = random.randint(0, 23) * 32
s.width = self.rectWidth
s.height = self.rectHeight
self.rects.append(s)
def update(self, st):
for i, s in enumerate(self.rects):
if st >= self.timers[i]:
s.x = random.randint(0, 40) * 32
s.y = random.randint(0, 23) * 32
self.timers[i] = st + random.random() * 0.1 + 0.1
return 0
-----------------------------------------------------------------------------------------------------------------------------
This coding segment is going to be used to create a pulsing vein effect around the edge of the screen. This will represent sanity, stress, eye strain. It is very effective at enhancing the story text with the images as it adds towards the atmospheric tension that will emit in certain scenes.
init python:
import math
class AnimatedMask(renpy.Displayable):
def __init__(self, child, mask, maskb, oc, op, moving=True, speed=1.0, frequency=1.0, amount=0.5, **properties):
super(AnimatedMask, self).__init__(**properties)
self.child = renpy.displayable(child) #The image (or color) being filtered
self.mask = renpy.displayable(mask) #A mask that hides the image
self.maskb = renpy.displayable(maskb) #A second mask that hides the image
self.oc = oc
self.op = op
self.null = None
self.size = None
self.moving = moving
self.speed = speed
self.amount = amount
self.frequency = frequency
def render(self, width, height, st, at):
cr = renpy.render(self.child, width, height, st, at)#.subsurface(((st * 50) % width, 0, width, height))
mr = renpy.render(self.mask, width, height, st, at)#.subsurface(((-st * 50) % width, 0, width, height))
mb = renpy.Render(width, height)
if self.moving:
mb.place(self.mask, ((-st * 50) % (width * 2)) - (width * 2), 0)
mb.place(self.maskb, -width / 2, 0)
else:
mb.place(self.mask, 0, 0)
mb.place(self.maskb, 0, 0)
cw, ch = cr.get_size()
mw, mh = mr.get_size()
w = min(cw, mw)
h = min(ch, mh)
size = (w, h)
if self.size != size:
self.null = Null(w, h)
nr = renpy.render(self.null, width, height, st, at)
rv = renpy.Render(w, h, opaque=False)
rv.operation = renpy.display.render.IMAGEDISSOLVE
rv.operation_alpha = 1.0
rv.operation_complete = self.oc + math.pow(math.sin(st * self.speed / 8), 64 * self.frequency) * self.amount #Opacity varies sinusoidally with time
rv.operation_parameter = self.op
rv.blit(mb, (0, 0), focus=False, main=False)
rv.blit(nr, (0, 0), focus=False, main=False)
rv.blit(cr, (0, 0))
renpy.redraw(self, 0)
return rv
image veins:
AnimatedMask("images/veinmask.png", "images/veinmask.png", "images/veinmaskb.png", 0.15, 16, moving=False, speed=10.0, frequency=0.25, amount=0.1)
xanchor 0.05 zoom 1.10
xpos -5
subpixel True
parallel:
ease 2.0 xpos 5
ease 1.0 xpos 0
ease 1.0 xpos 5
ease 2.0 xpos -5
ease 1.0 xpos 0
ease 1.0 xpos -5
repeat
parallel:
choice:
0.6
choice:
0.2
choice:
0.3
choice:
0.4
choice:
0.5
pass
choice:
xoffset 0
choice:
xoffset 1
choice:
xoffset 2
choice:
xoffset -1
choice:
xoffset -2
repeat