Il programma per l’orario digitale con i 7-segmenti si presta a esperimenti grafici!
Aggiungendo 6 sfere si possono coprire i buchi lasciati dai cilindri.

Le posizioni in verticale delle cifre diverse.

Orario e data.

from vpython import *
from datetime import datetime
#----------------------------------------------------------------------------------- Parametri
C = color.yellow # Colore dei cilindri
D = 1 # Dimensione, lunghezza, dei cilindri
R = D/5 # Raggio dei cilindri
#----------------------------------------------------------------------------------- Tutto acceso!
SETTE_SEGMENTI = [
cylinder(pos=vector(0,2*D,0), axis=vector(1,0,0), radius=R, color=C), # 0
cylinder(pos=vector(0, D,0), axis=vector(0,1,0), radius=R, color=C), # 1
cylinder(pos=vector(D, D,0), axis=vector(0,1,0), radius=R, color=C), # 2
cylinder(pos=vector(0, D,0), axis=vector(1,0,0), radius=R, color=C), # 3
cylinder(pos=vector(0, 0,0), axis=vector(0,1,0), radius=R, color=C), # 4
cylinder(pos=vector(D, 0,0), axis=vector(0,1,0), radius=R, color=C), # 5
cylinder(pos=vector(0, 0,0), axis=vector(1,0,0), radius=R, color=C) # 6
]
SEI_SFERE = [
sphere(pos=vector(0,2*D,0), radius=R, color=C), # 0
sphere(pos=vector(D,2*D,0), radius=R, color=C), # 1
sphere(pos=vector(0, D,0), radius=R, color=C), # 2
sphere(pos=vector(D, D,0), radius=R, color=C), # 3
sphere(pos=vector(0, 0,0), radius=R, color=C), # 4
sphere(pos=vector(D, 0,0), radius=R, color=C), # 5
]
#----------------------------------------------------------------------------------- Mappa
VALORE_SEGMENTI = [
[True , True , True , False, True , True , True ], # 0
[False, False, True , False, False, True , False], # 1
[True , False, True , True , True , False, True ], # 2
[True , False, True , True , False, True , True ], # 3
[False, True , True , True , False, True , False], # 4
[True , True , False, True , False, True , True ], # 5
[False, True , False, True , True , True , True ], # 6
[True , False, True , False, False, True , False], # 7
[True , True , True , True , True , True , True ], # 8
[True , True , True , True , False, True , False] # 9
]
VALORE_SFERE = [
[True , True , False, False, True , True],
[False, True , False, False, False, True],
[True , True , True , True , True , True],
[True , True , True , False, True , True],
[True , True , True , False, False, True],
[True , True , True , True , True , True],
[True , False, True , True , True , True],
[True , True , False, False, False, True],
[True , True , False, False, True , True],
[True , True , True , False, False, True]
]
#-----------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------
for i in range(7): # Tutto spento...
SETTE_SEGMENTI[i].visible = False
for i in range(6):
SEI_SFERE[i].visible = False
CIFRE = []
SFERE = []
POS_X = [-4.75*D, -3.25*D, -1.25*D, 0.25*D, 2.25*D, 3.75*D,
-6.25*D, -4.75*D, -2.75*D, -1.25*D, 0.75*D, 2.25*D, 3.75*D, 5.25*D]
POS_Y = [0.5*D, 0.5*D, 0.5*D, 0.5*D, 0.5*D, 0.5*D,
-2.5*D, -2.5*D, -2.5*D, -2.5*D, -2.5*D, -2.5*D, -2.5*D, -2.5*D]
for i in range(14):
sette_segmenti = []
for j in range(7):
segmento = SETTE_SEGMENTI[j].clone()
segmento.pos.x += POS_X[i]
segmento.pos.y += POS_Y[i]
sette_segmenti.append(segmento)
CIFRE.append(sette_segmenti)
sei_sfere = []
for j in range(6):
sfera = SEI_SFERE[j].clone()
sfera.pos.x += POS_X[i]
sfera.pos.y += POS_Y[i]
sei_sfere.append(sfera)
SFERE.append(sei_sfere)
#----------------------------------------------------------------------------------- Funzione
def aggiorna_stato(posizione, valore):
for segmento in range(7):
CIFRE[posizione][segmento].visible = VALORE_SEGMENTI[valore][segmento]
for sfera in range(6):
SFERE[posizione][sfera].visible = VALORE_SFERE[valore][sfera]
#----------------------------------------------------------------------------------- MAIN
cifre_orario = 14*[0]
while(True):
rate(5)
adesso = datetime.now()
ore = adesso.hour
minuti = adesso.minute
secondi = adesso.second
giorno = adesso.day
mese = adesso.month
anno = adesso.year
cifre_orario[0] = ore // 10
cifre_orario[1] = ore % 10
cifre_orario[2] = minuti // 10
cifre_orario[3] = minuti % 10
cifre_orario[4] = secondi // 10
cifre_orario[5] = secondi % 10
cifre_orario[6] = giorno // 10
cifre_orario[7] = giorno % 10
cifre_orario[8] = mese // 10
cifre_orario[9] = mese % 10
cifre_orario[10] = anno // 1000
cifre_orario[11] = (anno % 1000) // 100
cifre_orario[12] = (anno % 100) // 10
cifre_orario[13] = anno % 10
for i in range(14):
aggiorna_stato(i, cifre_orario[i])
Glowscript
Alcune modifiche per adattare il codice al web
Web VPython 3.2
#----------------------------------------------------------------------------------- Parametri
C = color.yellow # Colore dei cilindri
D = 1 # Dimensione, lunghezza, dei cilindri
R = D/5 # Raggio dei cilindri
#----------------------------------------------------------------------------------- Tutto acceso!
SETTE_SEGMENTI = [
cylinder(pos=vector(0,2*D,0), axis=vector(1,0,0), radius=R, color=C), # 0
cylinder(pos=vector(0, D,0), axis=vector(0,1,0), radius=R, color=C), # 1
cylinder(pos=vector(D, D,0), axis=vector(0,1,0), radius=R, color=C), # 2
cylinder(pos=vector(0, D,0), axis=vector(1,0,0), radius=R, color=C), # 3
cylinder(pos=vector(0, 0,0), axis=vector(0,1,0), radius=R, color=C), # 4
cylinder(pos=vector(D, 0,0), axis=vector(0,1,0), radius=R, color=C), # 5
cylinder(pos=vector(0, 0,0), axis=vector(1,0,0), radius=R, color=C) # 6
]
SEI_SFERE = [
sphere(pos=vector(0,2*D,0), radius=R, color=C), # 0
sphere(pos=vector(D,2*D,0), radius=R, color=C), # 1
sphere(pos=vector(0, D,0), radius=R, color=C), # 2
sphere(pos=vector(D, D,0), radius=R, color=C), # 3
sphere(pos=vector(0, 0,0), radius=R, color=C), # 4
sphere(pos=vector(D, 0,0), radius=R, color=C), # 5
]
#----------------------------------------------------------------------------------- Mappa
VALORE_SEGMENTI = [
[True , True , True , False, True , True , True ],
[False, False, True , False, False, True , False],
[True , False, True , True , True , False, True ],
[True , False, True , True , False, True , True ],
[False, True , True , True , False, True , False],
[True , True , False, True , False, True , True ],
[False, True , False, True , True , True , True ],
[True , False, True , False, False, True , False],
[True , True , True , True , True , True , True ],
[True , True , True , True , False, True , False]
]
VALORE_SFERE = [
[True , True , False, False, True , True],
[False, True , False, False, False, True],
[True , True , True , True , True , True],
[True , True , True , False, True , True],
[True , True , True , False, False, True],
[True , True , True , True , True , True],
[True , False, True , True , True , True],
[True , True , False, False, False, True],
[True , True , False, False, True , True],
[True , True , True , False, False, True]
]
#-----------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------
for i in range(7): # Tutto spento...
SETTE_SEGMENTI[i].visible = False
for i in range(6):
SEI_SFERE[i].visible = False
CIFRE = []
SFERE = []
POS_X = [-4.75*D, -3.25*D, -1.25*D, 0.25*D, 2.25*D, 3.75*D,
-6.25*D, -4.75*D, -2.75*D, -1.25*D, 0.75*D, 2.25*D, 3.75*D, 5.25*D]
POS_Y = [0.5*D, 0.5*D, 0.5*D, 0.5*D, 0.5*D, 0.5*D,
-2.5*D, -2.5*D, -2.5*D, -2.5*D, -2.5*D, -2.5*D, -2.5*D, -2.5*D]
for i in range(14):
sette_segmenti = []
for j in range(7):
segmento = SETTE_SEGMENTI[j].clone()
segmento.pos.x += POS_X[i]
segmento.pos.y += POS_Y[i]
sette_segmenti.append(segmento)
CIFRE.append(sette_segmenti)
sei_sfere = []
for j in range(6):
sfera = SEI_SFERE[j].clone()
sfera.pos.x += POS_X[i]
sfera.pos.y += POS_Y[i]
sei_sfere.append(sfera)
SFERE.append(sei_sfere)
#----------------------------------------------------------------------------------- Funzione
def aggiorna_stato(posizione, valore):
for segmento in range(7):
CIFRE[posizione][segmento].visible = VALORE_SEGMENTI[valore][segmento]
for sfera in range(6):
SFERE[posizione][sfera].visible = VALORE_SFERE[valore][sfera]
#----------------------------------------------------------------------------------- MAIN
cifre_orario = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
while(True):
rate(5)
adesso = Date()
secondi = adesso.getSeconds()
minuti = adesso.getMinutes()
ore = adesso.getHours()
giorno = adesso.getDate()
mese = adesso.getMonth()+1
anno = adesso.getFullYear()
cifre_orario[0] = ore//10
cifre_orario[1] = ore % 10
cifre_orario[2] = minuti//10
cifre_orario[3] = minuti % 10
cifre_orario[4] = secondi//10
cifre_orario[5] = secondi % 10
cifre_orario[6] = giorno//10
cifre_orario[7] = giorno % 10
cifre_orario[8] = mese//10
cifre_orario[9] = mese % 10
cifre_orario[10] = anno//1000
cifre_orario[11] = (anno % 1000)//100
cifre_orario[12] = (anno % 100)//10
cifre_orario[13] = anno % 10
for i in range(14):
aggiorna_stato(i, cifre_orario[i])
Ulteriori variazioni
Il raggio dei cilindri e delle sfere più piccolo

Le sfere di colore diverso, il raggio dei cilindri più piccolo
