Jump to content

File:WDR paper computer performing addition.gif

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file (800 × 800 pixels, file size: 286 KB, MIME type: image/gif, looped, 19 frames, 29 s)

Summary

Description
English: An animation of the WDR paper computer running a program that performs addition (inside a Python-based emulator, see code below). At the beginning the two registers contain 5 and 4 respectively; at the end the first register contains their sum 9. This addition program is from the original German publication: [1] The Courier Prime font is used for the text. Also see File:WDR paper computer (pen and matchsticks).jpg for the pen and paper version of this program.
Deutsch: Eine Animation des Know-how-Computers, der eine Addition ausführt. Am Anfang befinden sich die Werte 5 und 4 in den beiden Registern; am Ende die Summe 9. Dieses Programm stammt aus der deutschen Erstveröffentlichung der Know-how-Computers: [2]
Date
Source Own work
Author Morn
GIF development
InfoField
 
This GIF graphic was created with Python.
Source code
InfoField

Python code

Source code
#!/usr/bin/python

# Run a simple addition program on the WDR paper computer
# and output steps as PNGs

# Create GIF animation with ImageMagick:
# convert -delay 150 wdr_step*.png -loop 0 wdr.gif

from PIL import Image, ImageDraw, ImageFont

w, h = 800, 800
fnt = ImageFont.truetype('Courier Prime.ttf', 40)

# the paper computer program to run
prog = """# Add register 2 to register 1
1 jmp 4
2 inc 1
3 dec 2
4 isz 2
5 jmp 2
6 stp"""

# set up registers
reg = 10 * [0]
reg[1] = 5
reg[2] = 4

# set up program counter
pc = 1

pp = prog.splitlines()
step = 0

while True:
    ins = pp[pc].split()
    step += 1
    print(pp[pc])
    print(step, reg)

    # create output image for current step
    im = Image.new('RGBA', (w, h), (0,0,0))
    d = ImageDraw.Draw(im)
    for n, x in enumerate(pp):
        if pc == n:
            col = (255, 255, 255)
            s = "> "
        else:
            col = (0, 255, 0)
            s = "  "
        d.text((0, 50 * n), s + pp[n], font = fnt, fill = col, align = "left")
    for n in range(1, 3):
        d.text((0, 50 * (n + len(pp) + 2)), "REGISTER %u: %u" % (n, reg[n]), font = fnt, fill = (255, 255, 0), align = "left")
    d.text((0, 50 * (n + len(pp) + 4)), "PROGRAM STEP: %u" % step, font = fnt, fill = (255, 0, 0), align = "left")
    im.save("wdr_step%04u.png" % step)

    # carry out the current instruction
    if ins[1] == "stp":
        break
    if ins[1] == "isz":
        if reg[int(ins[2])] == 0:
            pc += 2
        else:
            pc += 1
        continue
    if ins[1] == "jmp":
        pc = int(ins[2])
        continue
    if ins[1] == "inc":
        reg[int(ins[2])] += 1
    if ins[1] == "dec":
        reg[int(ins[2])] -= 1

    pc += 1

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

10 September 2021

image/gif

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current21:10, 10 September 2021Thumbnail for version as of 21:10, 10 September 2021800 × 800 (286 KB)Mornadd marker to current line
19:55, 10 September 2021Thumbnail for version as of 19:55, 10 September 2021800 × 800 (285 KB)Mornuse official mnemonics
13:26, 10 September 2021Thumbnail for version as of 13:26, 10 September 2021800 × 800 (297 KB)MornUploaded own work with UploadWizard

The following page uses this file:

Global file usage

The following other wikis use this file: