2023年7月29日土曜日


--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月17日月曜日

Haskell+Python.Turtleでハノイの塔をグラフィカルに解きます。


-- pbm.hs
import System.IO 
import System.Environment
getI :: IO Int 
getI = getArgs >>= (\(x:_) -> (return . read) x)
main = do
    n <- getI 
    mapM_ mkpbm [1..n]
mkpbm n = do
    h <- openFile ((show n) ++ ".pbm") WriteMode
    pbm h n
    hClose h
pbm h n = do
    hPutStrLn h "P1"
    hPutStrLn h $ show (10 * n)
    hPutStrLn h "10 "
    mapM_ (\x -> hPutStrLn h (line n)) [0..9]
    where line n = take (n*10) $ ['1','1' ..]

    
-- conv.hs
import System.Process
import System.FilePath
import System.Directory
main = do
    fs <- getCurrentDirectory >>= listDirectory 
    let fss = filter (\x -> "pbm" `isExtensionOf` x) fs
    print fs
    print fss
    mapM_ conv fss
--  % convert -fill 新しい色 -opaque 古い色 orig.png new.gif
conv i = do
    let o = nf
    createProcess (proc "convert" ["-fill","brown","-opaque","black", i ,o])
    where nf = replaceExtension i "gif" 

    
-- tHanoi.hs
import HTurtle
import Control.Monad
import Control.Monad.State
import Control.Exception
import System.IO.Error
main = do
    start
    line [(0,0),(0,100)]
    line [(100,0),(100,100)]
    line [(200,0),(200,100)]
    ts <- mapM tCons [1 .. 9]
    mapM_ (flip tSpeed 10) ts
    mapM_ tPenup ts
    putStrLn "s=getscreen()"
    mapM_ tReg gs
    zipWithM  tShape  ts gs
    zipWithM tMove ts p
    runStateT  loop (9,0,0)
    end
    where   p = [(0,x*10 - 10)|x <- [9,8..1]]
            gs = [show x++".gif"|x <- [1..9]]
tSpeed :: String -> Double -> IO()
tSpeed tn sn = do
    putStr tn
    putStr "."
    speed sn
tPenup :: String -> IO ()
tPenup tn = do
    putStr tn
    putStr "."
    penup
tCons :: Int -> IO String
tCons n = do
    putStr "t"
    putStr $ show n
    putStr "="
    putStrLn "Turtle()" 
    return $ 't':show n
tShape :: String -> String -> IO ()
tShape tname gifName = do
    putStr tname 
    putStr "."
    shape gifName
tReg :: String -> IO ()
tReg gn = do
    putStr "s"
    putStr "."
    putStr "register_shape"
    putStr "("
    putStr $ show gn
    putStrLn ")" 
tMove :: String -> Point -> IO()
tMove tn p = do
    putStr tn 
    putStr "."   
    setPos p
loop = do 
    [a,b,c] <- liftIO $ catchIOError getLine (\_ -> return "000")
    if a == '0' 
    then return ()
    else do
        let disc = "t" ++ [a]
        let tower = getTower c
        y <- update [b,c] 
        liftIO $ tMove disc (tower,fromIntegral (y*10))
        loop
getTower 'A' = 0
getTower 'B' = 100
getTower 'C' = 200
getTower _  = 0
update "AB" = do{(a,b,c) <- get;put(a-1,b+1,c);return b}
update "AC" = do{(a,b,c) <- get;put(a-1,b,c+1);return c}
update "BA" = do{(a,b,c) <- get;put(a+1,b-1,c);return a}
update "BC" = do{(a,b,c) <- get;put(a,b-1,c+1);return c}
update "CA" = do{(a,b,c) <- get;put(a+1,b,c-1);return a}
update "CB" = do{(a,b,c) <- get;put(a,b+1,c-1);return b}
update _ = return 0
 -- HTurtle.hs

module HTurtle where
type Point = (Double,Double)

f0 :: String -> IO()
f0 s = putStrLn s
f1 :: String -> IO()
f1 s = do
    putStr s
    putStrLn "()"
f2 :: String -> Double -> IO()
f2 s n = do
    putStr s
    putStr "("
    putStr $ show n
    putStrLn ")"
f2' :: String -> Point -> IO()
f2' s p = do
    putStr s
    putStrLn $ show p
f3 :: String -> String -> IO()
f3 s s1 = do
    putStr s
    putStr "("
    putStr "\""
    putStr s1
    putStr "\""
    putStrLn ")"
dig x = x / (pi / 180)
start = f0 "from turtle import *"
end = f1 "done"
getHeading = print "a = heading()"

pensize = f2 "pensize" 
screensize p = f2' "screensize" p
polygon :: [Point] -> String -> Bool -> IO ()
polygon pp@(p:ps) color True = do
    fillColor color
    beginFill
    penup
    setPos p
    pendown
    mapM_ setPos (ps ++ [p])
    endFill
line [a,b] = penup >> setPos a >> color "black" >> pendown >> setPos b  
erase [a,b] = penup >> setPos a >> color "white" >> pendown >> setPos b >> color "black" >> penup
dot p = penup >> setPos p >> pendown >> f1 "dot" >> pendown
penup = f1 "penup"
pendown = f1 "pendown"
triangle = polygon 
circle (a,b) x = penup >> setPos (a,b-x) >> pendown >> f2 "circle" x 
speed = f2 "speed" 
shape = f3 "shape" 
color = f3 "color" 
fillColor = f3 "fillcolor" 
beginFill = f1 "begin_fill"
endFill = f1 "end_fill"
setPos = f2' "setpos" 
setx = f2 "setx"
sety = f2 "sety" 
setH x = f2 "seth" (dig x)
foward x = pendown >> f2 "fd" x 
right = f2 "right" 
left = f2 "left" 
-- end of HTurtle.hs


2023年6月24日土曜日

El Toroby La Bande De "El Toreo"RCA Victor (LSP-2538)Publication date 1962

EL TORO / PASO DOBLES PERFORMED by LA BANDA de “EL TOREO” Under the direction of Mario Ruiz Armengol Audience reaction recorded live at the Mexican bull ring “El Toreo.” AZ£R Coordinator—Herman Diaz, Jr. . . a mystique, a passion .. . that transports and ennobles. La Corrida, the “running of the bulls” or the bullfight, is one of the great spectacles of the Spanish-speaking world. It has been poetically described as a ritual challenge of death. Each time the matador triumphs over the formidable bull, he is Man facing up to Death, the Great Extinguisher, and winning a victory over it for all men. In this defiance and triumph, there is something of immortality for all men. You may be sure that that least of aficionados! sitting up there in the glaring sun of the sol zone does not ponder the experience in such exalted terms. He is probably too intent on exercising his expertise in judging the fine points of the performance of the matadors, the picadors, the banderilleros—and the bulls. Let any > of these worthies turn in what our aficionado considers less than a creditable performance and he incurs the risk of . the fearsome whistling which is the Latin equivalent of the U.S. “'boo'” or Bronx cheer. But aside from. :, the thrills, the noise and the color, there isa mystique, a passion in the corrida that transports and ennobles BA the audience. Here in this album is an attempt to capture these emotions and sensations. Here is the excited anticipation of the crowd, the surging “Olé's,” the thrilling paso doblés . ( —traditional music that accompanies the acts and actions of the drama. $ If you have ever witnessed the corrida or, like countless millions the world 'over, have vicariously experienced its expression in.all the arts—literature, painting, the dance, music,“etc.—this album will brilliantly % re-create the spectacle for you. THE SPECTACLE FROM START TO FINISH “To the Bulls! To the Bulls!” cry the cabdrivers and bus drivers .. . and the people flow like an immense river to the plaza. The sun bathes the golden sand, the band launches into a gay bullfight paso doble, and the cuadrillas make the paseo greeted by a thundering ovation. The bugle sounds and the first bull comes into the ruedo. After the suerte de varas, the matador plays the bull with his cape in sublime lances. The banderilleros spear the bull with three magnificent pairs of banderillas, and the final tercio begins. The matador advances slowly, muleta and estoque in hand— and the faena begins. Enthusiasm mounts. Each pase is chorused with a stentorian “¡olé!” A vibrant paso doble accompanies the great show of courage and art, and finally comes—““la hora de la verdad.” The matador has cuadrado the bull. There is a deep silence. These are the seconds of most intense emotion, The craftsman se perfila to enter for the kill. He then attracts the bull's attention with the muleta. The bull leaps forth like a gust of wind. The maestro stands firm against the savage attack. The estoque sinks up to the hilt between the shoulder blades of the beast... and he falls as if mortally wounded by a bolt of lightning. Irre- pressible jubilation explodes. The people applaud, they yell till they're hoarse; they turn to all kinds of noisy demonstrations to show their highest approval. The band breaks out with a lively paso doble—a glorious culmination for a splendid lidia, which is awarded the two ears and the tail. And thus for a total of six bulls. And thus the next Sunday . . . and the next... and the next. It is the national fiesta—gold, silk, blood and sun! It is the fiesta of courage, which makes the heart overflow with enthusiasm and admiration! Aficionados ... . friends . .. don't miss this corrida! To the Bulls! To the Bulls! GLOSSARY Aficionados—bullfight fans (in this case); sometimes, amateurs. Banderillero—bulifighter who thrusts small darts adorned with colored paper, called banderillas, into the withers of the bull. Cuadrar—positioning bull for the kill. Cuadrilla—the matadors “team": pica- dores (goad the bull), banderilleros (place the darts), mozo de estoques (sword bearer). Corrida—bullfight. Estoque—sword. Faena—the work done with the muleta. “La Hora de la Verdad"—“"The Moment of Truth” (the moment of killing the bull. Lance—pass with the cape. Lidia—bullfight, Matador—he who kills the bull. Muleta—cloth used to lure the bull. 1Olél—a cheer. Pase—pass made with the muleta, Paseo—the march of the cuadrillas into the bull ring. Perfilarse—one of the stances used in kill- ing the bull. Ruedo—the bull ring. Suerte or Tercio—each of the three parts into which each bullfight is divided. Suerte de varas—portion of the bullfight in which mounted picadors thrust their goads —picas—into the bulls. **¡A los toros! ¡A los toros!”, gritan cocheros y choferes + + « y los vehículos se llenan y el pueblo todo afluye como inmenso río a la plaza. El sol inunda la dorada arena. La banda ataca un alegre paso doble torero . . . y las cuadrillas hacen el paseo acogidas por estruendosa ovación. Suenan los clarines, y salta al ruedo el primer toro. Tras la suerte de varas, el matador lo torea de capa con lances sublimes. Los banderilleros le clavan tres magníficos pares de banderillas .. . y viene el último tercio. El matador se adelanta despacio, muleta y estoque en mano ... y comienza la faena. El entusiasmo va subiendo. Cada pase es coreado con un estentóreo ¡olé!. Un vibrante paso doble acompaña al derroche de valor y arte, y al fin llega .... “la hora de la verdad.” El matador ha cuadrado al toro. Se hace un profundo silencio. Son los segundos de más intensa emoción. El diestro se perfila para entrar a matar. Cita entonces al toro con la muleta. Se arranca éste como una exhalación. Aguanta el maestro a pie firme la salvaje acometida. Se hunde el estoque hasta el puño en todo lo alto del morrillo de la fiera... y ésta cae como herida de muerte por un rayo. El júbilo estalla incontenible. La gente aplaude, grita hasta enronquecer ... recurre a toda manifestación ruidosa para demostrar su exaltada aprobación .. . y la banda rompe a tocar un brioso paso doble—gloriosa culminación para tan espléndida lidia, que se premia con las dos orejas y el rabo. Y así... seis toros. Y así al otro domingo . .. y al otro ...yalotro... ¡Es la fiesta nacional—oro, seda, sangre y sol .. .! ¡Es la fiesta del valor, que hace que se desborden de entusiasmo y admiración los corazones! Aficionados ... amigos .. . ¡no se pierdan esta corrida! ¡A los toros! ¡A los toros! Emitio De Torre

2023年6月20日火曜日

コッホ曲線



import HTurtle
import Data.Complex
main = do
    start
    koch ((0,0),(400,0)) 4
    end
koch ((a,b),(c,d)) n = do
    if n == 0   then doKoch >> return ()
                else do koch (p0,p1) (n-1)
                        koch (p1,p2) (n-1)
                        koch (p2,p3) (n-1)
                        koch (p3,p4) (n-1)
    where   al = a :+ b
            be = c :+ d
            p0 = (a,b)
            p1 = let (a :+ b) = c1 in (a,b)
            p2 = let (a :+ b) = c2 in (a,b)
            p3 = let (a :+ b) = c3 in (a,b)
            p4 = (c,d)
            c1 = cid (al,be) 1 2
            c2 = sumit (c1,c3) (pi / 3)
            c3 = cid (al,be) 2 1
            doKoch = do setPos p0
                        setPos p1
                        setPos p2
                        setPos p3
                        setPos p4
cid (a,b) m n = (n * a + m * b) / (m + n)
sumit (a,b) th = (b - a) * (cos th :+ sin th) + a


2023年6月14日水曜日

Flacファイルの分割


-- fc.hs
import  Graphics.UI.Gtk 
main = do
    initGUI
    fchdal <- fileChooserDialogNew Nothing Nothing 
        FileChooserActionOpen
        [("Cancel", ResponseCancel), ("Select", ResponseAccept)]
    fchdal `set` [fileChooserDoOverwriteConfirmation := True]
    widgetShow fchdal
    response <- dialogRun fchdal
    case response of
        ResponseCancel -> putStrLn "You cancelled..."
        ResponseAccept -> do 
            nwf <- fileChooserGetFilename fchdal
            case nwf of
                Nothing -> putStrLn "Nothing" 
                Just path -> putStr path 
    w <- windowNew 
    w `set` [windowDefaultWidth := 16, windowDefaultHeight := 16]
    s <- spinnerNew
    containerAdd w s 
    widgetShowAll w
    spinnerStart s
    widgetDestroy fchdal
    fchdal `on` objectDestroy $ mainQuit
    mainGUI
-- end of fc.hs

-- t.hs
import System.Directory
import System.FilePath.Posix
import System.Process
duration :: FilePath -> IO ()
duration f = createProcess (proc "soxi" ["-D",f]) >> return ()
splitFileName' = return . splitFileName
main = do
    (d,f) <- readFile "fn" >>= splitFileName' 
    setCurrentDirectory d
    duration f 
-- end of t.hs

-- t2.hs
import System.Directory
import System.FilePath.Posix
import System.Process
getC :: IO Double
getC = getContents >>= return . read 
splitFileName' = return . splitFileName
main = do
    d <- getC 
    (dir,f) <- readFile "fn" >>= splitFileName'
    setCurrentDirectory dir
    n <- f1 d 1
    let t = d / n
    let l = f2 t n
    doComs f t l    
f1 d n = if (d / n)  < 300 then return n else f1 d (n + 1)  
f2 d n = map (\x -> x*d) [0..(n - 1)]
doComs f d l = do
    mapM_ (\x -> trim f (nf f x) x (d + 10)) (init l)
    let x = last l
    trim f (nf f x) x d
    where nf f x = "trimed" ++ show (round x) ++ takeBaseName f ++ ".flac"
trim :: FilePath -> FilePath -> Double -> Double -> IO ()
trim i o sP d = createProcess (proc "sox" [i, o,"trim", show sP, show d]) >> return ()
-- end of t2.hs


2023年6月13日火曜日

1812

 The incredible popularity in release of this version of 1812 proved not only the durable appeal of Tchaikovsky’s famous musical


3 war-horse, but also the appetite of the record-buying public for genuine sonic thrills. Thus, Mercury was prompted to seek out

another “symphonic battle piece”: Beethoven’s stormy Wellington's Victory. Here, cannons were present in the scoring, plus the

carefully-cued rattling crack of 19th century musketry. In this second recording, another “sonic spectacular” was born—and, once

again, recording history was made!



mated orchestral machine run by air pressure

which played flutes, clarinets, trumpets, violins,

cellos, drums, cymbals, triangles and so on. It

could also be made to shoot off muskets and other

weaponry. Fascinated by what the machine could

do, Beethoven agreed enthusiastically to write a

piece for the metal monster. The composer had

been a Bonapartist until 1804 when Napoleon un-

seated the French Revolution and made himself

an Emperor. At that time, he scratched the Na-

poleonic dedication from his Eroica Symphony

and joined the Anti-Bonaparte partisans. After

the Vitoria victory, he was delighted at the

chance of depicting musically the defeat of the

Emperor’s brother by the British.


In Wellington’s Victory, Beethoven wrote

carefully to the capacities of the machine, but

troubles in rigging the apparatus kept delaying

its premiere. The novelty value of the subject of

the piece was fast fading. Finally, Beethoven de-

cided quickly to re-score it for conventional or-

chestra. It was thus that it was first performed.


As the piece begins, the opposing armies intro-

duce themselves musically before doing battle.

First, faintly from the British camp (right), a

drum tattoo pulses distantly; other drums join

in; the sound grows until a thundering roar fills

the air; then, above the tumult of steady drum-

ming, trumpets sound a battle cry.'The British

cap this brilliant fanfare with a rousing version

of Rule, Britannia. From their side (left), the

French respond with their own drum-and-trum-

pet fanfare and the war song Malbrouck s’en va

ten guerre (known to Americans as The Bear

Went Over The Mountain). After these prelimi-

naries, the French challenge the British to fight

in a stirring trumpet call. The British accept,

throwing the call back with higher-pitched trum-

pets. As battle begins, the main orchestra takes

over. Throughout the clamorous battle, the Brit-

ish and French trumpets are heard distinctly

from their respective sides, rallying the troops.

Musket volleys and cannonade punctuate the

music. Soon, we notice that only the British can-

non are firing. The British have won the upper

hand; Bonaparte’s army finally shudders to a halt

in a minor-key version of the Malbrouck tune. A

victory finale, featuring a vigorous treatment of

God Save The King, brings this piéce d’occasion

to a tremendous close.

HOW THESE RECORDINGS WERE MADE

The musical portions of the Overture 1812 were

recorded in Minneapolis, while the military ef.

fects were taped at West Point. To serve as au-

thentic French weapons of a type used by Napo-

leon in 1812, Gerald C. Stowe, Curator of the

West Point Museum, selected cannons made in

France during the 18th century: one made in

Douay in 1775 (stereo version), and the other cast

in Strasbourg in 1761 (monophonic version).


To achieve a truly realistic bell effect for this

recording, it was decided to use authentic caril-

lon sounds. For the stereo version, the magnifi-

cent Laura Spelman Rockefeller Memorial Caril-

lon of New York City’s Riverside Church was

used. This instrument includes a bass-toned bell

which is the largest tuned bell in the world; the

full carillon weighs over half a million pounds.

For the monophonic version, use was obtained

of the bells of the beautiful Harkness Memorial

Tower on the Yale University campus.


The recording of Wellington’s Victory used

three orchestras in which augmented sections of

brass and percussion, flintlock muskets and a bat-

tery of field artillery comprised basic added ele-

ments. According to Beethoven’s instructions,

the musical forces were deployed in the follow-

ing manner:

His score fixes the exact point at which each of

188 cannon shots was to be fired, designating

British weaponry by a black dot @; French by a

hollow dot o. These dots appear above their re-

spective beats and measures. Entry, direction and

duration of the musket shots is indicated pre-

cisely by notation, each volley shown in tied,

trilled notes.


Again, as in recording of the 1812, weapons of

authentic style were provided by the West Point

Museum and firing was done on the grounds of

the United States Military Academy. Seven flint-

lock muskets of the Napoleonic era—both British

and French in casting—were used. The muzzle-

loading field artillery is represented by two 6-

pound smooth-bore bronze cannons and a 12-

pound bronze howitzer. The French cannon heard

here was made at Strasbourg in 1761; the British

at Woolwich in 1755; the howitzer is of a type

used by both sides in the Napoleonic wars.