3

I want the smoke at the top to move infinitely. I am looking for a simple implementation. Here is my code:

def welcome():

    print("               (")
    print("                 )")
    print("               (")
    print("                _)")
    print("     __________| |____")
    print("    /                 \\")
    print("   /     Welcome to    \\")
    print("  /     A Horror Game   \\")
    print("  |    By: A.D & T.P    |")
    print("  |     ____     ___    |")
    print("  |    |    |   |___|   |")
    print("__|____|____|___________|__")
    print("")

    time.sleep(1)
ePi272314
  • 12,557
  • 5
  • 50
  • 36
  • 3
    If you want that kind of animation, keeping it simple isn't likely - you'll probably have to take total control of the terminal with a module like `curses`. – user2357112 Mar 21 '20 at 00:00
  • Use ANSI escape codes to clear the screen: https://stackoverflow.com/questions/37774983/clearing-the-screen-by-printing-a-character/37778152#37778152 and timers and a loop – Richard Mar 21 '20 at 00:03
  • 1
    @Richard: That's probably going to interfere with user input echoing, and cause awkward blinking too. – user2357112 Mar 21 '20 at 00:04
  • @user2357112supportsMonica: Probably, though I think there are more specific codes for manipulating individual characters. – Richard Mar 21 '20 at 04:28

3 Answers3

4

Welcome newbie

Below a possible implementation without using any specialized package.
However, also look to these packages: curses and asciimatics.

See and play with this example in this online interpreter.
Here is an animated gif.

import time
import platform    # Used by clear_screen
import subprocess  # Used by clear_screen

# System independent clear screen function
# https://stackoverflow.com/questions/18937058/#42877403
def clear_screen():
    command = "cls" if platform.system().lower()=="windows" else "clear"
    return subprocess.call(command) == 0

def smoke():
    # You could use the random package for a more realistic effect
    # https://docs.python.org/3/library/random.html

    shift = 15 + smoke.shift
    print(" "*(shift+2)+"(")
    print(" "*(shift  )+")")
    print(" "*(shift+2)+"(")
    print(" "*(shift  )+")")

    # Next shift using current direction
    smoke.shift += smoke.direction

    # Change direction if out of limits
    if smoke.shift>3 or smoke.shift<-2:
        smoke.direction *= -1

def house():
    print("     __________| |____")
    print("    /                 \\")
    print("   /     Welcome to    \\")
    print("  /     A Horror Game   \\")
    print("  |    By: A.D & T.P    |")
    print("  |     ____     ___    |")
    print("  |    |    |   |___|   |")
    print("__|____|____|___________|__")
    print()

# MAIN CODE

smoke.shift = 0
smoke.direction = 1 # could be 1 or -1


# print('\033[2J') # One possible method to clear the screen
clear_screen()

# Infinite loop. Use CTR-C to stop
while True:   
    smoke()
    house()
    time.sleep(1)
    clear_screen()
ePi272314
  • 12,557
  • 5
  • 50
  • 36
  • Thank you ePi27... , but when the code starts, the house continuously moves down, and instead of the smoke going left and right, is it possible for it to go up and down? Thank you – Student.Coder Mar 21 '20 at 03:05
  • Is working. I tried again in the online compiler, and the smoke was moving. I also checked on my Mac. I will add a video. Perhaps the clear screen in not working your system. Try to get the code running in your system and later improve the smoke movement using random numbers. – ePi272314 Mar 21 '20 at 15:27
  • I updated the code to clear the screen using another method to that is system independent – ePi272314 Mar 21 '20 at 15:35
  • Thanks man! It works like a charm! One more thing, I have a lot of code after this but that code isn't operating. Is that meant to happen? If yes,is there any way i can fix it? – Student.Coder Mar 22 '20 at 06:41
  • Try to identify your problems (probably you have few) and post then in separate questions. See here how to ask . – ePi272314 Mar 22 '20 at 12:54
  • One more thing, consider accepting my answer as the correct answer for your question. You should click in the check mark – ePi272314 Mar 22 '20 at 12:58
1

You'd probably want to do something simply such as create a while loop that calls upon multiple functions with print statements placing the smoke in different locations, e.g.:

def welcome2():


print("                 (")
print("               )")
print("                 (")
print("               _)")
print("     __________| |____")
print("    /                 \\")
print("   /     Welcome to    \\")
print("  /     A Horror Game   \\")
print("  |    By: A.D & T.P    |")
print("  |     ____     ___    |")
print("  |    |    |   |___|   |")
print("__|____|____|___________|__")
print("")
time.sleep(1)

or something of the sort. If you call on multiple functions repeatedly it would appear as though smoke is "moving." I'm not exactly sure where you're calling this welcome function from though.

murky123
  • 120
  • 6
0

I think this is an interesting question, I dig it. Building off of ePi272314 's answer, you could try the following for another cool smoke effect. Hope that helps!

import time
import os
from os import system, name

# define our clear function
def clear():
    os.system( 'cls' )

def welcome():

    smoke = ['               (_)','               ()', '                ()','               ()', '                ()']
    print("\n"*4)
    print("                _     ")
    print("     __________| |____")
    print("    /                 \\")
    print("   /     Welcome to    \\")
    print("  /     A Horror Game   \\")
    print("  |    By: A.D & T.P    |")
    print("  |     ____     ___    |")
    print("  |    |    |   |___|   |")
    print("__|____|____|___________|__")
    print("")
    time.sleep(.6)
    clear()

    print("\n"*5)
    print (smoke[0])
    print("     __________| |____")
    print("    /                 \\")
    print("   /     Welcome to    \\")
    print("  /     A Horror Game   \\")
    print("  |    By: A.D & T.P    |")
    print("  |     ____     ___    |")
    print("  |    |    |   |___|   |")
    print("__|____|____|___________|__")
    print("")
    time.sleep(.6)
    clear()

    print("\n"*4)
    print (smoke[1])
    print (smoke[0])
    print("     __________| |____")
    print("    /                 \\")
    print("   /     Welcome to    \\")
    print("  /     A Horror Game   \\")
    print("  |    By: A.D & T.P    |")
    print("  |     ____     ___    |")
    print("  |    |    |   |___|   |")
    print("__|____|____|___________|__")
    print("")
    time.sleep(.6)
    clear()

    print("\n"*3)
    print (smoke[2])
    print (smoke[1])
    print (smoke[0])
    print("     __________| |____")
    print("    /                 \\")
    print("   /     Welcome to    \\")
    print("  /     A Horror Game   \\")
    print("  |    By: A.D & T.P    |")
    print("  |     ____     ___    |")
    print("  |    |    |   |___|   |")
    print("__|____|____|___________|__")
    print("")
    time.sleep(.6)
    clear()

    print("\n"*2)
    print (smoke[3])
    print (smoke[2])
    print (smoke[1])
    print (smoke[0])
    print("     __________| |____")
    print("    /                 \\")
    print("   /     Welcome to    \\")
    print("  /     A Horror Game   \\")
    print("  |    By: A.D & T.P    |")
    print("  |     ____     ___    |")
    print("  |    |    |   |___|   |")
    print("__|____|____|___________|__")
    print("")
    time.sleep(.6)
    clear()

    print("\n"*1)
    print (smoke[4])
    print (smoke[3])
    print (smoke[2])
    print (smoke[1])
    print (smoke[0])
    print("     __________| |____")
    print("    /                 \\")
    print("   /     Welcome to    \\")
    print("  /     A Horror Game   \\")
    print("  |    By: A.D & T.P    |")
    print("  |     ____     ___    |")
    print("  |    |    |   |___|   |")
    print("__|____|____|___________|__")
    print("")
    time.sleep(.6)
    clear()




while True:
    welcome()
    print('\033[2J')
B-L
  • 144
  • 1
  • 8
  • Thank you Brack,but the house just duplicates, each house different. Is that meant to happen? – Student.Coder Mar 21 '20 at 03:06
  • Hi Student Coder no problem at all!, I modified the code a bit. Go ahead and run that in the windows console and let me know if that is what you are looking for. (will need some adjustment if you are using a mac). – B-L Mar 21 '20 at 10:06
  • Hi Student.Coder, I think you should give my code a shot. The smoke goes up and down which is what i think you are looking for. Having the house print in multiple iterations and clearing them as murky123 described, is what I have done here. I have just written the code out in long form so that it is better to understand – B-L Mar 23 '20 at 13:22