Twinside / Rasterific

A drawing engine in Haskell
BSD 3-Clause "New" or "Revised" License
140 stars 11 forks source link

Discontinuousinous paths and fill-rules #3

Closed jeffreyrosenbluth closed 10 years ago

jeffreyrosenbluth commented 10 years ago

It will be very difficult to implement a fully featured diagrams backend without the ability to create discontinuous paths and without a built in way to choose a fill-rule Take a look at the diagrams User manual, in particular:

The Path section of: http://projects.haskell.org/diagrams/doc/manual.html#trails-and-paths

and

http://projects.haskell.org/diagrams/doc/manual.html#fill-rules

[CubicBezierPrim (CubicBezier {_cBezierX0 = V2 572.7273 300.0, _cBezierX1 = V2 572.7273 149.37689, _cBezierX2 = V2 450.62314 27.272736, _cBezierX3 = V2 300.00003 27.272736}),CubicBezierPrim (CubicBezier {_cBezierX0 = V2 300.0 27.272728, _cBezierX1 = V2 149.37689 27.272728, _cBezierX2 = V2 27.272736 149.37689, _cBezierX3 = V2 27.272736 300.0}),CubicBezierPrim (CubicBezier {_cBezierX0 = V2 27.272728 300.0, _cBezierX1 = V2 27.272728 450.6231, _cBezierX2 = V2 149.37689 572.7273, _cBezierX3 = V2 300.0 572.7273}),CubicBezierPrim (CubicBezier {_cBezierX0 = V2 300.0 572.7273, _cBezierX1 = V2 450.6231 572.7273, _cBezierX2 = V2 572.7273 450.62314, _cBezierX3 = V2 572.7273 300.00003}),CubicBezierPrim (CubicBezier {_cBezierX0 = V2 481.81818 300.0, _cBezierX1 = V2 481.81818 400.4154, _cBezierX2 = V2 400.4154 481.81818, _cBezierX3 = V2 300.0 481.81818}),CubicBezierPrim (CubicBezier {_cBezierX0 = V2 300.0 481.81818, _cBezierX1 = V2 199.5846 481.81818, _cBezierX2 = V2 118.18182 400.4154, _cBezierX3 = V2 118.18182 300.0}),CubicBezierPrim (CubicBezier {_cBezierX0 = V2 118.181816 300.0, _cBezierX1 = V2 118.181816 199.5846, _cBezierX2 = V2 199.5846 118.18182, _cBezierX3 = V2 300.0 118.18182}),CubicBezierPrim (CubicBezier {_cBezierX0 = V2 300.0 118.181816, _cBezierX1 = V2 400.4154 118.181816, _cBezierX2 = V2 481.81818 199.5846, _cBezierX3 = V2 481.81818 300.0})]

jeffreyrosenbluth commented 10 years ago

Maybe this is a little simpler.

[LinePrim (Line {_lineX0 = V2 572.7273 572.7273, _lineX1 = V2 572.7273 27.272766}),LinePrim (Line {_lineX0 = V2 572.7273 27.272728, _lineX1 = V2 27.272766 27.272728}),LinePrim (Line {_lineX0 = V2 27.272728 27.272728, _lineX1 = V2 27.272728 572.72723}),LinePrim (Line {_lineX0 = V2 27.272728 572.7273, _lineX1 = V2 572.72723 572.7273}),LinePrim (Line {_lineX0 = V2 481.81818 481.81818, _lineX1 = V2 118.18182 481.81818}),LinePrim (Line {_lineX0 = V2 118.181816 481.81818, _lineX1 = V2 118.181816 118.18182}),LinePrim (Line {_lineX0 = V2 118.181816 118.181816, _lineX1 = V2 481.81818 118.181816}),LinePrim (Line {_lineX0 = V2 481.81818 118.181816, _lineX1 = V2 481.81818 481.81818})]

jeffreyrosenbluth commented 10 years ago
import Codec.Picture( PixelRGBA8( .. ), writePng )
import Graphics.Rasterific
import Graphics.Rasterific.Texture

main :: IO ()
main = do
 let white = PixelRGBA8 255 255 255 255
     drawColor = PixelRGBA8 0 0x86 0xc1 255
     recColor = PixelRGBA8 0xFF 0x53 0x73 255
     img = renderDrawing 600 600 white $
        withTexture (uniformTexture drawColor) $ do
           stroke 5 (JoinMiter 0) (CapStraight 0, CapStraight 0) [LinePrim (Line {_lineX0 = V2 572.7273 572.7273, _lineX1 = V2 572.7273 27.272766}),LinePrim (Line {_lineX0 = V2 572.7273 27.272728, _lineX1 = V2 27.272766 27.272728}),LinePrim (Line {_lineX0 = V2 27.272728 27.272728, _lineX1 = V2 27.272728 572.72723}),LinePrim (Line {_lineX0 = V2 27.272728 572.7273, _lineX1 = V2 572.72723 572.7273}),LinePrim (Line {_lineX0 = V2 481.81818 481.81818, _lineX1 = V2 118.18182 481.81818}),LinePrim (Line {_lineX0 = V2 118.181816 481.81818, _lineX1 = V2 118.181816 118.18182}),LinePrim (Line {_lineX0 = V2 118.181816 118.181816, _lineX1 = V2 481.81818 118.181816}),LinePrim (Line {_lineX0 = V2 481.81818 118.181816, _lineX1 = V2 481.81818 481.81818})]

 writePng "rast.png" img
Twinside commented 10 years ago

My last commit should avoid crash, I let the ticket open to remind me about the fill-rule