File:7segment multiplexing.gif

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

Original file(1,688 × 630 pixels, file size: 518 KB, MIME type: image/gif, looped, 61 frames, 12 s)

Summary

Description
Deutsch: Multiplexing einer 7-Segment-Anzeige.
Anzeige von "1.234" in verschiedenen Frequenzen.
Date
Source Own work
Author Laserlicht

Python code

#Path to Cairo Lib
import os
os.environ["PATH"] = r"D:\Programme\msys64\mingw64\bin" + os.pathsep + os.environ["PATH"]

import numpy as np
import drawSvg as draw

############################

#load and ransform segments
#based on Coords from here: https://commons.wikimedia.org/wiki/File:7_Segment_Display_with_Labeled_Segments.svg
seg = [ # X, Y
        [[278.759,242.759,98.759,62.759,98.759,242.759,278.759,242.759], [520.74,556.74,556.74,520.74,484.74,484.74,520.74,556.74]], #A
        [[287.759,323.759,323.759,287.759,251.759,251.759,287.759,323.759], [295.928,331.928,475.928,511.928,475.928,331.928,295.928,331.928]], #B
        [[287.759,323.759,323.759,287.759,251.759,251.759,287.759,323.759], [64.427,100.427,244.427,280.427,244.427,100.427,64.427,100.427]], #C
        [[278.759,242.759,98.759,62.759,98.759,242.759,278.759,242.759], [55.26,91.26,91.26,55.26,19.26,19.26,55.26,91.26]], #D
        [[53.758,89.759,89.759,53.758,17.758,17.758,53.758,89.759], [64.427,100.427,244.427,280.427,244.427,100.427,64.427,100.427]], #E
        [[53.758,89.758,89.758,53.758,17.758,17.758,53.758,89.758], [295.928,331.928,475.928,511.928,475.928,331.928,295.928,331.928]], #F
        [[278.759,242.759,98.759,62.759,98.759,242.759,278.759,242.759], [287.927,323.928,323.928,287.927,251.927,251.927,287.927,323.928]] #G
      ]
seg = np.array(seg)
circle = np.array([373.241, 515.74])

offs = np.array([17.758, 19.26])

circle -= offs

offs = np.repeat(offs[:, np.newaxis], 8, axis=1)
offs = np.repeat(offs[np.newaxis, :, :], 7, axis=0)

seg -= offs

scale_f = 537.48
seg /= scale_f
circle /= scale_f
circle = np.absolute(circle + np.array([0, -1]))
circle_r = 41 / scale_f

############################

seg_decoder = {
    "0": [False, True, True, True, True, True, True],
    "1": [False, False, False, False, True, True, False],
    "2": [True, False, True, True, False, True, True],
    "3": [True, False, False, True, True, True, True],
    "4": [True, True, False, False, True, True, False],
    "5": [True, True, False, True, True, False, True],
    "6": [True, True, True, True, True, False, True],
    "7": [False, False, False, False, True, True, True],
    "8": [True, True, True, True, True, True, True],
    "9": [True, True, False, True, True, True, True],
    "A": [True, True, True, False, True, True, True],
    "B": [True, True, True, True, True, False, False],
    "C": [False, True, True, True, False, False, True],
    "D": [True, False, True, True, True, True, False],
    "E": [True, True, True, True, False, False, True],
    "F": [True, True, True, False, False, False, True],
    " ": [False, False, False, False, False, False, False],
    '█': [True, True, True, True, True, True, True]
}

############################

def render(text, point, column_switch, seg_switch_draw):
    d = draw.Drawing(402, 150, origin=(0, 0), displayInline=False)
    d.append(draw.Rectangle(0, 0, 585, 150, fill='#ffffff'))

    for i in range(len(text)):
        char = text[i]

        seg1 = seg * 100

        offs = np.array([90 * i + 4 + 50, 5])
        offs = np.repeat(offs[:, np.newaxis], 8, axis=1)
        offs = np.repeat(offs[np.newaxis, :, :], 7, axis=0)
        seg1 += offs

        color_enabled = 'green'
        color_disabled = '#eeeeee'
        color_wire_disabled = 'gray'
        color_wire_enabled_p = 'red'
        color_wire_enabled_m = 'blue'

        d.append(draw.Rectangle(90 * i + 50, 0, 82, 110-0.25, fill='#cccccc', stroke='black', stroke_width=0.5))
        d.append(draw.Lines(*np.ravel(seg1[0],'F'), close=False, fill=color_enabled if seg_decoder[char][6] else color_disabled, stroke='black'))
        d.append(draw.Lines(*np.ravel(seg1[1],'F'), close=False, fill=color_enabled if seg_decoder[char][5] else color_disabled, stroke='black'))
        d.append(draw.Lines(*np.ravel(seg1[2],'F'), close=False, fill=color_enabled if seg_decoder[char][4] else color_disabled, stroke='black'))
        d.append(draw.Lines(*np.ravel(seg1[3],'F'), close=False, fill=color_enabled if seg_decoder[char][3] else color_disabled, stroke='black'))
        d.append(draw.Lines(*np.ravel(seg1[4],'F'), close=False, fill=color_enabled if seg_decoder[char][2] else color_disabled, stroke='black'))
        d.append(draw.Lines(*np.ravel(seg1[5],'F'), close=False, fill=color_enabled if seg_decoder[char][1] else color_disabled, stroke='black'))
        d.append(draw.Lines(*np.ravel(seg1[6],'F'), close=False, fill=color_enabled if seg_decoder[char][0] else color_disabled, stroke='black'))
        d.append(draw.Circle(*(circle * 100 + np.array([90 * i + 4 + 50, 5])), circle_r * 100, fill=color_enabled if point[i] else color_disabled, stroke_width=1, stroke='black'))

        d.append(draw.Text(str(i + 1), 9, 90 * i + 50 + 41 - 2, 143, fill='magenta'))
        d.append(draw.Line(90 * i + 50 + 41, 110, 90 * i + 50 + 41, 120, stroke=color_wire_enabled_m if column_switch[i] else color_wire_disabled, stroke_width=2, fill='none'))
        d.append(draw.Line(90 * i + 50 + 41, 130, 90 * i + 50 + 41, 140, stroke=color_wire_enabled_m, stroke_width=2, fill='none'))
        a = 2 if not column_switch[i] else 0
        d.append(draw.Line(90 * i + 50 + 41 - 2 - a, 118, 90 * i + 50 + 41 - 2 - a, 132, stroke=color_wire_enabled_m if column_switch[i] else color_wire_disabled, stroke_width=2, fill='none'))

        for j in range(8):
            en = (seg_decoder[text[seg_switch_draw]] + [point[seg_switch_draw]])[j]
            d.append(draw.Line(90 * i + 50, 110 / 9 * (j + 1), 90 * i + 50 - 8, 110 / 9 * (j + 1), stroke=color_wire_enabled_p if en else color_wire_disabled, stroke_width=2, fill='none'))

            if i==seg_switch_draw:
                d.append(draw.Text(["DP", "A", "B", "C", "D", "E", "F", "G"][::-1][j], 9, 7, 110 / 9 * (j + 1) - 3, fill='magenta'))
                d.append(draw.Line(50 - 20, 110 / 9 * (j + 1), 50 - 10 - 20, 110 / 9 * (j + 1), stroke='red', stroke_width=2, fill='none'))
                b = 2 if not en else 0
                d.append(draw.Line(50 - 6, 110 / 9 * (j + 1) + 2 + b, 50 - 10 - 12, 110 / 9 * (j + 1) + 2 + b, stroke='red', stroke_width=2, fill='none'))
                
    d.setPixelScale(4.2)  # Set number of pixels per geometry unit
    #d.setRenderSize(400,200)  # Alternative to setPixelScale
    #d.saveSvg('example.svg')
    #d.savePng('example.png')

    #d.rasterize()  # Display as PNG
    #d  # Display as SVG
    return d

############################

from apng import APNG
import os, numpy, PIL
from PIL import Image

files = []
f = 0

text = "1234"
pointpos = 0

for j in range(6):
  delay = 1000/2**j

  for _ in range(j):
    for i in range(len(text)):
      fn = "R:/Temp/" + str(f).zfill(5) + ".png"

      seg_switch_draw = i
      column_switch = [i==x for x in range(len(text))]
      point = [i==pointpos==x for x in range(len(text))]
      text_masked = "".join([x if i==index else " " for index, x in enumerate(text)])

      render(text_masked, point, column_switch, seg_switch_draw).savePng(fn)
      
       #remove colors
      arr = numpy.array(Image.open(fn),dtype=numpy.float)
      arr = numpy.array(numpy.round(arr),dtype=numpy.uint8)
      arr = numpy.bitwise_and(arr >> 4, 0x0f)
      arr = numpy.bitwise_and(arr << 4, 0xff)
      out = Image.fromarray(arr,mode="RGB")
      out.save(fn)

      files.append((fn, delay))

      f += 1

#mean
file, delay = files[0]
w,h = Image.open(file).size
N = len(text)
arr = numpy.zeros((h,w,3),numpy.float)
for i in range(len(text)):
  file, delay = files[-i]
  imarr = numpy.array(Image.open(file),dtype=numpy.float)
  arr = arr+imarr/N
arr = numpy.array(numpy.round(arr),dtype=numpy.uint8)

arr = numpy.bitwise_and(arr >> 4, 0x0f) #remove colors
arr = numpy.bitwise_and(arr << 4, 0xff)

out = Image.fromarray(arr,mode="RGB")
out.save(r"R:\Temp\avg.png")
files.append((r"R:\Temp\avg.png", 5000))

im = APNG()
for file, delay in files:
  im.append_file(file, delay=int(delay))
im.save(r"R:\Temp\result.png")

from IPython.display import Image
Image(filename=r"R:\Temp\result.png")

#apng2gif result.png result.gif



Licensing

Image:

w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
Attribution: Laserlicht
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Source:

This file is licensed under the Expat License, sometimes known as the MIT License:

Copyright © Laserlicht

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.


To uploader: MIT License has various versions, you may want to specify the license more precisely. Click {{MIT}} to see details.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

25 February 2022

image/gif

0aafdf6bfcf739840261d4eb0d1c285e12a319d4

530,074 byte

12 second

630 pixel

1,688 pixel

File history

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

Date/TimeThumbnailDimensionsUserComment
current21:58, 25 February 2022Thumbnail for version as of 21:58, 25 February 20221,688 × 630 (518 KB)Laserlichthighest speed not possible in browser...
21:54, 25 February 2022Thumbnail for version as of 21:54, 25 February 20221,688 × 630 (708 KB)LaserlichtThumb->Animation
21:40, 25 February 2022Thumbnail for version as of 21:40, 25 February 20222,010 × 750 (850 KB)LaserlichtUploaded own work with UploadWizard
The following pages on the English Wikipedia use this file (pages on other projects are not listed):

Global file usage

The following other wikis use this file: