機械学習を活用して、Amazonの文化破壊と闘う先住民族がいます
2024年4月10日水曜日
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
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.