Comments (16)
William 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.
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.
Hello world
from generative-art.
from generative-art.
from generative-art.
from generative-art.
from generative-art.
from generative-art.
Accident 🥴
from generative-art.
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.
from generative-art.
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.
@janilcgarcia I took your idea to triangles :-)
from generative-art.
There are no mistakes, just happy little accidents :-D
from generative-art.
from generative-art.
The ugly one have to bee as well ;)
from generative-art.
Related Issues (20)
- Hide Delaunay internals
- Doctest: Add radial plot for pseudoAngle
- Delaunay docs still mention old _accessor fields
- Hide Geometry.Algorithms.Contour.Internal
- Document args of sutherlandHodgman
- triangulate: doctest instead of testsuite test
- bezierSubdivideS: doctest not visualtest
- Doctest: consider `...` matching HOT 1
- bezierSmoothen: outdated docs
- Remose ApollonianGasket from the lib
- bezierSmoothenLoop for <= 2 points
- recurseUntilPrecision: convert example to doctest
- Add nice example for the Plotting module
- Plotting: hide TinkeringInternals and states HOT 1
- Instance plotting polyline: use vector instead of list
- Render color previews in doctests instead of testsuite HOT 1
- Haddock CI: include dependencies
- Clipping pic is broken
- Bézier subdivision: more robustness
- QC failure for pseudoAngle
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from generative-art.