generate character variety image
This commit is contained in:
		
							
								
								
									
										14
									
								
								max_slope_picture/colors
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								max_slope_picture/colors
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
#a6cee3
 | 
			
		||||
#1f78b4
 | 
			
		||||
#b2df8a
 | 
			
		||||
#33a02c
 | 
			
		||||
#fb9a99
 | 
			
		||||
#e31a1c
 | 
			
		||||
#fdbf6f
 | 
			
		||||
#ff7f00
 | 
			
		||||
#cab2d6
 | 
			
		||||
#6a3d9a
 | 
			
		||||
#ffff99
 | 
			
		||||
#b15928
 | 
			
		||||
#ffff00
 | 
			
		||||
#00ffff
 | 
			
		||||
							
								
								
									
										6
									
								
								max_slope_picture/combine_images
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								max_slope_picture/combine_images
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
convert -size 100x99 canvas:black combined.png
 | 
			
		||||
for a in partition_*.pnm; do
 | 
			
		||||
	composite -compose plus combined.png $a combined.png
 | 
			
		||||
done
 | 
			
		||||
							
								
								
									
										69
									
								
								max_slope_picture/generate.hs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								max_slope_picture/generate.hs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
import Text.Printf
 | 
			
		||||
import System.Environment
 | 
			
		||||
import System.Process
 | 
			
		||||
import Data.List
 | 
			
		||||
 | 
			
		||||
wordlist = ["abacabacbabcbacbcacbac", "abacbabcbacbac", "abacbabcbacbcacbac", "abacbacbacbacbacbacbac", "abacbacbacbacbac", "abacbacbac", "bacabacbabcbacbcacbcac", "bacabacbabcbacbcac", "baca", "bacbabcbacbcac", "bacbacbacbacbacbacbcac", "bacbacbacbacbcac", "bacbacbcac", "bacbac"]
 | 
			
		||||
 | 
			
		||||
colors = [(0.651,0.808,0.890), (0.122,0.471,0.706), (0.698,0.875,0.541), (0.200,0.627,0.173), (0.984,0.604,0.600), (0.890,0.102,0.110), (0.992,0.749,0.435), (1.000,0.498,0.000), (0.792,0.698,0.839), (0.416,0.239,0.604), (1.000,1.000,0.600), (0.694,0.349,0.157), (1.000,1.000,0.000), (0.000,1.000,1.000)]
 | 
			
		||||
 | 
			
		||||
main = sequence $ zipWith (generatePicture "result_20210419_221603.out") wordlist colors
 | 
			
		||||
 | 
			
		||||
generatePicture :: String -> String -> (Double,Double,Double) -> IO ()
 | 
			
		||||
generatePicture datafile word color = do
 | 
			
		||||
  file1 <- readFile datafile
 | 
			
		||||
  file2 <- readProcess "../special_element" [word] ""
 | 
			
		||||
  let values1 = map (normalize.read.(!!4).words) (lines file1) :: [Double]
 | 
			
		||||
  let values2 = map (normalize.read.(!!3).words) (lines file2) :: [Double]
 | 
			
		||||
  let diff = zipWith (-) values1 values2
 | 
			
		||||
  writeFile (printf "partition_%s.pnm" word) $ drawGrayscalePicture color diff
 | 
			
		||||
  printf "Wrote partition_%s.pnm\n" word
 | 
			
		||||
 | 
			
		||||
-- kind of a failed experiment
 | 
			
		||||
-- supersample (width, height) to (factor*width - factor + 1, factor*height - factor + 1)
 | 
			
		||||
-- supersample :: Int -> Int -> Int -> [Double] -> [Double]
 | 
			
		||||
-- supersample width height factor orig = [pix x y | x <- [0..(width-1)*factor], y <- [0..(height-1)*factor]]
 | 
			
		||||
--     where
 | 
			
		||||
--       pix x y = xl*yl*a + xl*yr*b + xr*yl*c + xr*yr*d
 | 
			
		||||
--           where
 | 
			
		||||
--             x_ = x`div`factor
 | 
			
		||||
--             y_ = y`div`factor
 | 
			
		||||
--             xr = fromIntegral (x`mod`factor)/fromIntegral factor :: Double
 | 
			
		||||
--             xl = 1 - xr :: Double
 | 
			
		||||
--             yr = fromIntegral (y`mod`factor)/fromIntegral factor :: Double
 | 
			
		||||
--             yl = 1 - yr :: Double
 | 
			
		||||
--             aoffset = x_*height + y_
 | 
			
		||||
--             boffset = x_*height + y_+1
 | 
			
		||||
--             coffset = (x_+1)*height + y_
 | 
			
		||||
--             doffset = (x_+1)*height + y_+1
 | 
			
		||||
--             a = orig!!aoffset
 | 
			
		||||
--             b = if boffset < width*height then orig!!boffset else 0
 | 
			
		||||
--             c = if coffset < width*height then orig!!coffset else 0
 | 
			
		||||
--             d = if doffset < width*height then orig!!doffset else 0
 | 
			
		||||
 | 
			
		||||
-- xl*yl*a + xl*yr*b + xr*yl*c + xr*yr*d
 | 
			
		||||
 | 
			
		||||
drawGrayscalePicture :: (Double,Double,Double) -> [Double] -> String
 | 
			
		||||
drawGrayscalePicture (r,g,b) values = drawPicture 100 99 $ map color values
 | 
			
		||||
    where
 | 
			
		||||
      color x = (round (255*r*colorscale x), round (255*g*colorscale x), round (255*b*colorscale x))
 | 
			
		||||
 | 
			
		||||
drawPicture :: Int -> Int -> [(Int,Int,Int)] -> String
 | 
			
		||||
drawPicture w h values = printf "P3\n%d %d\n255\n%s" w h pixels
 | 
			
		||||
    where
 | 
			
		||||
      pixels = concat [printf "%d %d %d\n" r g b | (r,g,b) <- values] :: String
 | 
			
		||||
 | 
			
		||||
normalize x = if x < 1 then 1/x else x
 | 
			
		||||
 | 
			
		||||
readDataFile :: String -> IO [(String,Double)]
 | 
			
		||||
readDataFile filename = do
 | 
			
		||||
  f <- readFile filename
 | 
			
		||||
  return $ map process $ map words $ lines f
 | 
			
		||||
      where
 | 
			
		||||
        process (x:y:_:_:z:rest) = (x++" "++y,read z)
 | 
			
		||||
        normalize x = if x < 1 then 1/x else x
 | 
			
		||||
 | 
			
		||||
colorscale :: Double -> Double
 | 
			
		||||
colorscale x = if cs x < 0 then 1 else if cs x > 1 then 0 else 1 - cs x
 | 
			
		||||
    where
 | 
			
		||||
      cs x = 1e5*x
 | 
			
		||||
							
								
								
									
										9900
									
								
								max_slope_picture/result_20210419_221603.out
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9900
									
								
								max_slope_picture/result_20210419_221603.out
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user