SlideShare a Scribd company logo
1
Procedural Content
Generation with Clojure
Mike Anderson
2
Contents
1. Procedural Content Generation
2. Introducing Clojure
3. Creating content with Clisk
3
Definition
Procedural content generation (PCG)
is the programmatic generation
of content using algorithms, which may
incorporate random or pseudo-random
processes
4
Some applications
Content Types Examples
Images
• 3D model textures
• Abstract art
Pioneering work by Ken
Perlin (inventor of Perlin
noise)
Music
• Melodies
• Synthesised sounds
Work by Jeremy
Leach
http://algorithmiccomposition.org/
Game content
• Game items
• Random maps
Roguelike games
Virtual Worlds
• Landscapes
• Plants / animals
• Alien races
No Man’s Sky
(planned release 2016)
5
Image Generation
(0,0)
y-axis
(0,1) (1,1)
(1,0)
pixel colour = f(x, y)
x-axis
6
Image “Composition”
x
f(x, y) g(x, y)
=
f(x, y) * g(x, y)
The Big Idea: Use a functional language to compose images!
7
Contents
1. Procedural Content Generation
2. Introducing Clojure
3. Creating content with Clisk
8
What is Clojure?
JVM Language
Functional Dynamic
9
Data types – The Usual
Type Representation
Long integers 42
Double precision reals 3.14159265359
Strings “Hello World”
Characters M
Hex 0xFF8000
All represented by equivalent Java
Objects “under the hood”
10
Data types – The Not-So Usual
Type Representation
Keywords :foo
Symbols 'hello
Ratios 1/3
Regexes #"[0-9]+"
BigInt 15511210043330985984000000N
BigDecimal 189675.1678969698698969986M
Base-N numbers 3r1201200
11
Data types – Collections
Type Representation
Maps {:foo 10
:bar 20}
Sets #{2 3 5 7 11 13}
Vectors [1 2 3 :foo]
Lists '(foo a b c)
All collections in Clojure are Immutable!
12
Lisp = “Lots of Irritating Silly Parentheses”?
myfunction(alpha, beta)C-like languages
(myfunction alpha beta)Lisp
Usually the same number of parentheses!
13
Expressions
Function
application
=> (+ 11 31)
42
Nested
Expressions
=> (+ 11 (* 30 30))
911
Local definitions
=> (let [x 11]
(* x 100))
1100
14
Functions
Function definition
=> (defn triple [x]
(* x 3))
=> (triple 10)
30
Higher order
functions
=> (map triple [1 2 3])
(3 6 9)
15
“Code is Data”
=> (+ 2 3)
5
=> '(+ 2 3)
(+ 2 3)
=> (eval '(+ 2 3))
5
16
Java Interop
Java myObject.doSomething(foo, bar);
Clojure (.doSomething myObject foo bar)
17
Contents
1. Procedural Content Generation
2. Introducing Clojure
3. Creating content with Clisk
18
https://github.com/mikera/clisk
To follow along:
- Clone the repo at: https://github.com/mikera/clisk
- All examples are in: src/test/clojure/clisk/workshop/
19
Collaborative spirit – all about sharing!
Open Source Project
Open Source Language
Open Source content “Recipes”
20
Example from “TweeGeeMee”
https://twitter.com/tweegeemee/status/676985464813953029
21
@TweeGeeMee twitter bot by Roger Allen
@TweeGeeMee evolved images
22
Example from “Clevolution”
https://twitter.com/deathbob/status/661294702759669760
23
Image Generation
(0,0)
y-axis
(0,1) (1,1)
(1,0)
pixel colour = [x 0 0]
x-axis
REPL
Command
(show [x 0 0])
24
Image Generation
(0,0)
y-axis
(0,1) (1,1)
(1,0)
pixel colour = [x y 0]
x-axis
REPL
Command
(show [x y 0])
25
Implementation notes
• Clisk functions actually generate ASTs
• “show” function compiles the AST into efficient low-
level code, something like*:
• Lisp makes this (comparatively) easy!
This is very simplified! The real compiled code includes support for multi-threading,
caching of texture objects, making use of fast primitive maths etc.
*
(dotimes [y height]
(dotimes [x width]
(let [colour ....calculation code....]
(.setRGB image x y colour))))
26
Many primitives
Solid colours (show [0.1 0.7 1.0])
Patterns (show (checker red pink))
Texture maps (show clojure)
27
Transformations - scaling
Base (show (checker red pink))
Scaled
(show
(scale 0.3
(checker red pink)))
28
Transformations – offsets
Base (show (checker red pink))
Offset
(show
(offset
[0.2 0.2]
(checker red pink)))
29
Transformations – warps
Base (show (checker red pink))
Warped
(show
(warp
(scale 0.2 vnoise)
(checker red pink)))
30
Noise functions
Monochomatic
noise
(show (scale 0.2 noise))
Vector noise (show (scale 0.2 vnoise))
Plasma (show (scale 0.2 plasma))
31
Live coding time!
32
Images from the Gallery: Stained Glass
(show (let [voronoi1 (voronoi :points 512)]
(v*
(v* 20.0 (voronoi-blocks :voronoi voronoi1))
(warp (voronoi-points :voronoi voronoi1) grain)))
:size 512)
Key techniques:
• Use a Voronoi map to create “cells”
• Multiply with the psuedo-random “grain” function to colour cells
33
Images from the Gallery: Mandelbrot
(show (viewport [-2 -1.5] [1 1.5]
(fractal
:while (v- 2 (length [x y]))
:update (v+ c [(v- (v* x x) (v* y y))
(v* 2 x y)])
:result (vplasma (v* 0.1 'i))
:bailout-result black
:max-iterations 1000)) :size 256)
Key techniques:
• Use the “fractal” function to create an iterative process
• Simulate complex numbers (x+ iy) using regular clisk vectors
• Use a viewport to see the relevant region of the Mandelbrot set
34
Images from the Gallery: Voronoi Fractal
(show (let [voronoi1 (voronoi :points 32)]
(fractal
:while (v- 0.97 (voronoi-function
(v- 1 (v* (vdivide (v- y x) y)
(vdivide (v- z x) z)))
:voronoi voronoi1))
:update (v+ (v* pos 2) pos)
:result (vdivide 3 (v+ 3 'i))
:max-iterations 4)) :size 512)
Key techniques:
• Voronoi map used to create a “net” pattern
• Use the “fractal” function to create iterative layers
• If it hits the net, stop
• Else continue to next layer with a scaled version of the net
3535
BACKUP / OUT

More Related Content

PPTX
Clojure for Data Science
Mike Anderson
 
PPTX
Enter The Matrix
Mike Anderson
 
PDF
Clojure for Data Science
henrygarner
 
PDF
Machine Learning Live
Mike Anderson
 
PDF
Clojure class
Aysylu Greenberg
 
PDF
From Lisp to Clojure/Incanter and RAn Introduction
elliando dias
 
PDF
Clojure: The Art of Abstraction
Alex Miller
 
PPT
Oop lecture9 13
Shahriar Robbani
 
Clojure for Data Science
Mike Anderson
 
Enter The Matrix
Mike Anderson
 
Clojure for Data Science
henrygarner
 
Machine Learning Live
Mike Anderson
 
Clojure class
Aysylu Greenberg
 
From Lisp to Clojure/Incanter and RAn Introduction
elliando dias
 
Clojure: The Art of Abstraction
Alex Miller
 
Oop lecture9 13
Shahriar Robbani
 

What's hot (20)

PDF
The Ring programming language version 1.7 book - Part 39 of 196
Mahmoud Samir Fayed
 
PDF
Coscup2021-rust-toturial
Wayne Tsai
 
PDF
Coscup2021 - useful abstractions at rust and it's practical usage
Wayne Tsai
 
PDF
Thinking Functionally In Ruby
Ross Lawley
 
PDF
Python 2.5 reference card (2009)
gekiaruj
 
PDF
The Ring programming language version 1.6 book - Part 32 of 189
Mahmoud Samir Fayed
 
PDF
Compact and safely: static DSL on Kotlin
Dmitry Pranchuk
 
KEY
R for Pirates. ESCCONF October 27, 2011
Mandi Walls
 
PDF
Rainer Grimm, “Functional Programming in C++11”
Platonov Sergey
 
PDF
Bartosz Milewski, “Re-discovering Monads in C++”
Platonov Sergey
 
PDF
Nx tutorial basics
Deepakshankar S
 
PDF
Introduction to Machine Learning
Big_Data_Ukraine
 
PDF
The Ring programming language version 1.4.1 book - Part 7 of 31
Mahmoud Samir Fayed
 
PDF
Futures e abstração - QCon São Paulo 2015
Leonardo Borges
 
PDF
The Ring programming language version 1.9 book - Part 46 of 210
Mahmoud Samir Fayed
 
PDF
The Curious Clojurist - Neal Ford (Thoughtworks)
jaxLondonConference
 
PDF
미려한 UI/UX를 위한 여정
SeungChul Kang
 
PDF
The Ring programming language version 1.6 book - Part 35 of 189
Mahmoud Samir Fayed
 
PPT
JDBC Core Concept
Rays Technologies
 
PDF
Python Cheat Sheet
GlowTouch
 
The Ring programming language version 1.7 book - Part 39 of 196
Mahmoud Samir Fayed
 
Coscup2021-rust-toturial
Wayne Tsai
 
Coscup2021 - useful abstractions at rust and it's practical usage
Wayne Tsai
 
Thinking Functionally In Ruby
Ross Lawley
 
Python 2.5 reference card (2009)
gekiaruj
 
The Ring programming language version 1.6 book - Part 32 of 189
Mahmoud Samir Fayed
 
Compact and safely: static DSL on Kotlin
Dmitry Pranchuk
 
R for Pirates. ESCCONF October 27, 2011
Mandi Walls
 
Rainer Grimm, “Functional Programming in C++11”
Platonov Sergey
 
Bartosz Milewski, “Re-discovering Monads in C++”
Platonov Sergey
 
Nx tutorial basics
Deepakshankar S
 
Introduction to Machine Learning
Big_Data_Ukraine
 
The Ring programming language version 1.4.1 book - Part 7 of 31
Mahmoud Samir Fayed
 
Futures e abstração - QCon São Paulo 2015
Leonardo Borges
 
The Ring programming language version 1.9 book - Part 46 of 210
Mahmoud Samir Fayed
 
The Curious Clojurist - Neal Ford (Thoughtworks)
jaxLondonConference
 
미려한 UI/UX를 위한 여정
SeungChul Kang
 
The Ring programming language version 1.6 book - Part 35 of 189
Mahmoud Samir Fayed
 
JDBC Core Concept
Rays Technologies
 
Python Cheat Sheet
GlowTouch
 
Ad

Viewers also liked (20)

PDF
Clojure for Java developers
John Stevenson
 
PDF
16th ALUMNI LEADERSHIP MASTERCLASS
Saviance Technologies
 
PPT
SkillPoint™ VRx Recruiting Software
Platina Software Pvt. Ltd.
 
PPTX
Sharepoint - turn on or turn off?
Workshare
 
PPTX
TLS 1.2 Internet Security Protocol: What it Means & Why You Should Give a ¢®@ϸ
AppointmentPlus
 
PPTX
Accolo - Turn your company into a hiring machine - 3-22-12 - John Younger
John Younger
 
PDF
How I learned to love the Process
Codeship
 
PDF
Marketing To Asian Women Conference Singapore
One9Ninety
 
PDF
Is PPM Enough?
Digite Inc
 
PPTX
EuroCloud Netherlands Launch
Jan Aleman
 
PPSX
4 habilidades de un líder
Safi
 
PDF
Applicant Tracking System - LetmeRecruit
LetmeRecruit
 
PDF
Advanced Recurring Contract Billing
Binary Stream Software
 
PDF
Igor Vuksanović - Kako bankrotirati pri izradi poslovne aplikacije (IT Showoff)
IT Showoff
 
PPTX
10 Must Haves in an Effective Recurring Revenue Management Solution
Aria Systems, Inc.
 
PPTX
Navantis & Microsoft "Find Your Silver Lining in the Cloud" Event Slidedeck
Navantis
 
PDF
Imex Smart Cities
Imex Systems Inc.
 
PDF
Bim advancements
Bentley Systems
 
PDF
Stamplay 101
Stamplay
 
Clojure for Java developers
John Stevenson
 
16th ALUMNI LEADERSHIP MASTERCLASS
Saviance Technologies
 
SkillPoint™ VRx Recruiting Software
Platina Software Pvt. Ltd.
 
Sharepoint - turn on or turn off?
Workshare
 
TLS 1.2 Internet Security Protocol: What it Means & Why You Should Give a ¢®@ϸ
AppointmentPlus
 
Accolo - Turn your company into a hiring machine - 3-22-12 - John Younger
John Younger
 
How I learned to love the Process
Codeship
 
Marketing To Asian Women Conference Singapore
One9Ninety
 
Is PPM Enough?
Digite Inc
 
EuroCloud Netherlands Launch
Jan Aleman
 
4 habilidades de un líder
Safi
 
Applicant Tracking System - LetmeRecruit
LetmeRecruit
 
Advanced Recurring Contract Billing
Binary Stream Software
 
Igor Vuksanović - Kako bankrotirati pri izradi poslovne aplikacije (IT Showoff)
IT Showoff
 
10 Must Haves in an Effective Recurring Revenue Management Solution
Aria Systems, Inc.
 
Navantis & Microsoft "Find Your Silver Lining in the Cloud" Event Slidedeck
Navantis
 
Imex Smart Cities
Imex Systems Inc.
 
Bim advancements
Bentley Systems
 
Stamplay 101
Stamplay
 
Ad

Similar to Procedural Content Generation with Clojure (20)

PDF
We Must Go Deeper
The Software House
 
PDF
(Fun clojure)
Timo Sulg
 
PDF
A gentle introduction to functional programming through music and clojure
Paul Lam
 
PDF
Three.js basics
Vasilika Klimova
 
PDF
[PR12] You Only Look Once (YOLO): Unified Real-Time Object Detection
Taegyun Jeon
 
PDF
Rust tutorial from Boston Meetup 2015-07-22
nikomatsakis
 
PDF
Web 2 . .3 Development Services
Theawaster485
 
PPTX
Minecraft in 500 lines with Pyglet - PyCon UK
Richard Donkin
 
PDF
Rust "Hot or Not" at Sioux
nikomatsakis
 
PDF
Rust: Reach Further
nikomatsakis
 
PDF
Learn Python 3 for absolute beginners
KingsleyAmankwa
 
PPTX
Python in 30 minutes!
Fariz Darari
 
PDF
3D everywhere
Vasilika Klimova
 
PDF
Web 2 . 0 .Zero Coding Services
Theawaster485
 
PDF
The Ring programming language version 1.10 book - Part 22 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 15 of 184
Mahmoud Samir Fayed
 
PPT
OWC 2012 (Open Web Camp)
Oswald Campesato
 
PDF
The Ring programming language version 1.8 book - Part 19 of 202
Mahmoud Samir Fayed
 
PDF
Concepts of Functional Programming for Java Brains (2010)
Peter Kofler
 
We Must Go Deeper
The Software House
 
(Fun clojure)
Timo Sulg
 
A gentle introduction to functional programming through music and clojure
Paul Lam
 
Three.js basics
Vasilika Klimova
 
[PR12] You Only Look Once (YOLO): Unified Real-Time Object Detection
Taegyun Jeon
 
Rust tutorial from Boston Meetup 2015-07-22
nikomatsakis
 
Web 2 . .3 Development Services
Theawaster485
 
Minecraft in 500 lines with Pyglet - PyCon UK
Richard Donkin
 
Rust "Hot or Not" at Sioux
nikomatsakis
 
Rust: Reach Further
nikomatsakis
 
Learn Python 3 for absolute beginners
KingsleyAmankwa
 
Python in 30 minutes!
Fariz Darari
 
3D everywhere
Vasilika Klimova
 
Web 2 . 0 .Zero Coding Services
Theawaster485
 
The Ring programming language version 1.10 book - Part 22 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 15 of 184
Mahmoud Samir Fayed
 
OWC 2012 (Open Web Camp)
Oswald Campesato
 
The Ring programming language version 1.8 book - Part 19 of 202
Mahmoud Samir Fayed
 
Concepts of Functional Programming for Java Brains (2010)
Peter Kofler
 

Recently uploaded (20)

PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
This slide provides an overview Technology
mineshkharadi333
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 

Procedural Content Generation with Clojure