2017-12-26 33 views
0

다른 두 이미지 (.png와 같은 이미지 파일에서 가져옴)를 다른 위치로 여러 번 가져 와서 싶습니다. 결과 이미지는 화면에 표시되거나 새 이미지 파일 중 더 쉬운 것을 생성해야합니다. 나는 그 새로운 이미지를 가져 와서 더 많은 작업을 통해 더 많은 그림을 그려 보겠습니다.하스켈 이미지 위에 이미지 그리기

내가 이것을 할 수있는 하스켈 라이브러리가 있습니까?

+2

좀 더 구체적으로 알려주시겠습니까? '.png'와 같은 이미지 파일을 얻고 있습니까? 창에서 화면으로 출력 하시겠습니까? 아니면 PDF 또는 OpenGL을 사용하고 있습니까? 또는 이미지 파일을 생성 하시겠습니까? 당신은 이미 무엇을 시도 했습니까? –

+0

Hackage에서 금요일과 juicypixels를 확인하십시오. –

+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