Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C# Help: Text-Typing Animation

Name: Anonymous 2010-07-05 4:06

I wish to make the console animate typing of a string kind of like the credits for Portal (for those who HAVEN'T seen the ending of portal, watch this video to understand what i'm asking for: http://www.youtube.com/watch?v=Y6ljFaKRTrI)

How should I approach this?

Name: Anonymous 2010-07-05 4:15

foreach(char in string); console.write(char); thread.sleep(abit);

Name: Anonymous 2010-07-05 4:22

so in order to make a function like so, it would look similar to:


void AnimateString(string s, time t)
{
 foreach(char in s)
 {
  console.write(char);
  thread.sleep(t);
 }
}


"time" is obviously an invalid variable, but its just for perspective

Name: Anonymous 2010-07-05 5:04

>>1
record the time at which you start the animation. when you want to paint the screen, paint the string up to the first n characters, where n =
(elapsed_time / char_appear_delay).

Name: Anonymous 2010-07-05 6:33

Thanks, anon! here's what my function looks like and it works!


        using System;

        static void AnimateText(string s, int t)
        {
            foreach (char c in s)
            {
                Console.Write(c);
                System.Threading.Thread.Sleep(t);
            }
            Console.WriteLine("\n");
        }

Name: Anonymous 2010-07-05 7:06

Dude, I did this in Flash when I was about 13. It's not hard.

Name: FrozenVoid 2010-07-05 7:37

#include "void.h"
mainstart;for(int i=0;i<strlen(argv[1]);i++){printf("%c",argv[1][i]);usleep(300000);};mainend;
C:\Program Files\DigitalMarsC\bin\code>main "This is a test"
This is a test
C:\Program Files\DigitalMarsC\bin\code>



__________________
Orbis terrarum delenda est

Name: Anonymous 2010-07-05 7:38

>>7
Wow, that animation looks really cool!

Name: Anonymous 2010-07-05 7:43

On a shitty datalogger I used to have, this could only be done be printing the first letter, wiping the screen, printing two letters, wiping the screen, .... Bad times man

Name: FrozenVoid 2010-07-05 8:18

>>8 New features in improved version:
#include "void.h"
mainstart;if(!argv[1]){printf("Error:no arguments\nSYNTAX:\n\t%s \"some text\"",argv[0]);exit();}
int a=clock();//time.h timer
for(int i=0;argv[1][i];printf("%c",argv[1][i++])){;
usleep(300000);};
if(!strcmp(argv[2],"clk")){printf("\n%d seconds elapsed",(clock()-a)/CLOCKS_PER_SEC);}
mainend;


C:\Program Files\DigitalMarsC\bin\code>main "Animated" clk
Animated
2 seconds elapsed
C:\Program Files\DigitalMarsC\bin\code>main
Error:no arguments
SYNTAX:
        C:\Program Files\DigitalMarsC\bin\code\main.exe "some text"
C:\Program Files\DigitalMarsC\bin\code>

__________________
Orbis terrarum delenda est

Name: Anonymous 2010-07-05 8:44

>>7
look at the fucking thread title

Name: Anonymous 2010-07-05 8:49

>>11
FV hasn't ported his universal header file to C# yet (alternatively he only writes in C because he's got some kind of selective blindness)

Name: FrozenVoid 2010-07-05 9:10

Why i should support unfree, Microsoft-only platform?
http://techrights.org/2007/12/17/mono-analysis-ecma/

__________________
Orbis terrarum delenda est

Name: Anonymous 2010-07-05 9:23

>>13
You're not a vendor. >>1 was clearly looking for a C# solution. Yours was not a solution, just thread noise.

Name: Anonymous 2010-07-05 9:32

If FrozenVoid was a vendor you would have to pay for his expert enterprise C# software solution.
Since you certainly don't intend to pay, you're a thief.

Name: Anonymous 2010-11-02 16:21

Name: Sachinio 2011-12-24 23:26

A slight improvement over the proposed solution. you might want to randomize the sleep function. This gives a more 'human' feel to the text being printed.

static void AnimateString(string sentence){
   Random random = new Random();
   foreach(char letter in sentence)
   {
      Console.Write(letter);
      Thread.Sleep(random.Next(10, 100));
   }
   Console.WriteLine();
}

Name: Anonymous 2011-12-25 21:13

Name: Anonymous 2011-12-25 21:13

                        ██████████████████████  
              ██████████                      ████            ██████        ████    ██    ██  ██████    ████    ██    ██    ██  ██████  ██      ██
      ████████              ██                    ████  ████████████      ██    ██  ██    ██  ██      ██    ██  ██  ██    ██    ██      ████  ████
    ██                  ████                          ████    ██████      ██        ████████  ████    ██        ████            ████    ██  ██  ██
    ██            ██████                                ██    ██████      ██    ██  ██    ██  ██      ██    ██  ██  ██          ██      ██      ██
      ██████████████                  ██                ██    ██████        ████    ██    ██  ██████    ████    ██    ██        ██████  ██      ██
              ██████          ████████                  ██    ██████                                                                                
                    ██████████      ██                  ██    ██████                                                                                
                    ██              ██                  ██    ██████      ██████    ██    ██  ██████    ████████    ██  ██  
                    ██          ████  ██                ██    ██████      ██    ██  ██    ██  ██    ██        ██    ██  ██  
                      ██████████      ██                ██    ██████      ██    ██  ██    ██  ██████      ████      ██  ██  
                        ██        ████  ██              ██    ██████      ██    ██  ██    ██  ██    ██  ██  
                          ████████      ██              ██    ██████      ██████      ████    ██████    ████████    ██  ██  
                          ██        ████              ████    ██████  
                            ████████            ██████  ████████████  
                                    ████████████              ██████

Name: Anonymous 2011-12-25 21:24

03:23 < chrisdone> dubs = check'em

Name: Anonymous 2011-12-25 21:28

☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝
☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝
☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝
☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝
☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝☝

Name: Anonymous 2011-12-26 0:33

How would you do it with a System.Windows.Forms.Label?


for (int i = 0; i != str.Length; ++i)
{
    label1.Text = str.Substring(0, i + 1);
    Thread.Sleep(123);
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List