Page 1 of 1

First-person blinking effect?

Posted: Mon Mar 17, 2014 6:30 pm
by Rosstin2
Sorry I keep asking these, I wish we had better search functions or TOCs. When I search for this, I keep finding things about character expression code.

I'm dead certain I saw someone post a very nice "blinking" effect a month or so ago, in the Cookbook, Creator Discussion, or Ren'Py Questions, I forget. The kind where it simulates a first-person human eye? I'm looking for a nice effect like that for Queen.

To be clear, I mean something like this: http://www.youtube.com/watch?v=bhVDvl7GxZI

More detailed search with better terms, I'm finding some stuff:
http://lemmasoft.renai.us/forums/viewto ... =8&t=23300
http://lemmasoft.renai.us/forums/viewto ... =8&t=24541

Re: First-person blinking effect?

Posted: Mon Mar 17, 2014 7:03 pm
by Asceai
Use an ImageDissolve transition. Multiply a vertical 0->1->0 gradient with a circular 0->1 gradient for your control image, then transition to / from black. The eye open animation should have reverse=False, the eye close animation should have reverse=True.

Re: First-person blinking effect?

Posted: Mon Mar 17, 2014 7:28 pm
by Asceai
It's a pretty hard effect to get quite right, but here is my attempt, just to give you a general idea. Someone not as inept at image manipulation would probably do a 10x better job.

Code: Select all

init python:
  def eyewarp(x):
    return x**1.33
  eye_open = ImageDissolve("eye.png", .5, ramplen=128, reverse=False, time_warp=eyewarp)
  eye_shut = ImageDissolve("eye.png", .5, ramplen=128, reverse=True, time_warp=eyewarp)
image black:
  Solid("#000")
image white:
  Solid("#FFF")

label start:
    scene black
    "Asleep"
    scene white
    with eye_open
    "Awake"
    scene black
    with eye_shut
    "Asleep"
    return

Re: First-person blinking effect?

Posted: Mon Mar 17, 2014 7:46 pm
by Asceai
Played around some more- this one is a little better:

Re: First-person blinking effect?

Posted: Mon Mar 17, 2014 9:47 pm
by Rosstin2
Wow, this is really good, Asc!

I meant to delete this topic after I necroed the other one... sorry forum gods ^_^;

Re: First-person blinking effect?

Posted: Thu Nov 17, 2016 2:05 pm
by crimsonnight
Asceai wrote:It's a pretty hard effect to get quite right, but here is my attempt, just to give you a general idea. Someone not as inept at image manipulation would probably do a 10x better job.

Code: Select all

init python:
  def eyewarp(x):
    return x**1.33
  eye_open = ImageDissolve("eye.png", .5, ramplen=128, reverse=False, time_warp=eyewarp)
  eye_shut = ImageDissolve("eye.png", .5, ramplen=128, reverse=True, time_warp=eyewarp)
image black:
  Solid("#000")
image white:
  Solid("#FFF")

label start:
    scene black
    "Asleep"
    scene white
    with eye_open
    "Awake"
    scene black
    with eye_shut
    "Asleep"
    return
Sorry, I know this topic is old - I'd love to use this effect in my game but I'm getting the following error when trying to use this code:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 153: expected an indented block
    return x**1.33
          ^
    

Ren'Py Version: Ren'Py 6.99.12.1912
How do I correct it?

Re: First-person blinking effect?

Posted: Thu Nov 17, 2016 2:46 pm
by Donmai
As the error is telling you. Check the indentation. Asceai's example code uses two spaces for indentation. It works, but if you mix it with another piece of code that uses a different indentation, you may have problems. Try 4-spaces indentation, for example:

Code: Select all

init python:
    def eyewarp(x):
        return x**1.33
    eye_open = ImageDissolve("eye.png", .5, ramplen=128, reverse=False, time_warp=eyewarp)
    eye_shut = ImageDissolve("eye.png", .5, ramplen=128, reverse=True, time_warp=eyewarp)
image black:
    Solid("#000")
image white:
    Solid("#FFF")

label start:
    scene black
    "Asleep"
    scene white
    with eye_open
    "Awake"
    scene black
    with eye_shut
    "Asleep"
    return
Does it work for you?
BTW, if you want to use this effect to simulate someone falling asleep and awakening, it would be better to change the .5 value to something like 1.0 or 2.0.

Re: First-person blinking effect?

Posted: Thu Nov 17, 2016 3:06 pm
by crimsonnight
Donmai wrote:As the error is telling you. Check the indentation. Asceai's example code uses two spaces for indentation. It works, but if you mix it with another piece of code that uses a different indentation, you may have problems. Try 4-spaces indentation, for example:

Code: Select all

init python:
    def eyewarp(x):
        return x**1.33
    eye_open = ImageDissolve("eye.png", .5, ramplen=128, reverse=False, time_warp=eyewarp)
    eye_shut = ImageDissolve("eye.png", .5, ramplen=128, reverse=True, time_warp=eyewarp)
image black:
    Solid("#000")
image white:
    Solid("#FFF")

label start:
    scene black
    "Asleep"
    scene white
    with eye_open
    "Awake"
    scene black
    with eye_shut
    "Asleep"
    return
Does it work for you?
BTW, if you want to use this effect to simulate someone falling asleep and awakening, it would be better to change the .5 value to something like 1.0 or 2.0.
Thanks, I think I was being an idiot, I've got it working now... only it isn't what I hoped for. There doesn't seem to be any actual blinking :(
My aim is to create an effect of someone blinking rapidly a few times, for example after being exposed to a bright light - maybe I should start a new thread?

Re: First-person blinking effect?

Posted: Mon May 28, 2018 7:10 pm
by redeyedangel01
Asceai wrote:
Mon Mar 17, 2014 7:28 pm
It's a pretty hard effect to get quite right, but here is my attempt, just to give you a general idea. Someone not as inept at image manipulation would probably do a 10x better job.

Code: Select all

init python:
  def eyewarp(x):
    return x**1.33
  eye_open = ImageDissolve("eye.png", .5, ramplen=128, reverse=False, time_warp=eyewarp)
  eye_shut = ImageDissolve("eye.png", .5, ramplen=128, reverse=True, time_warp=eyewarp)
image black:
  Solid("#000")
image white:
  Solid("#FFF")

label start:
    scene black
    "Asleep"
    scene white
    with eye_open
    "Awake"
    scene black
    with eye_shut
    "Asleep"
    return
I'm aware that this thread is super old but i was wondering if i might have your permission in using this code for my game?
I just starting learning renpy recently.
and if on the off-chance that i make profit off of my game in the future i really need your permission to use the code before i can use it in good faith.

Re: First-person blinking effect?

Posted: Mon Jun 10, 2019 9:38 pm
by richycapy
Amazing animation!! Congrats!!

Re: First-person blinking effect?

Posted: Tue Sep 10, 2019 9:54 pm
by Treladon
I know it's been a while since this was posted, but for anyone who ends up here (like I did) I wanted to post what I ended up doing as well. Another option if you like.

I wanted to player to see main character blinking a few times over the background (like they're waking up, trying to clear their vision, etc.), so what I did was add a blank png to my images folder as well as this half-closed eye background attached (a plain black background will do basically the same thing).
eye.png
*Not sure if this attached png will actually have any transparency on LemmaSoft, so you may have to make your own.

Then I created this transform:

Code: Select all

transform blink:
        "eye.png" 
        alpha 1.0
        .1
        alpha 0.0
        .2
        alpha 1.0
        .1
        alpha 0.0
        .7
        alpha 1.0
        .1
        alpha 0.0  
I added the blank png as a background image at the beginning of the script:

Code: Select all

image blank = "blank.png"
Then every time I want the player to blink a few times, I write:

Code: Select all

show blank at blink