Coder Social home page Coder Social logo

Bob 2022 picture upload about generative-art HOT 16 CLOSED

quchen avatar quchen commented on July 3, 2024
Bob 2022 picture upload

from generative-art.

Comments (16)

knuton avatar knuton commented on July 3, 2024 3

William Shatter

shatter

shatter

Code
module Main (main) where

import qualified Data.Vector as V
import qualified Graphics.Rendering.Cairo as Cairo
import System.Random.MWC

import Geometry
import Geometry.Core
import Draw

-- | Draw a 'Render' to PNG and SVG files.
drawToFiles
    :: FilePath -- ^ Output location, will store .svg and .png versions
    -> Int -- ^ Width
    -> Int -- ^ Height
    -> Cairo.Render a -- ^ Picture, parameterized by width/height
    -> IO ()
drawToFiles filename w h drawing = do
    _ <- withSurface PNG (filename ++ ".png") w h (\surface -> Cairo.renderWith surface drawing)
    _ <- withSurface SVG (filename ++ ".svg") w h (\surface -> Cairo.renderWith surface drawing)
    pure ()

-- | You can generate the output files using either:
--
-- `stack build --file-watch --exec bob-2022-workshop`
-- (slower compile time, faster execution time, works out of the box with `stack`)
--
-- `ghcid --command='stack ghci --main-is generative-art:bob-2022-workshop' --test=main -W`
-- (fast compilation, slower execution time, requires `ghcid` installation)
main :: IO ()
main = drawToFiles "bob2022/shatter" 1000 1000 $ do
    setColor white
    Cairo.paint

    let square = Polygon
            [ Vec2 100 100
            , Vec2 100 900
            , Vec2 900 900
            , Vec2 900 100
            ]
    let square = Polygon
            [ Vec2 100 100
            , Vec2 100 900
            , Vec2 900 900
            , Vec2 900 100
            ]

    for_ [ 0, 0.1..180 ] $ \angle -> do
	let sqr = transform (rotate (deg $ 90 * cos (angle/100))) square
	let sqs = transform (scaleAround (polygonCentroid sqr) (1/(angle/50+1))) sqr
        sketch sqs
        setColor (hsl 0 1 0.5 `withOpacity` 0.1)
        --Cairo.fillPreserve
        setColor (black `withOpacity` 0.1)
        Cairo.stroke
    for_ [ 0, 0.1..180 ] $ \angle -> do
	let sqr = transform (rotate (deg $ 90 * cos (angle/100))) square
	let sqs = transform (scaleAround (polygonCentroid sqr) (1/(angle/50+1))) sqr
        sketch sqs
        setColor (hsl 0 1 0.5 `withOpacity` 0.1)
        --Cairo.fillPreserve
        setColor (black `withOpacity` 0.1)
        Cairo.stroke
    for_ [ 0, 0.1..180 ] $ \angle -> do
	let sqr = transform (rotate (deg $ 27.5 * sin (angle/100))) square
	let sqs = transform (scaleAround (polygonCentroid sqr) (1/(angle/40+1))) sqr
        sketch sqs
        setColor (hsl 40 1 0.5 `withOpacity` 0.01)
        --Cairo.fillPreserve
        setColor (black `withOpacity` 0.1)
        Cairo.stroke
    for_ [ 0, 0.1..180 ] $ \angle -> do
	let sqr = transform (rotate (deg $ 45 * cos (angle/100) * sin (angle/100))) square
	let sqs = transform (scaleAround (polygonCentroid sqr) (1/(angle/40+1))) sqr
        sketch sqs
        setColor (hsl 90 1 0.5 `withOpacity` 0.01)
        --Cairo.fillPreserve
        setColor (black `withOpacity` 0.1)
        Cairo.stroke

from generative-art.

quchen avatar quchen commented on July 3, 2024 3

Just looked through this again and I must say I’m still impressed by how quickly you whipped up such nice pictures. I mean we’re talking about one hour here!

from generative-art.

knuton avatar knuton commented on July 3, 2024 2

Hello world

shatter

from generative-art.

Arkham avatar Arkham commented on July 3, 2024 2

shatter

from generative-art.

janilcgarcia avatar janilcgarcia commented on July 3, 2024 2

shatter

from generative-art.

juhp avatar juhp commented on July 3, 2024 2

truchetti

from generative-art.

fmthoma avatar fmthoma commented on July 3, 2024 1

image
image

from generative-art.

fmthoma avatar fmthoma commented on July 3, 2024 1

image

from generative-art.

knuton avatar knuton commented on July 3, 2024 1

Accident 🥴

shatter

from generative-art.

janilcgarcia avatar janilcgarcia commented on July 3, 2024 1

shatter
now I created a bias function for the color:
bias x = abs $ sin (x / pi + 0.4)

and I'm using it like this:

colorIndex <- Cairo.liftIO $ uniformRM (0, 1) gen
let color = viridis $ bias colorIndex

from generative-art.

richard-zhang avatar richard-zhang commented on July 3, 2024 1

shatter

from generative-art.

janilcgarcia avatar janilcgarcia commented on July 3, 2024

shatter
I actually introduced a bias for vertical lines with:

  randomAngle <- uniformRM (0, 4) gen
  let angles = [deg 0, deg 90, deg 90, deg 0, deg 90]

from generative-art.

fmthoma avatar fmthoma commented on July 3, 2024

@janilcgarcia I took your idea to triangles :-)

image

from generative-art.

fmthoma avatar fmthoma commented on July 3, 2024

There are no mistakes, just happy little accidents :-D

from generative-art.

fmthoma avatar fmthoma commented on July 3, 2024

image

from generative-art.

dfurmans avatar dfurmans commented on July 3, 2024

The ugly one have to bee as well ;)
image

from generative-art.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.