Skip to content

Commit a0ea5b7

Browse files
committed
added scale_rotate example
1 parent cf83663 commit a0ea5b7

File tree

8 files changed

+123
-22
lines changed

8 files changed

+123
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![sketchy_logo_002](https://user-images.githubusercontent.com/96601789/154788295-49904170-fc0f-4de0-8e70-2c9093fdd6f1.png)
22

3-
Sketchy is a framework making generative art in Go. It is inspired by [vsketch](https://github.com/abey79/vsketch) and [openFrameworks](https://github.com/openframeworks/openFrameworks). It uses [gg](https://github.com/fogleman/gg) for drawing and the [ebiten](https://github.com/hajimehoshi/ebiten) game engine for the GUI. It's designed to provide controls (sliders) via simple JSON that can be used within a familiar `update()` and `draw()` framework to enable quick iteration on designs.
3+
Sketchy is a framework for making generative art in Go. It is inspired by [vsketch](https://github.com/abey79/vsketch) and [openFrameworks](https://github.com/openframeworks/openFrameworks). It uses [gg](https://github.com/fogleman/gg) for drawing and the [ebiten](https://github.com/hajimehoshi/ebiten) game engine for the GUI. It's designed to provide controls (sliders) via simple JSON that can be used within a familiar `update()` and `draw()` framework to enable quick iteration on designs.
44

55
Sketchy is still very much in the alpha stage. Below is an example of what the framework looks like while running the "noise" example.
66

examples/lissajous/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"flag"
45
"image/color"
56
"log"
67

@@ -33,15 +34,23 @@ func draw(s *sketchy.Sketch, c *gg.Context) {
3334
}
3435

3536
func main() {
36-
s, err := sketchy.NewSketchFromFile("config.json")
37-
s.Updater = update
38-
s.Drawer = draw
37+
var configFile string
38+
var prefix string
39+
var randomSeed int64
40+
flag.StringVar(&configFile, "c", "sketch.json", "Sketch config file")
41+
flag.StringVar(&prefix, "p", "sketch", "Output file prefix")
42+
flag.Int64Var(&randomSeed, "s", 0, "Random number generator seed")
43+
s, err := sketchy.NewSketchFromFile(configFile)
3944
if err != nil {
4045
log.Fatal(err)
4146
}
47+
s.Prefix = prefix
48+
s.RandomSeed = randomSeed
49+
s.Updater = update
50+
s.Drawer = draw
4251
s.Init()
4352
ebiten.SetWindowSize(int(s.ControlWidth+s.SketchWidth), int(s.SketchHeight))
44-
ebiten.SetWindowTitle(s.Title)
53+
ebiten.SetWindowTitle("Sketchy - " + s.Title)
4554
ebiten.SetWindowResizable(false)
4655
if err := ebiten.RunGame(s); err != nil {
4756
log.Fatal(err)
File renamed without changes.

examples/noise/main.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"flag"
5-
"fmt"
65
"log"
76

87
"github.com/aldernero/sketchy"
@@ -11,7 +10,7 @@ import (
1110
"github.com/lucasb-eyer/go-colorful"
1211
)
1312

14-
var hasShownMinMax bool = false
13+
var tick int64
1514

1615
func update(s *sketchy.Sketch) {
1716
s.Rand.SetSeed(int64(s.Var("seed")))
@@ -22,40 +21,32 @@ func update(s *sketchy.Sketch) {
2221
s.Rand.SetNoiseScaleY(s.Var("yscale"))
2322
s.Rand.SetNoiseOffsetX(s.Var("xoffset"))
2423
s.Rand.SetNoiseOffsetY(s.Var("yoffset"))
24+
s.Rand.SetNoiseScaleZ(0.005)
25+
s.Rand.SetNoiseOffsetZ(float64(tick))
26+
tick++
2527
}
2628

2729
func draw(s *sketchy.Sketch, c *gg.Context) {
2830
cellSize := s.Var("cellSize")
29-
minNoise := 100.0
30-
maxNoise := -100.0
31+
c.SetLineWidth(0)
3132
for x := 0.0; x < s.SketchWidth; x += cellSize {
3233
for y := 0.0; y < s.SketchHeight; y += cellSize {
33-
noise := s.Rand.Noise2D(x, y)
34-
if noise > maxNoise {
35-
maxNoise = noise
36-
}
37-
if noise < minNoise {
38-
minNoise = noise
39-
}
40-
hue := sketchy.Map(-1, 1, 0, 360, noise)
34+
noise := s.Rand.Noise3D(x, y, 0)
35+
hue := sketchy.Map(0, 1, 0, 360, noise)
4136
cellColor := colorful.Hsl(hue, 0.5, 0.5)
4237
c.SetColor(cellColor)
4338
c.DrawRectangle(x, y, cellSize, cellSize)
4439
c.Fill()
4540
}
4641
}
47-
if !hasShownMinMax {
48-
fmt.Println(minNoise, maxNoise)
49-
hasShownMinMax = true
50-
}
5142
}
5243

5344
func main() {
5445
var configFile string
5546
var prefix string
5647
var randomSeed int64
5748
flag.StringVar(&configFile, "c", "sketch.json", "Sketch config file")
58-
flag.StringVar(&configFile, "p", "sketch", "Output file prefix")
49+
flag.StringVar(&prefix, "p", "sketch", "Output file prefix")
5950
flag.Int64Var(&randomSeed, "s", 0, "Random number generator seed")
6051
s, err := sketchy.NewSketchFromFile(configFile)
6152
if err != nil {
File renamed without changes.

examples/scale_rotate/main.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"image/color"
6+
"log"
7+
"math"
8+
9+
"github.com/aldernero/sketchy"
10+
"github.com/fogleman/gg"
11+
"github.com/hajimehoshi/ebiten/v2"
12+
)
13+
14+
const radius = 300.0
15+
16+
func update(s *sketchy.Sketch) {
17+
// Update logic goes here
18+
// Not needed for this example
19+
}
20+
21+
func draw(s *sketchy.Sketch, c *gg.Context) {
22+
// Drawing code goes here
23+
N := int(s.Var("N"))
24+
sides := int(s.Var("sides"))
25+
rotate := sketchy.Deg2Rad(s.Var("rotate"))
26+
scale := s.Var("scale")
27+
c.SetColor(color.CMYK{
28+
C: 200,
29+
M: 0,
30+
Y: 0,
31+
K: 0,
32+
})
33+
for i := 0; i < N; i++ {
34+
x := s.SketchWidth / 2
35+
y := s.SketchHeight / 2
36+
r := math.Pow(scale, float64(i)) * radius
37+
c.DrawRegularPolygon(sides, x, y, r, float64(i)*rotate)
38+
c.Stroke()
39+
}
40+
}
41+
42+
func main() {
43+
var configFile string
44+
var prefix string
45+
var randomSeed int64
46+
flag.StringVar(&configFile, "c", "sketch.json", "Sketch config file")
47+
flag.StringVar(&prefix, "p", "sketch", "Output file prefix")
48+
flag.Int64Var(&randomSeed, "s", 0, "Random number generator seed")
49+
s, err := sketchy.NewSketchFromFile(configFile)
50+
if err != nil {
51+
log.Fatal(err)
52+
}
53+
s.Prefix = prefix
54+
s.RandomSeed = randomSeed
55+
s.Updater = update
56+
s.Drawer = draw
57+
s.Init()
58+
ebiten.SetWindowSize(int(s.ControlWidth+s.SketchWidth), int(s.SketchHeight))
59+
ebiten.SetWindowTitle("Sketchy - " + s.Title)
60+
ebiten.SetWindowResizable(false)
61+
if err := ebiten.RunGame(s); err != nil {
62+
log.Fatal(err)
63+
}
64+
}

examples/scale_rotate/sketch.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"Title": "Scale & Rotate",
3+
"Prefix": "scale_rotate",
4+
"SketchWidth": 800,
5+
"SketchHeight": 800,
6+
"ControlWidth": 240,
7+
"Controls": [
8+
{
9+
"Name": "N",
10+
"MinVal": 1,
11+
"MaxVal": 100,
12+
"Val": 30,
13+
"Incr": 1
14+
},
15+
{
16+
"Name": "sides",
17+
"MinVal": 1,
18+
"MaxVal": 100,
19+
"Val": 7,
20+
"Incr": 1
21+
},
22+
{
23+
"Name": "rotate",
24+
"MinVal": -180,
25+
"MaxVal": 180,
26+
"Val": -60,
27+
"Incr": 0.5
28+
},
29+
{
30+
"Name": "scale",
31+
"MinVal": 0,
32+
"MaxVal": 1,
33+
"Val": 0.9,
34+
"Incr": 0.01
35+
}
36+
]
37+
}
115 KB
Loading

0 commit comments

Comments
 (0)