text:
8-bit style bouncing ball around a canvas
Inspired by this listing from the Commodore 64 User's Guide:
10 PRINT "{CLR/HOME}"
20 POKE 53280,7 : POKE 53281,13
30 X = 1 : Y = 1
40 DX = 1 : DY = 1
50 POKE 1024 + X + 40 * Y, 81
60 FOR T = 1 TO 10 : NEXT
70 POKE 1024 + X + 40 * Y, 32
80 X = X + DX
90 IF X <= 0 OR X >= 39 THEN DX = -DX
100 Y = Y + DY
110 IF Y <= 0 OR Y >= 24 THEN DY = -DY
120 GOTO 50

Make a similar program in your chosen language/platform to bounce a ball-alike object around your terminal, screen, canvas or other visual display area.
You don't have to mimic the C64's PETSCII graphics exactly, a simple O or o will do, nor do you have to use the GOTO command if it exists in your language still. As long as your ball starts at the top of your canvas and travels diagonally until it hits a canvas limit, and then bounces accordingly, as follows:

Travelling downwards and right and hits the bottom of the screen area, bounces up and continues right;
Travelling up and right and hits the right-most boundary, and bounces left and up;
Travelling left and up and hits the top, bounces left and down;
Travelling left and down and reaches the left-most boundary, bounces right and down;
Hits any corner and reverses direction;

Then we're all good.
You don't have to move the ball 8-pixels at a time either, like is happening in the BASIC listing on the C64; you can move one character block or one pixel at a time, whichever you think is most appropriate.
To see this BASIC listing working, you can type it in with this online Commodore 64 emulator providing your browser supports JavaScript.

JavaScript canvas. D'uh.

I'm not sure what you call a screen nowadays. You used to have just the screen and border area viewed through your television set or VDU... and now you've got terminals, windows, canvases, stdout etc... it's all very confusing to me.

It'd be better if we had a constant pixel size value.

But that depends on what you are outputting and whether or not you are using fixed-width fonts surely?

If you want the ball height and width to be a constant then submit your entry on an 8 bit computer like the Sinclair ZX Spectrum or something ;)

Have you managed to type it into and run it on that emulator?

^ A gif with the result would be nice @ShaunBebbers

I'm using my mobile phone; I'll GIF it asap

Jonathan Allan: I've typed this program on a real C64 and variants on a VIC-20, PET, ZX81 and Spectrum many times. The program listing works

@ShaunBebbers Jonathan's comment was probably along the lines that the emulator doesn't seem to accept pasting, so you have to type it in by hand

Can we use 0 for the ball?

Yes you may use a zero - whatever you are comfortable with. As long as it bounces around the screen.

Yes, you have to type it in by hand to the online emulator as far as I know. If you use more recent versions of VICE you can copy and paste to that. Read the VICE dox to find out how

Even if you do copy/paste to VICE it probably won't recognise the {CLR/HOME} from the listing. Change line 10 to 10 PRINT CHR$(147)

Actually I made it clear in the question and description "To see this BASIC listing working, you can type it in with this online Commodore 64 emulator providing your browser supports Flash."

@ShaunBebbers Yes, it was clear. It's just annoying not being able to paste it :-)

Ah the joys of 8 bit computing. At least the C64 had a real keyboard unlike some machines.

Can we assume the screen size of 1x1 and print o forever?

Yes if you had a 1x1 screen it would print forever, but you wouldn't see it animate either. You'd have an issue with a 20 x 20 screen where it'd bounce corner to corner unless it started from somewhere other than the top left.

I can´t get it typed. All my C64s are inoperative and I can´t find the CLR/HOME key in that emulator (on a german keyboard). This thing could really use a screen keyboard.

Try print chr$(147) instead of CLR/HOME or press the Home key if you use Windows emulation

possible duplicate of ASCII Ball in Box Animation

Sorry about the possible duplication - the programming speak is so much different nowadays (scrolly texts are now animated scrolling marquees, for instance). I did a search but probably missed it or searched for the incorrect expression.

Btw, IMHO better online demo

I think this site is quite nice, just uses an emscripten-compiled vice :)

6502 machine code (C64), 90 89 91 bytes
+2 bytes because it needs a load address (not PIC because of self modification)
00 C0 20 44 E5 CA D0 FD C6 FC D0 F9 A2 20 86 FC A9 D8 85 9E A9 03 85 9F A4 CA
18 A5 9E 69 28 85 9E 90 02 E6 9F 88 10 F2 A4 C9 8A 91 9E C9 20 D0 08 E6 C9 E6
CA A2 51 10 D7 A5 C9 F0 04 C9 27 D0 08 AD 2F C0 49 20 8D 2F C0 A5 CA F0 04 C9
18 D0 B4 AD 31 C0 49 20 8D 31 C0 D0 AA

Online demo
Usage: sys49152
I tried hard to reduce size (e.g. NOT using IRQs for timing but stupid empty loops instead), still impossible to reach the level of Titus' golfed C64 BASIC :o oh, well. But it looks less flickering ;)
Explanation: (vice disassembly)
00 C0       .WORD $C000         ; load address
20 44 E5    JSR $E544           ; clear screen
CA          DEX
D0 FD       BNE $C003           ; inner wait (256 decrements)
C6 FC       DEC $FC
D0 F9       BNE $C003           ; outer wait (32 decrements in zeropage)
A2 20       LDX #$20            ; wait counter and screen code for "space"
86 FC       STX $FC             ; store wait counter
A9 D8       LDA #$D8            ; load screen base address ...
85 9E       STA $9E             ; ... -40 (quasi row "-1") ...
A9 03       LDA #$03            ; ... into vector at $9e/$9f
85 9F       STA $9F
A4 CA       LDY $CA             ; load current row in Y
18          CLC                 ; clear carry flag
A5 9E       LDA $9E             ; add ...
69 28       ADC #$28            ; ... $28 (40 cols) to ...
85 9E       STA $9E             ; ... vector
90 02       BCC $C023
E6 9F       INC $9F             ; handle carry
88          DEY                 ; count rows down
10 F2       BPL $C018
A4 C9       LDY $C9             ; load current col in Y
8A          TXA                 ; copy screen code from X to A
91 9E       STA ($9E),Y         ; store at position of screen
C9 20       CMP #$20            ; screen code was "space"
D0 08       BNE $C037           ; if not, ball was drawn
E6 C9       INC $C9             ; next column   | opcodes are modified
E6 CA       INC $CA             ; next row      | here for directions
A2 51       LDX #$51            ; screen code for "ball"
10 D7       BPL $C00E           ; and back to drawing code
A5 C9       LDA $C9             ; load current column
F0 04       BEQ $C03F           ; if zero, change X direction
C9 27       CMP #$27            ; compare with last column (39)
D0 08       BNE $C047           ; if not equal, don't change X direction
AD 2F C0    LDA $C02F           ; load opcode for X direction
49 20       EOR #$20            ; toggle between ZP INC and DEC
8D 2F C0    STA $C02F           ; store back
A5 CA       LDA $CA             ; load current row
F0 04       BEQ $C04F           ; if zero, change Y direction
C9 18       CMP #$18            ; compare with last row (24)
D0 B4       BNE $C003           ; if not equal, don't change Y direction
AD 31 C0    LDA $C031           ; load opcode for Y direction
49 20       EOR #$20            ; toggle between ZP INC and DEC
8D 31 C0    STA $C031           ; store back
D0 AA       BNE $C003           ; -> main loop

Just for fun, here's a more professional variant using a sprite for the ball and flashing the border when hit in 385 bytes (containing the sprite data that's used in place):
00 C0 AD 15 D0 F0 30 A9 CC 85 FC A9 04 20 A2 C0 A9 97 8D 00 DD A9 15 8D 18 D0
A9 00 8D 15 D0 8D 1A D0 A2 81 8E 0D DC A2 31 8E 14 03 A2 EA 8E 15 03 58 A6 D6
4C F0 E9 A9 04 85 FC A9 CC 20 A2 C0 A2 31 86 01 A2 10 A9 D0 85 FC B1 FB C6 01
91 FB E6 01 C8 D0 F5 E6 FC CA D0 F0 A9 37 85 01 A9 94 8D 00 DD A9 35 8D 18 D0
8D 27 D0 A2 05 8E F8 CF A2 01 8E 15 D0 8E 1A D0 8E 12 D0 86 FD 86 FE A2 18 8E
00 D0 A2 1B 8E 11 D0 A2 32 8E 01 D0 A2 7F 8E 0D DC AE 0D DC AE 20 D0 86 FB A2
C1 8E 14 03 A2 C0 D0 8A 85 FE 8D 88 02 A9 00 85 FB 85 FD A2 04 A0 00 78 B1 FB
91 FD C8 D0 F9 E6 FC E6 FE CA D0 F2 60 A6 FB 8E 20 D0 CE 19 D0 A5 FD F0 20 AD
00 D0 18 69 04 8D 00 D0 90 03 EE 10 D0 C9 40 D0 2C AD 10 D0 29 01 F0 25 20 38
C1 C6 FD F0 1E AD 00 D0 38 E9 04 8D 00 D0 B0 03 CE 10 D0 C9 18 D0 0C AD 10 D0
29 01 D0 05 20 38 C1 E6 FD A5 FE F0 14 AD 01 D0 18 69 04 8D 01 D0 C9 E6 D0 19
20 38 C1 C6 FE F0 12 AD 01 D0 38 E9 04 8D 01 D0 C9 32 D0 05 20 38 C1 E6 FE 4C
31 EA A9 01 8D 20 D0 60 00 00 00 7E 00 03 FF C0 07 FF E0 1F FF F8 1F FF F8 3F
FF FC 7F FF FE 7F FF FE FF FF FF FF FF FF FF FF FF FF FF FF 7F FF FE 7F FF FE
3F FF FC 1F FF F8 1F FF F8 07 FF E0 03 FF C0 00 7E 00 00 00 00

Online demo -|- browse ca65 assembler source
Start and stop the bouncing ball with sys49152.

This leaves the C64 BASIC running, that's done by moving the VIC-II address space up to $C000, which requires copying the screen contents and the character set (font).
It hooks into the system IRQ and to avoid flicker, changes the source of this IRQ to the VIC-II graphics chip, so updates are always done between frames.
Glitches:

RUN/STOP + RESTORE is broken, don't try.
With the VIC-II as IRQ source, the cursor blinks slightly slower and TI$ will lag behind as well.
when stopping while the border is flashed (very unlikely but possible), it stays white -- you have to restore it manually.

It´s not totally independent, is it? I see two absolute LDAs and two STAs. Great work nonetheless!

Damn you're right :o I forgot the self modification! I'll update as soon as I'm on the PC.

@Titus fixed ... and just for fun, added a "better" variant :)

Have you considered packing the sprite? (Hmm ... use the charset ROM?) And I´d prefer inc $d020 over jsr flash ;) hitshimselfwithalargetrout It´s marvellous!

@Titus hehe thanks, and I really thought about copying the ball from the charset, but I wanted a big ball :D Packing might work ... using it in place takes 65 bytes right now (63 for the sprite and 2 padding bytes to align it), so maybe it's possible to have packed data + depacking routine in fewer than 65 bytes.

@Titus several attempts later ... I guess it's impossible to create the sprite from fewer than 65 bytes :) But feel free to try yourself ;)

@Titus yes, OS routines for numbers are often useless, they all operate on floats... That's why I implemented my own "double-dabble" routines in this answer :)

Ok, probably no way to golf with packing. But You could put the sprite in front and run with SYS 49215. Btw I don´t think that the code starts with its own address?

@Titus would save 2 bytes, yes. As for the load address, it's part of a valid .prg file and from my meta question here I take I have to include it ... could probably leave it out if the code was position independent.

I´m not 100% sure, but I think it should work well without initializing the position. (Where is that done anyway?) And why do you copy from $0400 to $0400? Remains of an earlier version?

@Titus there's very little initialization, but the whole code up to the start label could be dropped if you don't need a clean exit. I consider my character version the code-golf entry, this sprite version was just for fun ;) The loop copying to the same address is for copying the character rom (it switches banks) --- that's absolutely necessary for leaving the system running because the character rom isn't mapped into VIC bank #3 (from $c000).

I know it´s fun; but it´s still fun to golf it down. Loading to the 1st bank would save a bit, but occupy the BASIC RAM. Relocating the BASIC RAM to $0a00 would be an option, but corrupt any prog that´s already loaded, while it´s totally unobtrusive the way it is. Fragile version: load it to $0400 :D

@Titus yes, this was the point ... the only "unobtrusive" (to BASIC) way is to use VIC bank #3 (any other VIC bank overlaps with RAM usable from BASIC), so I did it ... and it still affects TI$ because the IRQ frequency isn't exactly the same when synchronized to the VIC (vblank = rasterline #0) as opposed to the default CIA1 timer, but the difference is very small :)

Bash + Unix utilities, 125 117 bytes
for((x=y=u=v=1;;x+=u,y+=v,u=(x<1||x>=`tput cols`-1)?-u:u,v=(y<1||y>=`tput lines`-1)?-v:v)){
tput cup $y $x
sleep .1
}

Animation of sample run:

It hit the exact corner! :O

CP-1610 assembly, 67 … 64 62 DECLEs = 78 bytes
This code is intended to be run on an Intellivision. It's using one of its hardware sprites, known as a MOB (for Mobile Object).
A CP-1610 opcode is encoded with a 10-bit value, known as a 'DECLE'. This program is 62 DECLEs long, starting at $4800 and ending at $483D.
Hexadecimal dump + source
                            ROMW  10            ; use 10-bit ROM
                            ORG   $4800         ; start program at address $4800

                    FRAME   EQU   $17E          ; frame #

                            ;; ------------------------------------------------ ;;
                            ;;  main entry point                                ;;
                            ;; ------------------------------------------------ ;;
                    main    PROC

4800 0001                   SDBD                ; load Interrupt Service Routine
4801 02B8 002B 0048         MVII  #isr,   R0    ; into R0

4804 0240 0100              MVO   R0,     $100  ; update ISR
4806 0040                   SWAP  R0
4807 0240 0101              MVO   R0,     $101

4809 02B9 0208              MVII  #$0208, R1    ; initialize R1 = X
480B 02BA 0108              MVII  #$0108, R2    ; initialize R2 = Y
480D 02BB 0001              MVII  #1,     R3    ; initialize R3 = DX
480F 009C                   MOVR  R3,     R4    ; initialize R4 = DY

4810 0002                   EIS                 ; enable interrupts

                            ;; ------------------------------------------------ ;;
                            ;;  main loop                                       ;;
                            ;; ------------------------------------------------ ;;
4811 0280 017E      @@loop  MVI   FRAME,  R0    ; R0 = current frame #

4813 0340 017E      @@spin  CMP   FRAME,  R0    ; wait for next frame
4815 0224 0003              BEQ   @@spin

4817 00D9                   ADDR  R3,     R1    ; X += DX

4818 0379 02A0              CMPI  #$2A0,  R1    ; reached right border?
481A 0204 0003              BEQ   @@updDx

481C 0379 0208              CMPI  #$208,  R1    ; reached left border?
481E 002F                   ADCR  PC

481F 0023           @@updDx NEGR  R3            ; DX = -DX

4820 00E2                   ADDR  R4,     R2    ; Y += DY

4821 037A 0160              CMPI  #$160,  R2    ; reached bottom border?
4823 0204 0003              BEQ   @@updDy

4825 037A 0108              CMPI  #$108,  R2    ; reached top border?
4827 002F                   ADCR  PC

4828 0024           @@updDy NEGR  R4            ; DY = -DY

4829 0220 0019              B     @@loop        ; loop forever

                            ENDP

                            ;; ------------------------------------------------ ;;
                            ;;  ISR                                             ;;
                            ;; ------------------------------------------------ ;;
                    isr     PROC

482B 01DB                   CLRR  R3            ; clear a bunch of STIC registers
482C 02BC 0020              MVII  #$20,   R4

482E 0263           @@clear MVO@  R3,     R4    ; (including background color,
482F 037C 0032              CMPI  #$32,   R4    ; border color, etc.)
4831 0226 0004              BLE   @@clear

4833 0259                   MVO@  R1,     R3    ; update X register of MOB #0
4834 0242 0008              MVO   R2,     $8    ; update Y register of MOB #0
4836 02BB 017E              MVII  #$017E, R3    ; update A register of MOB #0
4838 0243 0010              MVO   R3,     $10   ; (using a yellow "O")

483A 0298                   MVI@  R3,     R0    ; increment frame #
483B 0008                   INCR  R0
483C 0258                   MVO@  R0,     R3

483D 00AF                   JR    R5            ; return from ISR

                            ENDP

Output

TI-BASIC, 71 70
1->A
1->B
1->C
1->D
While 1
ClrHome
Output(B,A,0
A+C->A
B+D->B
If A<2 or A>15
~C->C
If B<2 or B>7
~D->D
End

Quite literal translation, I wouldn't be surprised if there are tricks to make it smaller.
The screen is 16x8 and 1-indexed so the constants are different.
~ is the SourceCoder way to write the negation symbol.

It looks smoother on hardware.

Are you sure this is 70 bytes? It looks like less than that.

@12Me21 how many bytes do you count? I get 80 bytes if I save this on a calculator and 10 bytes for an empty program which agrees with my count.

Oh, I guess I counted wrong then.

HTML (Microsoft Edge/Internet Explorer), 81 bytes
Pretend it's 1998 with these nested <marquee> tags:

<marquee behavior=alternate direction=down><marquee behavior=alternate width=99>O

Tested in Microsoft Edge, though from what I've read IE should also still support marquees.  Decidedly does not work in Chrome.
Setting direction=up would save 2 bytes, but break the rule that the ball has to start at the top of the canvas.

Unfortunately, this is an invalid answer as the ball does not travel diagonally, as required by the challenge.

Did you try it in Microsoft Edge?  Chrome doesn't seem to support the direction attribute.

Huh, my apologies - it does work in Edge. I can confirm that it does not work in Chrome, and I can attest that it does work in Firefox and Internet Explorer. Three out of four isn't bad (and you only need one for this answer to be valid). +1

+1 for marquee, that's pretty creative!

Worked in Chrome for me.

@ckjbgames You must have a really old version of Chrome, then, considering that the marquee tag is obsolete.

@mbomb007 It only partially worked.

If it only moved horizontally, it didn't work.

Works in Firefox 56

Befunge, 209 bytes
>10120130pppp>"l52?[J2["39*,,,,39*,,,,,,v
v+56/+55\%+55:+1g01*83-"6!"7\-"6!?"8-*86<
>00g1+:55+%\55+/"+!6"-48*,68>*#8+#6:#,_v$
v:+g03g01p02+-\g02*2!-*64\*2!:p00:+g02g<$
>10p:!2*\"O"-!2*30g\-+30p"2"::**>:#->#1_^

This assumes a screen size of 80x25, but you can easily tweak the range by replacing the "O" (79) on the last line and the *64 (24) on the second last line (note that the second last line is executed right to left). The speed can also be adjusted by replacing the "2" (50) on the last line.

Java, 184 176 bytes
class A{public static void main(String[]a)throws Exception{for(int X=1,Y=1,x=1,y=1;;System.out.print("\033["+X+";"+Y+"H"),Thread.sleep(50),X+=x=X%25<1?-x:x,Y+=y=Y%85<1?-y:y);}}

This makes use of ANSI Escape Sequences to relocate the cursor, which is the object that bounces around a 85 x 25 terminal display. Save in a file named A.java.
Ungolfed
class Terminal_Bouncing_Ball {
    public static void main(String[] args) throws InterruptedException {
        int X = 0, Y = 0, dx = 1, dy = 1;
        while (true) {
            System.out.print(String.format("\033[%d;%dH",X,Y));
            Thread.sleep(50);
            dx = (X < 1) ? 1 : (X > 71) ? -1 : dx;
            dy = (Y < 1) ? 1 : (Y > 237) ? -1 : dy;
            X += dx;
            Y += dy;
        }
    }
}

Demo

This is code golf, so you'll want to remove Thread.sleep(50). And your golfed and ungolfed programs don't match.

Clojure, 398 380 375 bytes
(ns g(:require[quil.core :as q]))(def w 1e3)(def h 1e3)(def f 100)(def b(atom{:x f :y f :n 1 :m 1}))(q/defsketch . :size[w h]:setup #(do(q/text-font(q/create-font""f))(q/fill 255 255 255)):draw #(let[s 9{x :x y :y n :n m :m}@b c(+ x(* n s))u(+ y(* m s))](q/background 0 0 0)(reset! b{:x c :y u :n(if(< 0 c(- w f))n(* -1 n)):m(if(<(+ 0 f)u h)m(* -1 m))})(q/text"O"(:x @b)(:y @b))))

-18 bytes by changing the font name to an empty string to default it, inlining the boundary checks, and fixing the bottom boundary issue (which you can see in the GIF). Fixing that actually saved bytes.
-5 bytes by changing to a more succinct destructuring syntax and shrinking the ball by a pixel.
Uses Quil.
I tried to switch to functional mode, but it required a lot of extra code and ended up being more expensive.
(ns bits.golf.ball-bounce
  (:require [quil.core :as q]))

(def width 1000)
(def height 1000)

(def font-size 100)

; Mutable state holding the properties of the ball. n and m are the directions on the x and y axis.
(def ball (atom {:x 300 :y 600 :n 1 :m 1}))

(q/defsketch b
  :size [width height] ; Window size

  :setup #(do
            (q/text-font (q/create-font "Arial" font-size)) ; Set the font
            (q/fill 255 255 255)) ; And the text color

  :draw
  #(let [speed 9
         ; Deconstruct the state
         {:keys [x y n m]} @ball
         next-x (+ x (* n speed))
         next-y (+ y (* m speed))

         ; I'm adding/subtracting the font-size so it stays in the window properly
         x-inbounds? (< 0 next-x (- width font-size))
         y-inbounds? (< (+ 0 font-size) next-y height)]

     ; Wipe the screen so the ball doesn't smear
     (q/background 0 0 0)

     ; Reset the state
     (reset! ball
             {:x next-x
              :y next-y
              :n (if x-inbounds? n (* -1 n))
              :m (if y-inbounds? m (* -1 m))})

     ; Draw the ball
     (q/text "O" (:x @ball) (:y @ball))))

(Note, the new version doesn't bounce early along the bottom of the screen like it does in the GIF.)

I just realized I have (+ 0 font-size) in there. That's embarrassing. I'll fix that in the next version. Should save me like 5 bytes.

Racket 247 bytes
(let*((w 500)(h(* w 0.6))(x 100)(y 0)(d 10)(e d)(G(λ(t)(set! x(+ x d))(when(or(> x w)(< x 0))
(set! d(* d -1)))(set! y(+ y e))(when(or(> y h)(< y 0))(set! e(* e -1)))
(underlay/xy(rectangle w h"solid""white")x y(circle 10"solid""black")))))(animate G))

Ungolfed:
(require 2htdp/image
         2htdp/universe)

(let* ((wd 500)            ; define variables and their initial values
       (ht 300)
       (x 100)
       (y 0)
       (dx 10)
       (dy 10)

       (imgfn              ; define function to draw one frame; called repeatedly by animate fn;
        (λ (t)             ; t is number of ticks till now- sent by animate fn; ignored here;

                           ; update location (x and y values):
          (set! x (+ x dx))
          (when (or (> x wd) (< x 0))
            (set! dx (* dx -1)))             ; invert direction at edges
          (set! y (+ y dy))
          (when (or (> y ht) (< y 0))
            (set! dy (* dy -1)))             ; invert direction at edges

                           ; draw image:
          (underlay/xy
           (rectangle wd ht "solid" "white") ; draw background
           x y                               ; go to location (x,y)
           (circle 10 "solid" "black")       ; draw ball
          ))))

  (animate imgfn))         ; animates the images created by imgfn (default rate 28 times/sec)

Output:

Playing racquetball with Racket!

That's a good one!

"Racket" is derived from "Scheme" programming language: after Scheme (a devious plan) there is Racket (a scam or swindle)!

@mso Even better!

Simons´ BASIC (C64), 66 65 bytes
One byte saved thanks @ShaunBebbers.
I need only one line here, because Simons´ Basic has a modulo function.
AfaIk, this requires a physical C64 and a Simons´ BASIC module
(or any other BASIC extension that has a mod function).
0fori=0to623:print"{CLR}":poke1024+40*abs(mod(i,48)-24)+abs(mod(i,78)-39),81:next:goto

Type in these 69 characters:
0fOi=0TO623:?"{CLR}":pO1024+40*aB(mod(i,48)-24)+aB(mod(i,78)-39),81:nE:gO

{CLR} is PETSCII 147, which clears the screen. Use Shift+CLR/HOME to type it in.
bytecount
When saved to disk, it takes 65 bytes, because the commands are tokenized:
for, to, poke, abs, next and goto are one byte each; mod takes two bytes.
That makes 59 bytes of code plus 4 bytes for pointers and 2 bytes for the line number.
For reference, see Mapping the C64 and search for $800 (BASIC Program Text).
(You can find the Video Screen Memory Area at $400.)
breakdown
The program loops I from 0 to 623 (=LCM of 48 and 78 minus 1). In the loop

the screen is cleared
I gets mapped to 39..0..38 respectively 24..0..23
and the blob (PETSCII 81) is put at the corresponding position in the video memory
(like the original program does).

When the loop is done, the program is restarted by jumping to line 0.
C64 BASIC, 77 76 bytes
0fori=0to623:print"{CLR}"
1poke1024+40*abs(i-48*int(i/48)-24)+abs(i-78*int(i/78)-39),81:next:goto

Unfortunately I need two lines, because even with all possible abbreviations it would take 83 characters - too many to use the C64 line editor:
0fOi=0to623:?"{CLR}":pO1024+40*aB(i-48*int(i/48)-24)+aB(i-78*int(i/78)-39),81:nE:gO

(A hex editor could be used to create a longer line - which would make it 73 bytes.)

Commodore command separators are : and not ;

Also if you start at line zero, you can simply use goto in your two-liner version, as goto without a number assumes goto 0 on BASIC 2

If you want to get more commands on your C64 BASIC listing, enter it into a C128 in 128 mode, save it to disk and load it back into C64 mode, the C128 has a 160 character limit by default so this barrier can be broken by using Commodore keyword abbreviations.

@ShaunBebbers nice to know. It´s been so long. I also wanted to implement this in machine code ... trying to recap on the kernel routines; not sure when I have to backup what registers; the complete kernel listing is online; I just cannot take the time to dig further. Would You like to complete this?

I was going to make a MC version, though I think submitting it to my own challenge would be over-indulgent even for me. The fastest way would be to write the byte directly to the screen from $0400 to $07e7; or use sprites. Using the Kernal with $ffd2 (output accumulator) would work as you can set the X and Y pos on the cursor easily enough (I don't remember the call for that), but you might have to avoid the last character position in case it forces a line feed.

@Titus and Shaun, MC version done, feel free to outgolf ... hehe :D I think sprites aren't an option for golfing :o

Jelly, 37 bytes
“ñc‘Ọ24ḶŒḄṖ⁸ị⁷x⁸µ80ḶŒḄṖ⁸ị⁶x⁸‘œS.1
Ç1¿

With some help from this answer for getting the loop and escape characters right. Currently it bounces around in a 80x24 screen, but that can be easily modified in the code.
The coördinates in each direction can be represented as elements of two lists [0, 1,..., 24, 23,..., 1] and [0, 1,..., 80, 79,..., 1], let's call them Y and X, that are infinitely repeated. This infinite repetition can be emulated using modular indexing -- using ị in Jelly. Example: in the ith iteration the ball is at position (X[i%|X|], Y[i%|Y|]) = (iịY, iịX). The moving ball is just the cursor that is put into position by emitting iịY newlines and iịX spaces.
Demo

Explanation
“ñc‘Ọ24ḶŒḄṖ⁸ị⁷x⁸µ80ḶŒḄṖ⁸ị⁶x⁸‘œS.1        Monadic helper link - argument i.
                                         Resets the terminal, prints Y[i] newlines,
                                         X[i] spaces and returns i + 1.
“ñc‘                                     Set the output to [27, 99]
    Ọ                                    Convert to characters and print (\x1bc)
                                          -> Cursor is at position (0,0)
     24Ḷ                                 Lowered range of 24. Yields [0,...,23].
        ŒḄ                               Bounce. Yields [0,...,23,22,...,0].
          Ṗ                              Pop. Yields [0,...,23,22,...,1] = Y.
           ⁸ị                            Modular index i (⁸) into Y. The current
                                         value is the Y coordinate, y.
              x                          Repeat y times
             ⁷                           the newline character ('\n').
               ⁸                         Output that (y times '\n') and continue
                                         with value i.
                                          -> Cursor is at position (0, y)
                µ                        Monadic chain separation.
                 80ḶŒḄṖ                  Same as above, but this time yielding X.
                       ⁸ị                Modular index i into X, yielding the
                                         value for x.
                          x              Repeat x times
                         ⁶               the whitespace character.
                           ⁸             Output that (x times ' ') and continue
                                         with value i.
                                         -> Cursor is at position (x, y), the
                                            final position.
                             œS.1        Wait 0.1 seconds.
                            ‘            Return i + 1.

Ç1¿                                      Main (niladic) link.
 1¿                                      While true.
Ç                                        Call the helper link. The first time
                                         there is no argument and i will be [],
                                         which is cast to 0 when used as integer
                                         (e.g. try ‘¶Ç). After that, the previous
                                         return value (i + 1) is used.

Dyalog APL, 44 bytes
{⎕SM∘←0,G←⍺+⍵⋄G∇⍵×1-2×⊃1 G∨.≥G⎕SD⊣⎕DL.1}⍨1 1

Explanation:

{...}⍨1 1: call the given function with ⍺=⍵=1 1

⎕SM∘←0,G←⍺+⍵: store ⍺+⍵ in G, display a 0 at that location in the ⎕SM window.
⎕DL.1: wait 1/10th of a second
⊃1 G∨.≥G⎕SD: check if G is at the ⎕SM window boundary (1≥G or G≥⎕SD, ⎕SD is the screen dimensions)
1-2×: map [1,0] onto [¯1,1], to flip the direction of travel
⍵×: multiply the current direction of travel by that
G∇: recursion, let G be the new location (⍺) and ⍵.... be the new direction (⍵).

Is this supposed to continuously open and close terminals as it runs? It's quite difficult to stop this from running once it's started, as the terminal closes and reopens every tenth of a second (at least on Windows).

@wptreanor: fixed

cool, excellent work!

SmileBASIC, 85 74 bytes
SPSET.,9M=MAINCNT
SPOFS.,ASIN(SIN(M/5))*122+192,112+71*ASIN(SIN(M/3))EXEC.

The position of the ball can be modelled with 2 triangle waves, and the shortest way I could find to produce them in SmileBASIC was arcsine(sine(x)). (the algorithm using MOD was longer since SB uses MOD instead of %)

PHP, 112 97 94 103 102 bytes
for(;;usleep(1e5),$i%=624)echo($r=str_repeat)(A^K,99),$r(A^a,abs($i%78-39)),O,$r(A^K,abs($i++%48-24));

bounces a capital O on a 40x25 grid, starting at the top right corner;
prints 99 newlines to clear the screen.
Run with -nr.
A^K = chr(10) = newline
A^a = chr(32) = space

Hi Titus it's me again. for($d=$e=-1;;usleep(1e5))echo($r=str_repeat)(A^K,99),$r(A^a,$x+=$d*=$x%79?1:-1),O,$r(A^K,$y+=$e*=$y%24?1:-1);. The modulo is false at 0 and N and reverts the direction. Sadly we have to init $d and $e to -1 but still get some savings. $x%79<=>.5 also works for the same bytes.

Hey @Christoph welcome back. Strange: when I copied Your stuff it had 116 bytes instead of 110. But it inspired me to something a lot shorter.

We're definitely a good team ;) Strange thing on the copying I've got no idea why.

CSS/HTML, 200 + 7 = 207 bytes

p{position:relative}a{position:absolute;animation:infinite linear alternate;animation-name:x,y;animation-duration:7.9s,2.3s}@keyframes x{from{left:0}to{left:79ch}}@keyframes y{from{top:0}to{top:24em}}
<p><a>O

This version shows you the size of the canvas and also gives the animation a more pixilated feel:

p {
  position: relative;
  width: 80ch;
  height: 25em;
  border: 1px solid black;
}
a {
  position: absolute;
  animation: infinite alternate;
  animation-name: x, y;
  animation-duration: 7.9s, 2.3s;
  animation-timing-function: steps(79), steps(23);
}
@keyframes x {
  from {
    left: 0;
  } to {
    left: 79ch;
  }
}
@keyframes y {
  from {
    top: 0;
  } to {
    top: 24em;
  }
}
<p><a>O</a></p>

C + curses, 190 bytes
#include<curses.h>
w;h;x;y;d;main(e){initscr();curs_set(0);getmaxyx(stdscr,h,w);for(d=e;;usleep(20000),mvaddch(y,x,32)){mvaddch(y+=d,x+=e,48);if(!y||y>h-2)d=-d;if(!x||x>w-2)e=-e;refresh();}}

Explanation:
#include<curses.h>
w;h;x;y;d;
main(e)
{
    initscr();
    curs_set(0);
    getmaxyx(stdscr,h,w);

    // initialize distances to 1 (e is 1 when called without arguments)
    // wait for 1/5 second, then write space character at current pos
    for(d=e;;usleep(20000),mvaddch(y,x,32))
    {
        // advance current pos and write ball character (`0`)
        mvaddch(y+=d,x+=e,48);

        // check and change direction:
        if(!y||y>h-2)d=-d;
        if(!x||x>w-2)e=-e;

        // trigger output to screen:
        refresh();
    }
}

QBasic, 71 bytes
DO
CLS
LOCATE 24-ABS(i MOD 46-23),80-ABS(i MOD 158-79)
?"O";
i=i+1
LOOP

This version loops forever, although it might break when i gets too large--I haven't tested. Also, how fast it moves depends on the hardware you use, but on the emulator at Archive.org it runs too fast to see the motion. Therefore, here's a somewhat friendlier version that terminates once the ball gets back to the top left corner:
FOR i=0TO 3634
CLS
LOCATE 24-ABS(i MOD 46-23),80-ABS(i MOD 158-79)
?"O";
z=COS(1)
NEXT

Change the COS(1) to COS(1)+COS(1)+COS(1) (etc.) to slow it down further. Try it here!
Explanation
Our bounding box is QBasic's standard text mode screen, 80 characters wide by 24 characters tall, 1-indexed. As several other answers have observed, we can calculate the correct x and y coordinates, given a frame number, using modular arithmetic:

Frame i
i MOD 46
(i MOD 46)-23
ABS((i MOD 46)-23)
y = 24-ABS(...)
x = 80-ABS(...)

0
0
-23
23
1
1

1
1
-22
22
2
2

22
22
-1
1
23
23

23
23
0
0
24
24

24
24
1
1
23
25

45
45
22
22
2
46

46
0
-23
23
1
47

47
1
-22
22
2
48

79
33
10
10
14
80

80
34
11
11
13
79

After that it's just an issue of clearing the screen with CLS, moving to the proper coordinates with LOCATE, and printing "O".

MATL, 42 bytes
1thXH_XI`Xx8E70hZ"79HZ}&(DH4M\1>EqI*XIH+XH

This uses a 70×16 screen and character O. If you wait for a few bounces you'll see the ball hitting a corner.
Try at MATL Online!
Screen size can be easily modified in the code. The relevant part is 8E70, which pushes 8, doubles it, and pushes 70. For example, for a 80×25 screen replace by 5W80, which pushes 5, squares it, and pushes 80 (or replace by 25 80, but that requires one more byte).
Also, adding tD at the end of the code shows the current position in real time (vertical, then horizontal, 1 1 is upper left). As an example, for a 80×18 screen,
1thXH_XI`Xx9E80hZ"79HZ}&(DH4M\1>EqI*XIH+XHtD

Try it too!
Explanation
This uses an infinite loop. Position is kept in clipboard H as a 1×2 vector, and direction is kept in clipboard I as a 1×2 vector with entries 1 or -1.
Each iteration clears the screen, defines a matrix of spaces, writes an O at the relevant position, and displays it. Then the position and directio need to be updated.
Position is 1-based, and thus the edges of the screen are 1 and the maximum screen size. So if position modulo screen size gives 0 or 1 in either the first or second components, which means we have reached a vertical or horizontal edge respectively, that component of the direction vector is negated. After that, the new direction is added to the current position to obtain the new position.

C 294 bytes
#include<graphics.h> f(){int d=0;g,x,y,a=0,b=0;initgraph(&d,&g,NULL);x=30;y=30;while(1){x+=6;y+=7;if(y<60)b=0;if(x<60)a=0;if((y>getmaxy()-40)) b=!b;if((x>getmaxx()-40))a=!a;if(b){y-=18;x+=3;}if(a){x-=15;y+=2;}usleep(10000);setcolor(4);cleardevice();circle(x, y,30);floodfill(x,y,4);delay(45);}}

Ungolfed version:
#include<graphics.h>
void f()
{
 int d=DETECT,g,x,y,r=30,a=0,b=0;
 initgraph(&d,&g,NULL);
 x=30;
 y=30;

 while(1)
 {
   x+=6;
   y+=7;

   if(y<60)
     b=0;
   if(x<60)
     a=0;

   if((y>getmaxy()-40))
        b=!b;

   if((x>getmaxx()-40))
        a=!a;

    if(b)
    {
        y-=18;
        x+=3;
    }

    if(a)
    {
       x-=15;
       y+=2;
    }
    usleep(10000);
    setcolor(RED);
    cleardevice();
    circle(x,y,r);
    floodfill(x,y,RED);
    delay(45);

  }

}

Explanation

So in order to begin with this, I had to get graphics.h in my /usr/include directory. Therefore, i searched and this is what I found. It is a TurboC Graphics implementation using SDL for Linux. One could also use OpenGL. In windows, I guess it is already installed, not sure about MacOS.
void initgraph(int *graphdriver, int *graphmode, char *pathtodriver); initialises the system and puts it in a graphics mode, in this case graphics driver is automatically detected. Please refer to this link for more details.
x and y are coordinates that determines the ball's position.
a and b are flags, a is set to zero when the x value drops below 60 and b is set to zero when y drops below 60.
The flags are toggled when x and y exceeds boundary values of window, and the coordinates are accordingly adjusted.
I put a usleep so that my CPU does not get stressed out.
One should normally use a closegraph() call, in order to close the window. But it's missing here.

Must be compiled with the linker flag -lgraph
It runs smoother on real hardware. :)

Are import statements necessary to run this program?

@KritixiLithos Yes sir; Updated! you need to include graphics.h. This answer http://askubuntu.com/questions/525051/how-do-i-use-graphics-h-in-ubuntu was helpful.

Python 2, 176 168 Bytes
This assumes a terminal size of 80x24. Definitely not optimal but I'm new to golfing so yeah.
import time;x=y=d=e=1
while 1:
 m=[[' 'for i in' '*80]for j in' '*24];x+=d;y+=e;m[y][x]='O';time.sleep(.1)
 if x%79<1:d=-d
 if y%23<1:e=-e
 for r in m:print''.join(r)

Thanks to R. Kap for suggesting the x%79<1 instead of x<1or x>79 and ditto for y.

You can save a few bytes by replacing x<1or x>78 with x%79<0 and y<1or y>22 with y%23<1.

Rebol/View, 284 266 bytes
rebol[]p: 3x9 d:[3 3]view layout[b: box blue 99x99 effect[draw[circle p 2]]rate :0.01 feel[engage: func[f a e][if a = 'time[case/all[p/x < 2[d/1: abs d/1]p/y < 2[d/2: abs d/2]p/x > 98[d/1: negate d/1]p/y > 98[d/2: negate d/2]]p/x: p/x + d/1 p/y: p/y + d/2 show b]]]]

Ungolfed:
rebol []

p: 3x9     ;; starting position
d: [3 3]   ;; direction

view layout [
    b: box blue 99x99 effect [
        draw [
            circle p 2
        ]
    ]

    rate :0.01 feel [
        engage: func [f a e] [
            if a = 'time [
                case/all [
                    p/x < 2  [d/1: abs d/1]
                    p/y < 2  [d/2: abs d/2]
                    p/x > 98 [d/1: negate d/1]
                    p/y > 98 [d/2: negate d/2]
                ]
                p/x: p/x + d/1
                p/y: p/y + d/2
                show b
            ]
        ]
    ]
]

Here's the ZX Spectrum listing.
  10 FOR n=0 to 7
  20 READ a: POKE USR "a"+n, a
  30 NEXT n
  40 DATA 60,126,243,251,255,255,126,60
  50 LET x=10:LET y=10:LET vx=1: LET vy=1
  60 PRINT AT y,x;"\a"
  70 IF x<1 OR x>30 THEN LET vx=-vx
  80 IF y<1 OR x>20 THEN LET vy=-vy
  90 LET x=x+vx: LET y=y+vy
 100 PRINT AT y-vy,x-vx;" ": GO TO 60

Nice first entry DrlB - could you please include a byte count. I assume this will work on any Speccy including 16K machines?

Hi this is 201 bytes, you could omit the first 4 lines but then you get just a bouncing "a" character but it saves you 64 bytes. I will try to optimize. This nothing fancy  at all and will work on any Spectrum model :)

Ok I've managed to cut it down to 185 by condensing the lines a bit without dropping the ball graphics. It's a bit less readable  though but it's faster.

CHIP-8, 36 34 28 bytes
FF29 'LDF I,vF //load digit sprite for the value of vF (should be 0)

4000 'SNE v0,0 //if x is 0...
6201 'LD v2,1 //set x velocity to 1
403C 'SNE v0,3C //if x is 3C...
62FF 'LD v2,FF //set x velocity to -1
4100 'SNE v1,0 //if y is 0...
6301 'LD v3,1 //set y velocity to 1
411B 'SNE v1,1B //if y is 1B...
63FF 'LD v3,FF //set y velocity to -1

D015 'DRW v0,v1,5 //draw sprite
D015 'DRW v0,v1,5 //draw sprite again to clear it.
8024 'ADD v0,v2 //add x velocity to x
8134 'ADD v1,v3 //add y velocity to y

1202 'JMP 202 //jump to second instruction

No fancy tricks here...
Requires an interpreter that draws sprites correctly (only one sprite can be drawn per frame, which slows down the program enough for you to be able to see it).
Low quality video

Lua (LÖVE 2D), 130 bytes
x,y,a,b=0,0,1,1
function love.draw()a=(x<0 or x>800)and-a or a
b=(y<0 or y>600)and-b or b
x=x+a
y=y+b
love.graphics.points(x,y)end

Lua is not the best language when it comes to code golf, but here you go! A few points worth mentioning:

The default canvas size is 800 x 600. It can be changed in the configuration file, but I didn't see any size restrictions, so I left it as is.
love.draw() is LÖVE's drawing function and it has a predetermined name. Alternative LÖVE functions that could be used would be love.update(dt) and love.run() -- the first being longer, in bytes, and the latter being shorter, yes, but without a built-in infinite loop. Thus, draw() seems to be our best bet here.
The above version uses love.graphics.points to draw the ball. Although shorter, I am not sure it is allowed. Here is a GIF of how it runs:

As you can see (or perhaps can't), there is a single pixel moving on the screen. While that saves up bytes, it's not the most satisfying of results.
So I've made an alternative 131 bytes solution:
x,y,a,b=0,0,1,1
function love.draw()a=(x<0 or x>795)and-a or a
b=(y<0 or y>595)and-b or b
x=x+a
y=y+b
love.graphics.print(0,x,y)end

This one uses love.graphics.print -- which prints text -- and a 0 as a ball, making it much more visible and appealing.

PostScript (GhostScript), 259 bytes
I don't think PostScript was built for animation... improvements welcome!
[/x{4}/y{196}/X{2}/Y{-2}/b{x y 4 currentgray add 0 360 arc fill}/p{/x x X add def}/q{/y y Y add def}/g{setgray}>>begin[/PageSize[320 200]>>setpagedevice{1 g
b p q
x 316 gt x 4 lt or{/X X -1 mul def}if
y 196 gt y 4 lt or{/Y Y -1 mul def}if
0 g b flushpage}loop

Needs GhostScript for flushpage.

(It runs smoother when the screen recorder isn't also running.)

Commodore C64 BASIC - 75 71 tokenised BASIC bytes, 77 73 characters with keyword abbreviations
The following answer is taken from the YouTube channel 8-BIT Show and Tell, so Robin Harbron deserves the credit, along with credit to the YouTube channel JosipRetroBits.
 0?"{CLEAR}":DEFFNA(B)=ABS(T-INT(T/B)*B-B/2):POKE1024+FNA(48)*40+FNA(78),81:T=T+1:GOTO

Older solution
 0?"{CLEAR}":DEFFNA(B)=ABS(T-INT(T/B)*B-B/2):Z=1024+FNA(48)*40+FNA(78):POKEZ,81:T=T+1:GOTO

The listing is above one logical (Commodore C64) line in Commodore BASIC, so it must be typed with keyword abbreviations, as in the screen shot below.
A full explanation of what is going on is linked above.

ZX Spectrum BASIC - 179 bytes
Here it is just condensed a little bit. It's 179 bytes with the ball graphics included
  10 LET a=10: LET b=10: LET c=1: LET d=-1: FOR e=0 TO 7: READ f: POKE USR "a"+e, f: NEXT e
  20 DATA 60, 126,243,251,255,255,126,60
  30 PRINT AT b,a;"\a"
  40 IF a<1 OR a>30 THEN LET c=-c
  50 IF b<1 OR b>20 THEN LET d=-d
  60 LET a=a+c: LET b=b+d: PRINT AT b-d, a-c;" ": GO TO 30

Please look at the mark-up used for answers, also by using the character o or O you may be able to save some bytes in the symbolic listing; you are also able to edit previous answers when you have improved solutions, rather than re-answering the same question

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Accessories after the fact!
This challenge is inspired by Mathematics is fact. Programming is not.

The mathematical notation for a factorial, or a fact is an exclamation mark !. The exclamation mark is also a common symbol for not in many programming languages.
Challenge:
Take a string, containing numerals, and the characters: + ! as input and output the following:
Everything in front of an exclamation mark should be evaluated as a mathematical expression, so 2+2 would be 4.
Everything after a single exclamation mark should be appended as accessories to whatever is in front of it, so: 2+2!5 should give 45, because 2+2=4, and 5 is an accessory. 2+2!5+5 should give 410.
Since ! also means not, anything that's not an accessory after the fact should not be appended. So, 2+2!!5 should give 4, since 5 is not an accessory. Now, not(not(true))==true, so 2+2!!!5 should give 45. 2+2!!5!5+5 should give: 410, because 2+2=4, then followed by a factorial and !5!5+5. The first 5 is not a fact, but 5+5 is after another exclamation mark, and is therefore a fact, yet again.
Clarifications:

The exclamation marks will not be adjacent to a + on either side.
There will not be leading + for numbers (it's 5, not +5).
You may optionally include a leading zero if that's the result of the expression in front of the first !. Both 4 and 04 are accepted output for input: 0+0!4

Executive summary: evaluate each sum (treating ! as separators). Then discard all numbers that appear after an even number of ! (counting from the start of the string). Then remove all !.
Test cases:
!
   <- Empty string

5
5

12!
12

!87
87

!!5
   <- Empty string

5+5!2+2
104

5+5!!2+2
10

1!2!3!4!5!6!7!8!9
12468

10+10!!2+2!!3+3!4+4
208

2!!3!5
25

2!!3!5!7
25

10!!!!!!!5
105

This is code-golf so the shortest code in bytes (in each language) wins! Explanations are strongly encouraged!

umm...lets say we have 2!!3!5 here is or is not 5 an accessory of 3?

@officialaimm It's 25 (see added test case). More importantly 2!!3!5!7 would still give 25, because there's an even number of ! left of the 7 (so you don't just count the run right in front of the number, but all the ! left of it).

Can the output be a Mathematica Row?

Um... so this challenge actually has nothing to do with factorials?

Retina, 35 31 29 bytes
Saved 4 bytes by taking some inspiration from ETHproductions.
Thanks to Leo for saving another 2 bytes.
\d+|\+
$*
1+
$.&
1`!

!\d*!?

Try it online!

You can save some bytes in the last lines like this

@Leo That's really neat, thank you. :)

JavaScript (ES6), 58 56 bytes
Saved two bytes thanks to Martin Ender.

let f =
x=>x.replace(/[^!]+/g,eval).replace(/!(\d*)!?\d*/g,"$1")
<input value="2+2!5+5" oninput="try{O.value=f(value)}catch(e){}"><br>
<input id=O value="410" disabled>

Might be improved somehow...

Nice use of function argument to replace.

@Neil Thanks, but I found a better way :-)

Your code snippet is giving me the wrong answer on 1+1!5. I think you forgot to eval the bit before the !.

@ValueInk Ah darn, I don't think there's any easy way to fix that.

Jelly, 18 bytes
ṣ”!µḊm2;@ḢW$LÐfVṾ€

Try it online!
How?
ṣ”!µḊm2;@ḢW$LÐfVṾ€ - Main link: string
ṣ”!                - split on '!' characters
   µ               - monadic chain separation (call that x)      e.g. ['1+1','0+0','0+0','0+0','','1+0','','','']
    Ḋ              - dequeue x (all but the leftmost entry of x) e.g.       ['0+0','0+0','0+0','','1+0','','','']
     m2            - modulo 2 index into that result             e.g.       ['0+0',      '0+0',   '1+0',   '']
           $       - last two links as a monad
         Ḣ         -     head x (the leftmost entry of x)        e.g.  '1+1'
          W        -     wrap                                    e.g. ['1+1']
       ;@          - concatenate with reversed arguments         e.g. ['1+1','0+0',      '0+0',   '1+0',   '']
             Ðf    - filter keep:
            L      -     length (keep that have non-zero length) e.g. ['1+1','0+0',      '0+0',   '1+0']
               V   - eval as jelly code (vectorises)             e.g. [  2,    0,          0,       1]
                      Yes, addition is just + and decimal numbers are just strings of digits in Jelly believe it or not!
                Ṿ€ - uneval €ach (creates a string from each one)e.g. [ '2',  '0',        '0'     ,'1']
                      without the € it would uneval the list and hence yield commas too)
                   - implicit print (prints the resulting list [of characters and possibly
                      lists of characters] as if it were all one string.)

I don't think this works for literal 0+0 in the middle of the input (in a place where it isn't being discarded); it produces the null string, even though it should produce a digit 0.

Ah, true - I will have to move to a longer solution :(

Should be fixed up (possibly golfable now).

Jelly, 16 bytes
ṣ”!µḢW;m2$VṾ$L¡€

Try it online!
Explanation
The key observation here is that we can run the steps "out of order"; instead of evaluating the sums then ignoring the ones we don't like, we can ignore the sums in invalid positions, then evaluate the rest.
ṣ”!µḢW;m2$VṾ$L¡€
ṣ”!                Split input on '!'
   µ               Set as the new default for missing arguments
    Ḣ              Take the first element, removing it from the default
     W;  $         Cons with
       m2            every odd-numbered element of {the tail of the !-split input}
               €   For each remaining element
          VṾ$      Evaluate and de-evaluate it
             L¡      a number of times equal to its length

Evaluating a sum like "10+10" will evaluate it to a number, e.g. 20, then de-evaluate it to a string, "20". Repeating that process has no additional effect (it's idempotent). Thus, we effectively evaluate every element of the string, except the null string, which remains unevaluated because it has a zero length.

That's a great trick to conditionally evaluate each item. Could you somehow take the logical AND of each item and its eval-deval'd value? (I assume the empty string is falsy in Jelly)

@ETHproductions: Jelly's tacitness makes it unlikely that that would save bytes; it prefers to avoid using the same value twice if possible, and if you do want to reuse a value, you normally have to at least put an extra µ in somewhere (and µ doesn't work inside a loop, meaning that you'd need something even more verbose). I did manage to make it work, as ṣ”!µḢW;m2$ȧVṾ$$€, but it isn't any shorter (and has the characteristic pile up of dollar signs that tends to happen when you push Jelly to the edge of its ability to nest control structures.)

Python 3, 90 bytes
def f(s,e=1,r=''):
 for x in s.split('!'):
  if x:r+=str(eval(x))*e
  else:e=1-e
 return r

Try it online!

-8 thanks to 97.100.97.109
-1 thanks to Steffan

Explanation
def f(s,e=1,r=''):

Define a function, f, which takes in a string, s.
e is whether to evaluate the next expression, and r is the return string.
 for x in s.split('!'):

Iterate through the string, split by '!'s.
  if x:r+=str(eval(x))*-e

If x is not empty, and e is True, evaluate x and add to the return string.
  else:e=1-e

Otherwise, set e to not e
 return r

Return the final value of r

Python 3.8+, 74 bytes
lambda s,e=1:''.join(e*str(eval(x))for x in s.split('!')if x or(e:=1-e)*0)

(Suggested by 97.100.91.109)
Attempt this online!

91 bytes -- could probably be shortened with some recursion

90 bytes with a simple golf

74 bytes

CJam, 20 bytes
r'!/{_{'+/1b}&}%(\2%

Try it online! (Linefeed-separated test suite.)

Ruby, 58 56+1 = 59 57 bytes
Uses the -p flag. -2 bytes from Tutleman.
i=0;$_=' '+$_;gsub(/!?([^!]*)/){eval$1if(2>i+=1)||i%2<1}

Try it online! (An extra line of code was added so that it would take all of the input lines and print the output in different lines.)

I think you can drop the parentheses around eval$1, no?

@Tutleman huh. I don't know what problem I was having that made me add the parens (they weren't present when I started writing the program), but it seems I really can drop them.

Pip, 18 bytes
I think this is the shortest it gets... although I said that about three iterations ago too.
{VaX++v%2+!v}Ma^'!

Takes input as command-line argument. Try it online!
Explanation
                    a is 1st cmdline arg; global variable v is -1 (implicit)
              a^'!  Split a on !
{           }M      Map this function to the resulting list (note that inside function,
                    a is the function arg):
    ++v              Increment v (so that v tracks the 0-based index of the current
                     element)
       %2            We want to keep the elements where v%2 is 1...
         +!v         ... and also v=0, where v%2 is 0, but adding !v makes it 1
  aX                 String-multiply the argument by the above quantity (turning elements
                     we don't want into empty string)
 V                   Eval it (eval'ing empty string gives nil, but that's okay because
                     nil doesn't output anything)
                    Autoprint the resulting list, concatenated together (implicit)

Batch, 192 184 bytes
@echo off
set/ps=
call:c . "%s:!=" "%"
echo(%s%
exit/b
:c
set s=
if not %2=="" set/as=%2
:l
shift
shift
if "%1"=="" exit/b
if %1=="" goto l
set/at=%1
set s=%s%%t%
goto l

Having to handle the empty strings is inconvenient.

R, 95 bytes
function(x)for(e in strsplit(gsub('!([^!]*)![^!]*','\\1!',x),'!')[[1]])cat(eval(parse(text=e)))

There is probably some room for improvement but at the moment it is the best I can come up with.

Japt -P, 14 bytes
q'! kÏ©YvÃ£OxX

Try it
You can also Try all test cases, with a slight modification in the footer since the -mR flag that is used to run on multiple test cases conflicts with the -P flag that formats the output in the main version.
q'! kÏ©YvÃ£OxX
q'!            # Split the string on "!"
    k    Ã     # Remove elements where:
     Ï         #  The index is non-zero
      ©Yv      #  And the index is divisible by 2
          £    # For each remaining element:
           OxX #  Evaluate it as Javascript
-P             # Concatenate the elements and print

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Reverse Insertion sort
Objective
Generate the original scrambled list, from the movements that an Insertion Sort would do to sort it.
The original list will have all numbers from 0 to N-1(inclusive) where N is the size of the input.
Input
A list containing the necessary moves to sort the list. Each value represents the amount of slots displaced by the original (scrambled) number to be in his right position , keep in mind that this process is from the left to the right.
The value at (0-indexed) position i in the input list will be between 0 and i inclusive.
You don't need to handle invalid inputs, any behaviour is acceptable in this case (crash, infinite loop, etc).
Output
The scrambled list
Step-by-step to generate the moves
Scrambled List | Moves to sort
[4,0,2,1,3,5]  | [0, , , , , ] #4 stay in place
[4,0,2,1,3,5]  | [0,1, , , , ] #0 is moved 1 slot to the left
[0,4,2,1,3,5]  | [0,1,1, , , ] #2 is moved 1 slot
[0,2,4,1,3,5]  | [0,1,1,2, , ] #1 is moved 2 slot
[0,1,2,4,3,5]  | [0,1,1,2,1, ] #3 is moved 1 slot
[0,1,2,3,4,5]  | [0,1,1,2,1,0] #5 is in the right place already
[0,1,2,3,4,5]

So, for the input [0,1,1,2,1,0] your program need to output [4,0,2,1,3,5].
Keep in mind that the movements aren't to the position in the (final) sorted list, but in the sorted segment(the bolded section)
Test Cases
[0,0,0] -> [0,1,2]
[0,1,0,1] -> [1,0,3,2]
[0,0,0,0,0,5] -> [1,2,3,4,5,0]
[0,1,2,3] -> [3,2,1,0]
[0,1,1,1] -> [3,0,1,2]
[0,1,1,2,1,0] -> [4,0,2,1,3,5]

Winning
This is code-golf, so the shortest answer wins.

May the program also take the length of the list as input?

@mbomb007 nope.

Can we use (n-1) steps instead? The first one is unnecessary, since it's always zero.

@GB sure, as long the output is right, you can use any algorithm

Jelly, 12 bytes
L!_UÆ¡$œ?J’U

Try it online!
Explanation
We can basically see the two lists (the input and the output) as encoding an integer; the input encodes an integer in factorial base, and the output encodes an integer as a permutation. Luckily, Jelly has builtins that are already very close to both of these encodings, so it's simply a matter of writing small pieces of code to convert to an integer, then back to the other encoding.
L!_UÆ¡$œ?J’U
   U           Reverse {the input}
    Æ¡         and convert from base factorial to integer;
  _   $        subtract that from
L!             the factorial of the length of {the input};
       œ?      then take the nth permutation of
         J     [1,2,...,l], where l is the length of {the input},
          ’    subtract 1 from every elevent,
           U   and reverse it

In the case of base factorial, we can observe that the first element of the list must be 0, the second can be 0 or 1, the third must be 0/1/2, and so on. Thus, we have to reverse the input in order to get its elements into the normal writing order for base conversion.
Additionally, for the relative orders of the factorial conversion and the permutation conversion to match up with the operation that insertion sort uses, we need to make two adjustments: reversing the sequence of the permutations, and reversing the order of the output list. Reversing the output list is easy enough, needing only a U at the end of the program. To reverse the sequence of permutations, we subtract from the factorial of the input length (this works because the base factorial produces a number in the range 0 to (length!-1), whereas the permutations are numbered by Jelly from 1 to length!, producing an implicit off-by-one that cancels out the off-by-one that you normally get when subtracting a permutation index from a factorial).
Jelly, 9 bytes, in collaboration with @JonathanAllan
UÆ¡Nœ?J’U

This version of the program is very similar, but uses a different method of reversing the sequence of permutations; simply negating the input with N is enough to make œ? treat the order in reverse. Apart from that, it works identically to the previous program.
Try it online!

O_O What sorcery is this?

Oh nice - I knew my Æ¡ and œ? atoms would work for this (I had already started trying to use them for this challenge earlier - I was so close, just needed the L! in there).

Excellent code!

In fact, you can do it in 9 bytes with UÆ¡Nœ?L’U because I implemented œ? (and similar) to act modularly  (as if they were using Jelly lists). The N just indexes in with the negative value. Note: I changed J to L - this is just because given a number it makes a range under-the-hood anyway).

Mathematica, 92 bytes
Permute[Range[l=Length@#]-1,(c=Cycles@{#}&)@{}©##&@@c[i-0~Range~#[[i]]]~Table~{i,l,1,-1}]&

Pure function taking a list of nonnegative integers as input and returning a list of nonnegative integers. The above code contains a ©, which is incorrect: it's a placeholder for the 3-byte symbol U+F3DE, which Mathematica represents by a circle with a dot in it, and which represents composition of permutations.
c=Cycles@{#}& defines a function that converts a list of integers into a Cycles object representing a permutation; for example, c[{3,4}] is the transposition swapping elements 3 and 4 of a list. c[i-0~Range~#[[i]]]~Table~{i,l,1,-1}] takes the input list and generates the permutations necessary to undo the insertion sort. Then c@{}©##&@@ composes all of these permutations together, starting with the identity permutation c@{}. Finally, Permute[Range[l=Length@#]-1,...] applies this permutation to the 0-indexed list of appropriate length.

What no built-in?! Surely...

@{#}&)@{}©##&@@ looks scary.

Python 2, 79 68 bytes
Thanks to Krazor for saving 10 bytes
Thanks to TuukkaX for saving 1 byte
a=input();b=range(len(a));print[b.pop(j-a[j])for j in b[::-1]][::-1]

Works by generating the moves in reverse

Make that 66! How about: a=input();b=range(len(a));print[b.pop(j-a[j]) for j in b[::-1]][::-1]. List comprehensions ftw!

@Krazor You have a space that could be removed before for, so make that 65 I guess :D

@Krazor Turns out the list comprehension didn't quite work, but I liked the idea of using b[::-1] !

No way? I commented with mobile, maybe I mistyped something. Which part does not work? For me, it interpreted correctly and fulfilled all test cases.

@Krazor Oh whoops, no you're right. I'm the one who mistyped it while testing.

That's cool, seems like I miscounted my letters? Sorry about that. Also, how come I didn't receive any rep for the upvotes on my comment? Do things work differently over here?

@Krazor No reputation is gained from upvotes on comments.

JavaScript (ES6), 69 65 63 bytes
a=>a.reverse(b=[...a.keys()]).map(o=>+b.splice(~o,1)).reverse()

Annoyingly both input and output are in the wrong order. Edit: Saved 4 bytes thanks to @Arnauld. Saved 2 bytes thanks to @ETHproductions.

I was still trying to find a better way but you were much faster. Nice one!

You don't need i, do you?

@Arnauld Apparently not. I started by trying to understand the Python answer, and I've only just noticed that it doesn't actually use i...

Easy -2: o=>+b.splice(~o,1)

JavaScript (ES6), 73 71 bytes
Saved 2 bytes thanks to ETHproductions
m=>(a=m.map((_,i)=>j=i)).map(_=>a.splice(j,0,+a.splice(j-m[j--],1)))&&a

Test cases

let f =

m=>(a=m.map((_,i)=>j=i)).map(_=>a.splice(j,0,+a.splice(j-m[j--],1)))&&a

console.log(JSON.stringify(f([0,0,0])));       // -> [0,1,2]
console.log(JSON.stringify(f([0,1,0,1])));     // -> [1,0,3,2]
console.log(JSON.stringify(f([0,0,0,0,0,5]))); // -> [1,2,3,4,5,0]
console.log(JSON.stringify(f([0,1,2,3])));     // -> [3,2,1,0]
console.log(JSON.stringify(f([0,1,1,1])));     // -> [3,0,1,2]
console.log(JSON.stringify(f([0,1,1,2,1,0]))); // -> [4,0,2,1,3,5]

Nice way of getting the length and the range at the same time. I was gonna suggest a=m.map(_=>j++,j=0), but that's the same length and I'm sure you've already tried it.

@ETHproductions You're right: I've tried it as well. :-) (It may be worth noting that this is not equivalent: this would set j to a.length rather than a.length-1 and would require a.splice(--j,0,a.splice(j-m[j],1)[0]))

Heh, I thought of that too, but I didn't think it was worth mentioning because it's the same length

Easy -2: +a.splice(j-m[j--],1)

Haskell, 85 bytes
f x|n<-length x-1=reverse x#[n,n-1..0]
(n:r)#l=r#(take n l++drop(n+1)l)++[l!!n]
x#l=x

Try it online! Example usage: f [0,1,1,2,1,0] yields [4,0,2,1,3,5].
f x calls the function # with list x reversed and a list [length x - 1, length x - 2, ... , 0]. (n:r)#l performs the reverse insertion sort by recursively taking the nth element out of l, where l!!n yields the nth element and take n l++drop(n+1)l yields the list l with the nth element removed.

Haskell, so beautiful.

Ruby, 49 bytes
->l{(w=l.size).times{l.insert(l.shift+w-=1,w)};l}

Performs the "reverse insertion" in place inside the list, starting with the largest number.

perl, 61 bytes
@o=@p=0..@ARGV-1;splice@o,$_,0,splice@o,$_-pop,1for reverse@p

Output ends up in array @o. Example with input array as command line arguments:
perl -le'@o=@p=0..@ARGV-1;splice@o,$_,0,splice@o,$_-pop,1for reverse@p;print@o' 0 1 1 2 1 0
402135


text:
Help the grandparents find their password
Here's a scenario:
A grandmother and grandfather forget what their GMail password is. They know the word, but can't remember which letters are capitals.
The challenge is to take a word given and print(stdout) every combination of capital letters possible, essentially "brute-forcing" but only on a given string.
Example:
and  would output
and
anD
aNd
aND
And
AnD
ANd
AND

Example:
ea!  would output
ea!
Ea!
EA!
eA!

Rules

ASCII characters only
Input doesn't have to be lowercase
The order is not important
Non-alphabetic chars are left alone
Standard Loopholes apply.
Any form of input is allowed
Repetition is NOT allowed

Leaderboard Snippet:

function answersUrl(a){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+a+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(a,b){return"https://api.stackexchange.com/2.2/answers/"+b.join(";")+"/comments?page="+a+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(a){answers.push.apply(answers,a.items),answers_hash=[],answer_ids=[],a.items.forEach(function(a){a.comments=[];var b=+a.share_link.match(/\d+/);answer_ids.push(b),answers_hash[b]=a}),a.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(a){a.items.forEach(function(a){a.owner.user_id===OVERRIDE_USER&&answers_hash[a.post_id].comments.push(a)}),a.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(a){return a.owner.display_name}function process(){var a=[];answers.forEach(function(b){var c=b.body;b.comments.forEach(function(a){OVERRIDE_REG.test(a.body)&&(c="
"+a.body.replace(OVERRIDE_REG,"")+"
")});var d=c.match(SCORE_REG);d&&a.push({user:getAuthorName(b),size:+d[2],language:d[1],link:b.share_link})}),a.sort(function(a,b){var c=a.size,d=b.size;return c-d});var b={},c=1,d=null,e=1;a.forEach(function(a){a.size!=d&&(e=c),d=a.size,++c;var f=jQuery("#answer-template").html();f=f.replace("{{PLACE}}",e+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link),f=jQuery(f),jQuery("#answers").append(f);var g=a.language;/b.lang?1:a.lang<b.lang?-1:0});for(var h=0;h<f.length;++h){var i=jQuery("#language-template").html(),g=f[h];i=i.replace("{{LANGUAGE}}",g.lang).replace("{{NAME}}",g.user).replace("{{SIZE}}",g.size).replace("{{LINK}}",g.link),i=jQuery(i),jQuery("#languages").append(i)}}var QUESTION_ID=110455,OVERRIDE_USER=8478,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align: left!important; font-family: sans-serif}#answer-list,#language-list{padding: 10px; width: 290px; float: left}table thead{font-weight: 700}table td{padding: 5px; margin: 0}table tr:nth-child(even){background: #eee}
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

 	Author	Language	Size

Winners by Language

 Language	User	Score

 {{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

 {{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

You say print. Is it allowed to return the result from a function? That's usually permitted here.

Also, do the output strings have to be unique or could we print all variations of ea! twice?

Is the input guaranteed to be in lowercase?

@JungHwanMin Sorry, I was just going to update to show the current winner

@GeordieFischer When there is a better answer, you would need to deselect the previous winner's answer. No one wants to see their reputation points go up then down. Anyway, the problem is solved now, so I deleted my previous comment.

Is the input guaranteed to contain at least one letter?

I don't know what happened, but after outputting three combinations the program halted and I got an SMS, saying I had to stop... ?

Sorry for dupe.

Jelly, 7 bytes
żŒsŒpQY

Try it online!
How it works
żŒsŒpQY Main link. Argument: s (string)

 Œs     Yield s with swapped case.
ż       Zip s with the result, creating an array of character pairs.
   Œp   Take the Cartesian product.
      Y Join, separating by linefeeds.
     Q  Unique; deduplicate the result.

Bash + GNU utils, 38
eval echo `sed 's/[a-z]/{\l&,\u&}/gi'`

Try it online.
The sed expression replaces every letter with {<LOWER>,<UPPER>}, where <LOWER> and <UPPER> are respectively the lower- and upper- case versions of that letter.  These are bash brace expansions which are then expanded - the eval ensures this is the last expansion to happen.

That's clever, but it seems to break if the input contains certain special characters. Not sure if that's a problem.

@DigitalTrauma Nicely done

And the port to Perl (37 bytes) : Try it online!

MATL, 13 12 bytes
!tYohZ}&Z*Xu

Try it online!
Same idea as Dennis, only less neat, with Luis Mendo's suggestion.

JavaScript (ES6), 99 97 bytes
Returns a space-separated list of words.
f=(s,i)=>--i<1?'':s.replace(/[a-z]/gi,c=>c[`to${i&n?'Upp':'Low'}erCase`](n*=2),n=1)+' '+f(s,i||n)

Test cases

f=(s,i)=>--i<1?'':s.replace(/[a-z]/gi,c=>c[`to${i&n?'Upp':'Low'}erCase`](n*=2),n=1)+' '+f(s,i||n)

console.log(f("and"))
console.log(f("ea!"))

PHP, 115 101 99 102 101 bytes
saved 14 bytes thanks @user63956.
function f($b,$a="
"){$b&a?f($c=substr($b,1),$a.$d=$b[0])|ctype_alpha($d^=" ")&&f($c,$a.$d):print$a;}

recursive function, prints the results with a leading newline
breadown
function f($b,$a="\n")                          // $b=remaining input, $a= prepared output
{
    // while $b is not empty
    $b&a        # this is not a typo!
        // recurse with $d(=first char of $b) appended to $a
        ?f($c=substr($b,1),$a.$d=$b[0])
        // if $d is letter, recurse with $d (case toggled) appended to $a
            |ctype_alpha($d)&&f($c,$a.$d^=" ")
    // if $b is empty, print $a
    :print$a;
}

You can toggle the case of ASCII letters with ^' '  and get rid of *cfirst() calls.

Checking if the string is not empty can be written as a&$b.

Bash + Unix utilities, 95 bytes (non-recursive)
s=${1,,}$'
'
s[1]=${s^^}
for((n=${#s};z<n*2**n;)){ echo -n "${s[z/n>>z%n&1]:z++%n:1}";}|sort -u

Try it online!
Note: This solution and the recursive solution below both require bash 4; the ${x,,} and ${x^^} constructs weren't available in bash 3.
This is quite a bit longer than @DigitalTrauma's solution, but I think it works on all strings, even if they have special characters in them.  For example, with input
{a,b}

this program outputs
{A,B}
{A,b}
{a,B}
{a,b}

as it should.  (@DigitalTrauma's solution, although very ingenious, doesn't work for this input and other similar inputs.)

Bash + Unix utilities, 88 bytes (recursive)
[ "$1" ]&&(c=${1:0:1};sed "h;s/^/${c,,}/;p;g;s/^/${c^^}/"<<<`$0 "${1:1}"`|sort -u)||echo

This recursive solution works on input {a,b} but it has problems with other special characters, for example, input a/b.

JavaScript (Firefox 30-57), 92 bytes
f=([c,...a])=>c?[for(l of new Set([c.toLowerCase(),c.toUpperCase()]))for(r of f(a))l+r]:['']

Accepts a string or array of characters and returns an array of strings.

Now that this question has been marked duplicate, I've just discovered that I posted an eerily similar answer to that question...

C 247 229 bytes
i,n,j,k,l;f(char *s){l=strlen(s);for(i=0;i<l;i++)s[i]=tolower(s[i]);int v[l];for(i=0;i<pow(2,l);i++){n=i,k=0;for(;n;k++){v[k]=n;n/=2;}for(j=0;j<l;j++){v[j]%=2;if(v[j])s[j]=toupper(s[j]);else s[j]=tolower(s[j]);}printf("%s ",s);}}

Ungolfed version:
void f(char *s)
{
  int i,num,k,l=strlen(s);
  for(int i=0;i<l;i++)
     s[i]=tolower(s[i]);

   int v[l];

   for(i=0;i<pow(2,l);i++)
   {
      num=i,k=0;
      for(;num;k++)
      {
         v[k]=num;
         num/=2;
      }

      for(int j=0;j<l;j++)
      {
        v[j]%=2;
        if(v[j])
         s[j]=toupper(s[j]);
        else
         s[j]=tolower(s[j]);

      }
      printf("%s \n",s);

   }
}

Explanation:

Accept the character string, convert the string to lowercase.
Declare integer array of length equal to that of the string.
Store the numbers from 0 to 2^strlen(s)in binary form in an int array.( For a 3 byte string: 000,001,010...111)
Depending on if a bit at a position is set or, toggle the case.
Output the string for every possible combination.

Macroing strlen would save a bunch of bytes. Or better yet use while(c[i]) (you can assume that the strings are null terminated)


text:
Output Keystrokes
In any programming language, create a program that takes input and animates the text being typed on a keyboard.
The delay between each character should be varying to simulate true typing on a keyboard. The delay shall be 0.1, 0.1, 0.5, 0.1, 0.1, 0.5 ... seconds, until the last character is printed. The final output shall be left on the screen.
You must overwrite the current line of text you can't have the text be printed on new rows.
Example, the input "Hello, PPCG! Goodbye Earth!" should result in the following animation (note that the sampling rate of the gif-maker was low, so the true result is slightly different):

Since this is code golf, the smallest amount of bytes win.

"You must overwrite the current line of text you can't have the text be printed on new rows." - is this implying that the program must clear the input and produce output in it's place? (Side note: your animation looks faster than specified.)

Can we assume there is always input?

And can we exit with an error after the animation is done?

Is the delay supposed to be random, or a repeating pattern of 0.1, 0.1, 0.5?

Should there be a delay before printing the first character?

It's that pattern yes @12Me21

I'm not sure if I can time stuff that accurately on the Commodore 64 (without a SuperCPU, I might be able to with) or Sinclair ZX81, would it be okay if I don't hit these timings on that basis?

I should have added Commodore and Sinclair ZX81 BASIC - assembly would be a different beast

C 108 93 89 78 73 80 bytes
f(char *s){for(int i=0;s[i];fflush(0),usleep(100000*(i++%3?1:5)))putchar(s[i]);}

Ungolfed version:
 void f(char *s)
 {
  for( int i=0;s[i];)
  {
    putchar(s[i]);
    fflush(0);
    usleep(100000*(i++%3?1:5));
 }
}

@Kritixi Lithos  @Metoniem Thanks for your input! saved some bytes.
Somehow, just int i gave me a segmentation error on running, so I initialized it with 0.

Wether you use my improvements or not: Your delays should be the other way around. if i%3 the delay should be 5.

Replace 100000 with 1e5 to shave 3 bytes

@AlbertRenshaw Thanks for the tip, updated. I have used it in some of my other solutions too don't know why I forgot here.

@AbelTom For some reason, 1e5 doesn't work on my device

@KritixiLithos howcome? are you on Linux?

@AbelTom No, I'm on macOS

@KritixiLithos According to man usleep, the function takes unsigned int as argument, I don't even get a warning. May be compiler does the typecasting implicitly.

C only default-initialises global variables to 0, not local variables.

@Neil Thanks, did not know that, learnt something new, :) updated!

I think this is 72 bytes not 73

Also you can get down to 68 bytes by moving the putchar into your for-loop's conditional section. Will return false if there is nothing to putchar. i;f(char *s){for(;putchar(s[i]);fflush(0),usleep(1e5*(i++%3?5:1)));} Note: I could not find an online C IDe that supported usleep in the output so I wasn't able to test this and see if it works in terms of the animation, but the logic part of it did work.

1. The delays are wrong. i++%3?5:1 will return 5 twice and 1 once. It should be backwards. 2. Without including unistd.h, the compiler cannot possibly know that usleep expects an int, so it will pass a float. There is no conversion there; the byte representation of 1e5 gets used as is. 3. Per meta consensus, functions have to be reusable, so you have to reset your counter to 0.

@Dennis Thanks for the feedback! 1. I was right the first time I implemented the delay with if else. 2. I have unistd.h included, so that explains the type conversion of 1e5.If one does not have it included, then the representation should be in int format. 3.  Re-wrote the code such that i is local and initialized to 0.

The sleep times still don't seem quite right, as it should sleep 0.1 seconds after the first character, 0.5 seconds after the third. This works and it's a bit shorter. i;f(char*s){for(i=0;putchar(*s++);usleep(100000*(++i%3?1:5)))fflush();} It prints a null byte at the end, but since this challenge is about visual output, I think that's OK.

Jelly, 13 bytes
115D÷⁵ṁȮœS¥@"

This is a monadic link/function. Due to implicit output, it doesn't work as a full program.
Verification

How it works
115D÷⁵ṁȮœS¥@"  Monadic link. Argument: s (string)

115            Set the return value to 115.
   D           Decimal; yield [1, 1, 5].
    ÷⁵         Divide all three integers by 10.
      ṁ        Mold; repeat the items of [0.1, 0.1, 0.5] as many times as
               necessary to match the length of s.
          ¥@"  Combine the two links to the left into a dyadic chain and apply it
               to each element in s and the corr. element of the last return value.
       Ȯ         Print the left argument of the chain (a character of s) and sleep
                 as many seconds as the right argument indicates (0.1 or 0.5).

MATLAB, 74 bytes
c=input('');p=[1,1,5]/10;for i=c;fprintf('%s',i);p=p([2,3,1]);pause(p);end

Explanation:
I used quite a while to make the fprintf version shorter than disp() with clc. The breakthrough was when I found out / remembered that pause can take a vector as argument, in which case it will just pick the first value. This makes it possible to leave out a counter.
c=input('');    % Take input as 'Hello'
p=[.1,.1,.5];   % The various pause times

for i=c;            % For each of the characters in the input c
  fprintf('%s',i);  % Print the character i, without any trailing newline or whitespace
                    % No need to clear the screen, it will just append the new character
                    % after the existing ones
  pause(p);         % pause for p(1) seconds. If the input to pause is a vector,
                    % then it will choose the first value
  p=p([2,3,1]);     % Shift the pause times
end

The shortest I got using disp was 81 bytes:
c=input('');p=[1,1,5]/10;for i=1:nnz(c),clc;disp(c(1:i));pause(p(mod(i,3)+1));end

Can  you do printf instead of fprintf? It works on https://octave-online.net/ (but it's Octave and not Matlab)

V, 20 19 18 bytes
1 byte saved thanks to @DJMcMayhem
saved 1 byte by removing ò at the end
òD1gÓulD1gÓulDgÓul

Terribly ungolfy, I know, it's just that strict undo preventing me to use nested loops.
Explanation
The cursor starts in the beginning of the buffer, which is the first character of the input.
ò                      " Start recursion
 D                     " Deletes everything from the cursor's position to the end of line
  1gÓ                  " Sleep for 100ms
     u                 " Undo (now the deletion is reverted)
      l                " Move cursor one to the right
       D1gÓul          " Do it again
             D         " Same as before but...
              gÓ       " Sleep for 500ms this time
                ul     " Then undo and move right
                       " Implicit ò

Gif coming soon...

gÓ without a count defaults to 500 ms, so you can save a byte there. Also, remember that you don't need the second ò!

Instead of undo can you just paste?  Unsure if that helps at all though

@DJMcMayhem I don't know why I missed the default 500, thanks! But I need the second ò because otherwise the program terminates early on account of the implicit newline at the end causing a breaking error.

@nmjcman101 I was also thinking about using paste, but alas it moves the cursor to the end of the line and to go back I would need something like \`` which would only increase my bytecount further

JavaScript (ES6), 67 bytes

f=(i,o,n=0)=>i[n]&&(o.data+=i[n],setTimeout(f,++n%3?100:500,i,o,n))
<form><input id=i><button onclick=f(i.value,o.firstChild)>Go!</button>

The snippet doesn't seem to work

@KritixiLithos Yup, doesn't seem to work on Chrome :-(

works in firefox tho

It works for me in Chrome, but the console says Blocked form submission to '' because the form's frame is sandboxed and the 'allow-forms' permission is not set.

@numbermaniac I changed the snippet to use a different event. (I'm so old I can actually remember when hitting Enter in a form field didn't trigger the following button but went straight to form submission.)

MATL, 16 bytes
"@&htDTT5hX@)&Xx

Try it at MATL Online!
Explanation
"        % Implicitly input string. For each char of it
  @      %   Push current char
  &h     %   Concatenate everything so far into a string
  tD     %   Duplicate and display
  TT5h   %   Push array [1 1 5]
  X@)    %   Get the k-th element modularly, where k is current iteration.
         %   So this gives 1, 1, 5 cyclically
  &Xx    %   Pause for that many tenths of a second and clear screen
         % Implicit end. Implicitly display the final string, again (screen
         % was deleted at the end of the last iteration)

Noodel, 18 bytes
ʋ115ṡḶƙÞṡạḌ100.ṡ€ß

Try it:)

How it works
                   # Input is automatically pushed to the stack.
ʋ                  # Vectorize the string into an array of characters.
 115               # Push on the string literal "115" to be used to create the delays.
    ṡ              # Swap the two items on the stack.

     ḶƙÞṡạḌ100.ṡ€  # The main loop for the animation.
     Ḷ             # Loops the following code based off of the length of the string.
      ƙ            # Push on the current iteration's element of the character array (essentially a foreach).
       Þ           # Pop off of the stack and push to the screen.
        ṡ          # Swap the string "115" and he array of characters (this is done because need array of characters on the top for the loop to know how many times to loop)
         ạ         # Grab the next character in the string "115" (essentially a natural animation cmd that every time called on the same object will access the next item looping)
                   # Also, turns the string into an array of characters.
          Ḍ100.    # Pop the character off and convert to a number then multiply by 100 to get the correct delay. Then delay for that many ms.
               ṡ   # Swap the items again to compensate for the one earlier.
                €  # The end of the loop.

                 ß # Clears the screen such that when implicit popping of the stack occurs it will display the correct output.

19 byte code snippet that loops endlessly.

For some reason, the delay seems off. The delay is 100ms, 100ms, 500ms. You seem to have 100ms all the time.

@IsmaelMiguel Good eye. After looking through the source there is an add instead of a multiply. I might keep it that way though in case I need that because I could see where it might be useful. Thanks a lot for that!

You're welcome. And I'm sorry that your byte count increased.

@IsmaelMiguel, it's fine because when I make the next version of Noodel I can make an 11 byte solution (because of basics I need to add). It will obviously be noncompeting, but this is a new language and has a long ways to go before it is as good as some of the top golfing languages:)

C#, 131 bytes
Not much to explain. It just takes a string (wrapped in "") as argument and prints each character using the correct delay pattern. After the animation it exits with an OutOfRangeException because the loop doesn't stop after it looped over all characters. Since it's an infinite loop, that also means I can use int Main instead of void Main ;-)
Golfed
class C{static int Main(string[]a){for(int i=0;){System.Console.Write(a[0][i]);System.Threading.Thread.Sleep(i++%3<1?500:100);}}}

Ungolfed
class C
{
    static int Main(string[] a)
    {
        for (int i = 0; ;)
        {
            System.Console.Write(a[0][i]);
            System.Threading.Thread.Sleep(i++ % 3 < 1 ? 500 : 100);
        }
    }
}

Edits

Saved 1 byte by moving incrementing i inside of the Sleep() method instead of in the for loop. (Thanks Maliafo)

I'm not a C# programmer, but can't you do something like Sleep(i++ [...]) to save an extra byte in the for loop ?

@Maliafo You might be right! I'll run it to make sure if it still runs correctly and then update my post. Thanks!

APL, 23 bytes
⊢{⍞←⍺⊣⎕DL⍵÷10}¨1 1 5⍴⍨⍴

Explanation:
               1 1 5⍴⍨⍴  ⍝ repeat the values [1,1,5] to match the input length
⊢                        ⍝ the input itself
 {           }¨          ⍝ pairwise map
      ⎕DL⍵÷10            ⍝ wait ⍵÷10 seconds, where ⍵ is the number
     ⊣                   ⍝ ignore that value, and
  ⍞←⍺                    ⍝ output the character

SmileBASIC, 61 bytes
LINPUT S$FOR I=0TO LEN(S$)-1?S$[I];
WAIT 6+24*(I MOD 3>1)NEXT

I think the delay calculation could be a lot shorter.

Python 3, 83 75 bytes
import time;i=0
for c in input():i+=1;print(end=c);time.sleep(i%3and.1or.5)

Try it online!

This doesn't work on TIO. Do it here. On repl.it, you don't even need ,flush=1.

Clojure, 81 bytes
#(doseq[[c d](map vector %(cycle[100 100 500]))](Thread/sleep d)(print c)(flush))

Loops over the input string zipped with a infinite list of [100 100 500].
(defn typer [input]
  ; (map vector... is generally how you zip lists in Clojure
  (doseq [[chr delay] (map vector input (cycle [100 100 500]))]
    (Thread/sleep delay)
    (print chr) (flush)))

Bash (+utilities), 32 byte

Note, this will beep in the process, but who said submissions can not have fancy sound effects !

Golfed
sed 's/.../&\a\a\a\a/g'|pv -qL10

Demo

Powershell, 66 65 63 Bytes
[char[]]$args|%{sleep -m((1,1,5)[++$i%3]*100);Write-Host $_ -N}

-1 removed unneeded white space after -m
-2 thanks to AdmBorkBork - used 1,1,5 and * end result by 100 instead of using 100,100,500
takes $args as a char array, loops through sleeping as specified, Write-Host with the -NoNewline argument is used to write the chars out on the same line.
Improvements?

use [0..99] instead of [char[]] to save 1 byte, but wont work on strings over 100 chars.
use 100,500 and [(++$i%3)-gt1] but make it shorter somehow.
combine it into a single string and clear between outputs, eliminating the long Write-Host

can't find any way to make the last two work, and the first one isn't valid by any particular rule.

Break out the hundred to save two bytes -- sleep -m((1,1,5)[++$i%3]*100)

@AdmBorkBork smart one - thanks!

Bash + coreutils, 57 bytes
for((;k<${#1};k++)){ echo -n ${1:k:1};sleep .$[2&k%3|1];}

Java 7, 151 149 bytes
class M{public static void main(String[]a)throws Exception{int n=0;for(String c:a[0].split("")){System.out.print(c);Thread.sleep(n++%3>0?100:500);}}}

-2 bytes thanks to @KritixiLithos for something I always forget..
Explanation:
class M{
  public static void main(String[] a) throws Exception{ // throws Exception is required due to the Thread.sleep
    int n = 0;                                          // Initialize counter (and set to 0)
    for(String c : a[0].split("")){                     // Loop over the characters of the input
      System.out.print(c);                              // Print the character
      Thread.sleep(n++ % 3 > 0 ?                        // if (n modulo 3 != 0)
                                 100                    //   Use 100 ms
                               :                        // else (n modulo 3 == 0):
                                 500);                  //   Use 500 ms
    }
  }
}

Usage:
java -jar M.jar "Hello, PPCG! Goodbye Earth!"

I haven't tested it, but can you do something like a[0].split("") instead?

@KritixiLithos Argg.. I always forget that one. Thanks.

Speaking about which, I should also use split in my Processing answer...

Processing, 133 131 bytes
int i;void setup(){for(String c:String.join("",args).split(""))p{try{Thread.sleep(i++%3<1?500:100);}catch(Exception e){}print(c);}}

I tried doing args[0] and wrapping the argument in "" instead, but it does not work for some reason.
Anyways... this is the first time I've written a Processing program that takes arguments. Unlike Java, you don't need to declare the arguments using String[]args, but the variable args will automatically be initialised to the arguments.
Put it in a file called sketch_name.pde under a folder called sketch_name (yes, same name for folder and sketch).  Call it like:
processing-java --sketch=/full/path/to/sketch/folder --run input text here

Perl, 63 bytes
foreach(split//,pop){$|=++$i;print;select('','','',$i%3?.1:.5)}

Python 3, 88 Bytes
import time;s=''
for x in input():s+=x;time.sleep(.1+.4*(len(s)%3==0));print('\n'*25+s)

Rebol, 65 bytes
s: input t:[.1 .1 .5]forall s[prin s/1 wait last append t take t]

Ungolfed:
s: input
t: [.1 .1 .5]

forall s [
    prin s/1
    wait last append t take t
]