2017-12-26 29 views
0

私は2つの異なるイメージ(.pngのようなイメージファイルから取ったもの)を取って、別の場所に何度か別の位置に描画したいと思っています。結果の画像は画面に表示するか、新しい画像ファイルを生成するかのどちらか簡単な方にしてください。私はその新しいイメージを取って、それ以上の操作でもっと描画していくつもりですハスケル描画イメージ上のイメージ

これを可能にするハスケルライブラリはありますか?

+2

より具体的にお願いしますか?あなたは '.png'のようなイメージファイルを取得していますか?ウィンドウの画面に出力しますか?またはPDFまたはOpenGLを使用していますか?または、イメージファイルを作成しますか?何を試しましたか? –

+0

ハッケージの金額とジュニタイプをチェックしてください。 –

+0

私は多くの情報を追加しました –

答えて

1

あなたがそういったことを行うにJuicyPixelsを使用することができます。

module Triangles where 

import Codec.Picture 
import LineGraphics 

{-| Parameterize color smoothly as a function of angle -} 
colorWheel :: Float -> Colour 
colorWheel x = (r, g, b, a) 
    where 
    r = floor $ (cos x + 1) * (255/2) 
    g = floor $ (sin x + 1) * (255/2) 
    b = floor $ (cos (x+(pi/2)) + 1) * (255/2) 
    a = 255 

{-| Draw a triangle centered about the point (x, y) -} 
triangle :: Point -> Path 
triangle (x, y) = 
    [ (x - k, y - k) 
    , (x + k, y - k) 
    , (x, y + k) 
    , (x - k, y - k) 
    ] 
    where 
    size = 30 
    k = size/2 

{-| 
    Draw 'n' equally-spaced triangles at a radius of 'r' about a center 
    point, '(x, y)'. 
-} 
triangles :: Float -> Radius -> Vector -> Picture 
triangles n r (x, y) = 
    [ (colorWheel theta, tri theta) | theta <- steps n ] 
    where 
    tri theta = triangle ((r * cos theta) + x, (r * sin theta) + y) 

{-| Interpolate the range [0, 2pi] by 'n' steps -} 
steps :: Float -> [Float] 
steps n = map (\i -> i * (2*pi/n)) [0 .. n] 

を我々はコードを支援するこのモジュールを使用します:

module LineGraphics (
    Point, Vector, Line, Path, Picture, Colour, Radius, 
    black, 
    drawPicture, 
) where 

import Graphics.Rasterific hiding (Point, Vector, Line, Path, polygon) 
import Graphics.Rasterific.Texture 
import Codec.Picture 

type Radius = Float 
type Point = (Float, Float) 
type Vector = (Float, Float) 
type Line = (Point, Point) 
type Path = [Point] 
type Picture = [(Colour, Path)] 
type Colour = (Int, Int, Int, Int) -- red, green, blue, opacity 

black = (0, 0, 0, 255) 

drawPicture :: Float -> Picture -> Image PixelRGBA8 
drawPicture linewidth picture = 
    renderDrawing 800 800 (toColour black) $ 
     mapM_ renderFn picture 
    where 
    renderFn (col, path) = withTexture (uniformTexture $ toColour col) (drawPath path) 
    drawPath points = stroke linewidth JoinRound (CapRound, CapStraight 0) $ 
     polyline (map (\(x, y) -> V2 x y) points) 
    toColour (a,b,c,d) = PixelRGBA8 
     (fromIntegral a) (fromIntegral b) (fromIntegral c) (fromIntegral d) 

そしてここでは、我々が得るものです: The rendered image

+0

'1 - sin x'ではなく' cos(x +(pi/2))+ 1'を使う数値的な理由はありますか? – dfeuer

+0

いいえ、他の誰も私の基本的な三角を忘れている;) – Chris

関連する問題