--7seg.hs
import HTurtle
import THTurtle
import Control.Monad
data Seg = A | B | C | D | E | F | G deriving (Show, Enum)
getGif :: Seg -> FilePath
getGif A = "y.gif"
getGif D = "y.gif"
getGif G = "y.gif"
getGif _ = "t.gif"
getPos :: Seg -> (Double,Double)
getPos A = (10,40)
getPos B = (20,30)
getPos C = (20,10)
getPos D = (10,0)
getPos E = (0,10)
getPos F = (0,30)
getPos G = (10,20)
onSeg,offSeg :: String -> IO ()
offSeg seg = do
putStr seg
putStrLn ".ht()"
onSeg seg = do
putStr seg
putStrLn ".st()"
mkSeg :: String -> Seg -> Double -> IO ()
mkSeg name seg offset = do
let gif = getGif seg
tShape name gif
let (a,b) = getPos seg
tMove name (a + offset, b)
setNum :: [String] -> Int -> IO [()]
setNum names n = do
zipWithM (\x y -> if y == 1 then onSeg x else offSeg x) names (table !! n)
table =
[[1,1,1,1,1,1,0],
[0,1,1,0,0,0,0],
[1,1,0,1,1,0,1],
[1,1,1,1,0,0,1],
[9,1,1,0,0,1,1],
[1,0,1,1,0,1,1],
[1,0,1,1,1,1,1],
[1,1,1,0,0,0,0],
[1,1,1,1,1,1,1],
[1,1,1,0,0,1,1]]
main = go
go = do
start
s0 <- -="" mapm="" x=""> tCons ("s0" ++ show x)) [0 .. 6]
s1 <- -="" mapm="" x=""> tCons ("s1" ++ show x)) [0 .. 6]
mapM_ tPenup s0
mapM_ tPenup s1
putStrLn "s=getscreen()"
mapM_ tReg ["t.gif","y.gif"]
zipWithM (\x y ->mkSeg x y 0) s0 [A .. G]
zipWithM (\x y ->mkSeg x y 30) s1 [A .. G]
mapM_ (setNum s0) [0..9]
end
#7seg.py
from turtle import *
import datetime
table = [[1,1,1,1,1,1,0], [0,1,1,0,0,0,0], [1,1,0,1,1,0,1], [1,1,1,1,0,0,1], [0,1,1,0,0,1,1], [1,0,1,1,0,1,1], [1,0,1,1,1,1,1], [1,1,1,0,0,0,0], [1,1,1,1,1,1,1], [1,1,1,0,0,1,1]]
s00=Turtle()
s01=Turtle()
s02=Turtle()
s03=Turtle()
s04=Turtle()
s05=Turtle()
s06=Turtle()
d0 = [s00,s01,s02,s03,s04,s05,s06]
for x in d0:
x.penup()
s10=Turtle()
s11=Turtle()
s12=Turtle()
s13=Turtle()
s14=Turtle()
s15=Turtle()
s16=Turtle()
d1 = [s10,s11,s12,s13,s14,s15,s16]
for x in d1:
x.penup()
s=getscreen()
s.register_shape("t.gif")
s.register_shape("y.gif")
s00.shape("y.gif")
s00.setpos(10.0,40.0)
s01.shape("t.gif")
s01.setpos(20.0,30.0)
s02.shape("t.gif")
s02.setpos(20.0,10.0)
s03.shape("y.gif")
s03.setpos(10.0,0.0)
s04.shape("t.gif")
s04.setpos(0.0,10.0)
s05.shape("t.gif")
s05.setpos(0.0,30.0)
s06.shape("y.gif")
s06.setpos(10.0,20.0)
s10.shape("y.gif")
s10.setpos(40.0,40.0)
s11.shape("t.gif")
s11.setpos(50.0,30.0)
s12.shape("t.gif")
s12.setpos(50.0,10.0)
s13.shape("y.gif")
s13.setpos(40.0,0.0)
s14.shape("t.gif")
s14.setpos(30.0,10.0)
s15.shape("t.gif")
s15.setpos(30.0,30.0)
s16.shape("y.gif")
s16.setpos(40.0,20.0)
def setNum (d,n):
t = table [n]
print (t)
for x in range (7):
if t[x] == 0:
d[x].ht()
else:
d[x].st()
dt_now = datetime.datetime.now()
print (dt_now)
s = dt_now.second
print (s)
while True:
dt_now = datetime.datetime.now()
if dt_now.second == s:
continue
else:
s = dt_now.second
q, r = divmod(s, 10)
setNum (d0,q)
setNum (d1,r)
done()
2023年7月29日土曜日
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿