"pinned the nix config"
This commit is contained in:
parent
155d4753ec
commit
febf06f27c
4 changed files with 42 additions and 46 deletions
15
project.nix
15
project.nix
|
|
@ -1,15 +0,0 @@
|
|||
{ mkDerivation, base, colour, diagrams-lib, diagrams-svg, hip
|
||||
, parallel, random, repa, stdenv, vector
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "image-triangles";
|
||||
version = "0.1.0.0";
|
||||
src = ./.;
|
||||
isLibrary = false;
|
||||
isExecutable = true;
|
||||
executableHaskellDepends = [
|
||||
base colour diagrams-lib diagrams-svg hip parallel random repa
|
||||
vector
|
||||
];
|
||||
license = stdenv.lib.licenses.bsd3;
|
||||
}
|
||||
38
release.nix
38
release.nix
|
|
@ -1,21 +1,27 @@
|
|||
let
|
||||
config = {
|
||||
packageOverrides = pkgs: rec {
|
||||
haskellPackages = pkgs.haskellPackages.override {
|
||||
overrides = haskellPackagesNew: haskellPackagesOld: rec {
|
||||
project =
|
||||
haskellPackagesNew.callPackage ./project.nix { };
|
||||
|
||||
SVGFonts =
|
||||
haskellPackagesNew.callPackage ./SVGFonts.nix { };
|
||||
};
|
||||
};
|
||||
};
|
||||
inherit (import <nixpkgs> {}) fetchFromGitHub;
|
||||
nixpkgs = fetchFromGitHub {
|
||||
owner = "NixOS";
|
||||
repo = "nixpkgs-channels";
|
||||
rev = "50f41ea2fcf86def32799f75577a4fe5cfd1132e";
|
||||
sha256 = "1q0bxl5nxx1kabqvyzkdw91c5dnwpi2rwsgs5jdmnj7f0qqgdxh8";
|
||||
};
|
||||
|
||||
pkgs = import <nixpkgs> {inherit config;};
|
||||
config = {
|
||||
packageOverrides = pkgs: rec {
|
||||
haskellPackages = pkgs.haskellPackages.override {
|
||||
overrides = haskellPackagesNew: haskellPackagesOld: rec {
|
||||
SVGFonts
|
||||
= pkgs.haskellPackages.callHackage "SVGFonts" "1.6.0.3" {};
|
||||
|
||||
project
|
||||
= haskellPackagesNew.callCabal2nix "image-triangles" ../image-triangles {};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
pkgs = import nixpkgs {inherit config;};
|
||||
in
|
||||
{ project = pkgs.haskellPackages.project;
|
||||
|
||||
}
|
||||
{
|
||||
project = pkgs.haskellPackages.project;
|
||||
}
|
||||
|
|
|
|||
13
src/Main.hs
13
src/Main.hs
|
|
@ -1,5 +1,3 @@
|
|||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import qualified Triangles as Tri
|
||||
|
|
@ -7,7 +5,7 @@ import qualified Render as Ren
|
|||
import Graphics.Image as Img hiding (map, zipWith)
|
||||
import System.Random
|
||||
import qualified Graphics.Image.ColorSpace as G
|
||||
import qualified Data.Colour.SRGB as C
|
||||
import qualified Data.Colour.SRGB.Linear as CL
|
||||
import Diagrams.Backend.SVG.CmdLine
|
||||
import Diagrams.Prelude
|
||||
import Debug.Trace
|
||||
|
|
@ -32,10 +30,11 @@ defaultOpts = Options {
|
|||
genList :: StdGen -> [StdGen]
|
||||
genList = map mkStdGen . randoms
|
||||
|
||||
tosRGB' :: (Ord b, Floating b) => Pixel G.RGB b -> Colour b
|
||||
tosRGB' (G.PixelRGB r g b) = C.sRGB r g b
|
||||
-- CL.rgb might be the wrong fn...
|
||||
tosRGB' :: (Ord b, Floating b) => Pixel G.RGB b -> CL.Colour b
|
||||
tosRGB' (G.PixelRGB r g b) = CL.rgb r g b
|
||||
|
||||
|
||||
convImage :: Image VU G.RGB Double -> Vec.Vector (Colour Double)
|
||||
convImage = Vec.map tosRGB' . Vec.convert . R.toUnboxed . Img.toRepaArray
|
||||
|
||||
-- progress goes from 0 to 1 the farther we get along the process
|
||||
|
|
@ -44,7 +43,7 @@ renderTri :: Vec.Vector (Colour Double) -> (Int, Int) -> StdGen -> Double -> QDi
|
|||
renderTri image dimensions gen progress = Ren.makeTriangle (Ren.toPointList dimensions triangle) color opacity'
|
||||
where
|
||||
|
||||
triangle = Tri.getRandomTriangle dimensions (Just area) gen
|
||||
triangle = Tri.getRandomTriangle image dimensions (Just area) gen
|
||||
|
||||
color = Tri.getTriangleAverageRGB image triangle dimensions
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,12 @@
|
|||
module Triangles where
|
||||
|
||||
import System.Random
|
||||
import qualified Data.Colour.SRGB as C
|
||||
import qualified Data.Colour.SRGB.Linear as C
|
||||
import qualified Data.Colour as C
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import qualified Data.Vector as Vec
|
||||
import Data.Fixed
|
||||
|
||||
|
||||
type Image_ = Vec.Vector Pixel_
|
||||
|
|
@ -40,7 +41,7 @@ shoelace' :: [Point] -> Double
|
|||
shoelace' [(y1, x1), (y2, x2), (y3, x3)] = abs $ (* 0.5) . fromIntegral $ x1*y2 + x2*y3 + x3*y1 - x2*y1 - x3*y2 - x1*y3
|
||||
|
||||
area :: Triangle -> Double
|
||||
area (p1, p2, p3) = shoelace' $ [p1, p2, p3]
|
||||
area (p1, p2, p3) = shoelace' [p1, p2, p3]
|
||||
where
|
||||
swapForCounterClockwise [a, b, c] = if snd a < snd b
|
||||
then [a, b, c]
|
||||
|
|
@ -62,23 +63,27 @@ getRandomPixel gen (rows, cols) =
|
|||
first3 :: [a] -> (a, a, a)
|
||||
first3 (a : b : c : _) = (a, b, c)
|
||||
|
||||
getP2 :: StdGen -> (Int, Int) -> Double -> (Int, Int)
|
||||
getP2 gen (x0, y0) r' = (x0 + x, y0 + y)
|
||||
-- colorComp :: Image_ -> (Int, Int) -> (Int, Int)
|
||||
-- colorComp img p1 p2 = comp ( p1)
|
||||
|
||||
getP2 :: Image_ -> StdGen -> (Int, Int) -> Double -> (Int, Int)
|
||||
getP2 image gen (x0, y0) r' = (x0 + x, y0 + y)
|
||||
where
|
||||
r = max 2.0 r'
|
||||
phi = fst . randomR (0.0, pi * 2) $ gen
|
||||
phi' = map (\x -> (x + phi) `mod'` (2 * pi)) [0, pi / 2, pi, 3 * pi / 2]
|
||||
x = round $ r * cos phi
|
||||
y = round $ r * sin phi
|
||||
|
||||
|
||||
getRandomTriangle :: (Int, Int) -> Maybe Double -> StdGen -> Triangle
|
||||
getRandomTriangle dims area gen = (p1, p2, p3)
|
||||
getRandomTriangle :: Image_ -> (Int, Int) -> Maybe Double -> StdGen -> Triangle
|
||||
getRandomTriangle image dims area gen = (p1, p2, p3)
|
||||
where
|
||||
p1 : p2' : _ = map (\x -> getRandomPixel x dims) genList
|
||||
|
||||
p2 = case area of
|
||||
Nothing -> p2'
|
||||
Just a -> getP2 gen1 p1 $ a * (fromIntegral $ (uncurry min) dims)
|
||||
Just a -> getP2 image gen1 p1 $ a * (fromIntegral $ (uncurry min) dims)
|
||||
|
||||
|
||||
gen0 : gen1 : genList = tail . iterate (snd . next) $ gen
|
||||
|
|
@ -158,7 +163,8 @@ getTriangleAverageRGB image triangle (y', x') = blendEqually $ pixels
|
|||
|
||||
points :: [Point]
|
||||
points = getPointsInTriangle image triangle
|
||||
|
||||
|
||||
-- I got so upset that I put this function in here instead of in general scope that I went to bed for the night.
|
||||
index' :: (Int, Int) -> Maybe Pixel_
|
||||
index' (y, x)
|
||||
| y >= y' = Nothing
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue