Skip Navigation
purescript
  • Flood fill - image transition effect in 16 lines of pure JS

    cross-posted from: https://lemmy.world/post/20776659

    A quick, naive AI generated Purescript translation (quickly generated that probably doesn’t work but will help get me started later) ```

    module Main where

    import Prelude import Effect (Effect) import Effect.Aff (launchAff_) import Effect.Aff.Timer (setInterval) import Effect.DOM (window) import Web.HTML (document) import Web.HTML.Document (getElementById) import Web.HTML.Element (Element, toElement) import Web.HTML.HTMLCanvasElement (getContext2D, getCanvasElementById) import Web.HTML.Canvas.Image (newImage, getWidth, getHeight, setSrc) import Web.HTML.Canvas.CanvasRenderingContext2D (CanvasRenderingContext2D, drawImage) import Web.HTML.Types (CanvasElement, Image) import Web.DOM.Node.Types (Node)

    foreign import requestAnimationFrame :: (Effect Unit -> Effect Unit) -> Effect Unit

    -- Loads the image and begins the animation startAnimation :: Effect Unit startAnimation = do img <- newImage setSrc img "example1.jpg" canvas <- getCanvasElementById "myCanvas" context <- getContext2D canvas

    -- We defer animation start until the image is loaded imgOnLoad img (beginAnimation context img)

    -- Sets the image onload handler, safely deferring canvas drawing until the image is ready imgOnLoad :: Image -> Effect Unit -> Effect Unit imgOnLoad img action = do foreignOnload img action

    foreign import foreignOnload :: Image -> Effect Unit -> Effect Unit

    -- Initializes the animation loop beginAnimation :: CanvasRenderingContext2D -> Image -> Effect Unit beginAnimation context img = do imageWidth <- getWidth img imageHeight <- getHeight img let row = imageHeight requestAnimationFrame (animate context img row imageWidth imageHeight)

    -- Animates drawing row by row animate :: CanvasRenderingContext2D -> Image -> Int -> Int -> Int -> Effect Unit animate context img row imageWidth imageHeight = do drawImage context img 0 row imageWidth 1 0 0 imageWidth row let nextRow = if row > 0 then row - 1 else imageHeight requestAnimationFrame (animate context img nextRow imageWidth imageHeight)

    main :: Effect Unit main = do startAnimation

    ```

    5
  • How to make a quick and pretty PureScript web app

    > This video demonstrates a quick way to have something nice running with purescript (react + tailwind css + shadcn/ui components)

    > Repository: https://github.com/Zelenya/purescript-shadcn-tailwind-copypaste

    > Check out my course "How to think like a functio programmer": https://impurepics.thi.

    #fp #functionalprogramming #purescript

    0
  • Dependent Types in PureScript by Mike Solomon, creator of Deku

    dev.to Dependent Types in PureScript

    Learn a bit about PureScript, the world's favorite dependently-typed language

    Dependent Types in PureScript

    > I've seen a bit of chatter recently in the PS community about dependent types. Many of us that have been using PureScript for years love it because of its simplicity and elegance, and there has been resistance in the community to build out the complexity, both syntax-wise and implementation-wise, of a full-blown dependently-typed language à la Idris and Agda. > > But another reason that there's not much community momentum behind adding dependent types to PureScript is because PureScript already has dependent types 😁

    0
  • Purus: Purescript -> UPLC | POA #1

    0
  • Making a simple node program with Purescript

    qiita.com Making a simple node program with Purescript - Qiita

    For whatever reason, I decided at 27:00 Friday that I should make a program that would get audio fr…

    Making a simple node program with Purescript - Qiita

    > For whatever reason, I decided at 27:00 Friday that I should make a program that would get audio from videos of a Youtube channel. This article will go over the details on why and how I made this with Purescript (and some FFI).

    0
  • advancedweb.hu Intro to PureScript for TypeScript developers

    Teaser for the benefits of strongly typed pure functional programming

    Intro to PureScript for TypeScript developers
    0
  • PolyConf 15: Post FRP Frontend Programming / Bodil Stokke

    0
  • "PureScript (Maybe This Time We Get JavaScript Right)" by Bodil Stokke

    0
2 Active users