Debian Codegraph @

vendor/github.com/xyproto/gfx/README.md

raw
1 # gfx
2
3 [![Build status](https://github.com/xyproto/gfx/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/xyproto/gfx/actions/workflows/test.yml)
4 [![Go Report Card](https://goreportcard.com/badge/github.com/xyproto/gfx?style=flat)](https://goreportcard.com/report/github.com/xyproto/gfx)
5 [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://pkg.go.dev/github.com/xyproto/gfx)
6 [![License MIT](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/xyproto/gfx#license-mit)
7
8 This is a fork of github.com/peterhellberg/gfx, with very few changes.
9
10 #### :warning: NO STABILITY GUARANTEES :warning:
11
12 ## Triangles
13
14 Triangles can be drawn to an image using a `*gfx.DrawTarget`.
15
16 ![gfx-triangles](examples/gfx-example-triangles/gfx-example-triangles.png)
17
18 [embedmd]:# (examples/gfx-example-triangles/gfx-example-triangles.go)
19 ```go
20 package main
21
22 import "github.com/xyproto/gfx"
23
24 var p = gfx.PaletteFamicube
25
26 func main() {
27 n := 50
28 m := gfx.NewPaletted(900, 270, p, p.Color(n+7))
29 t := gfx.NewDrawTarget(m)
30
31 t.MakeTriangles(&gfx.TrianglesData{
32 vx(114, 16, n+1), vx(56, 142, n+2), vx(352, 142, n+3),
33 vx(350, 142, n+4), vx(500, 50, n+5), vx(640, 236, n+6),
34 vx(640, 70, n+8), vx(820, 160, n+9), vx(670, 236, n+10),
35 }).Draw()
36
37 gfx.SavePNG("gfx-example-triangles.png", m)
38 }
39
40 func vx(x, y float64, n int) gfx.Vertex {
41 return gfx.Vertex{Position: gfx.V(x, y), Color: p.Color(n)}
42 }
43 ```
44
45
46 ## Polygons
47
48 A `gfx.Polygon` is represented by a list of vectors.
49 There is also `gfx.Polyline` which is a slice of polygons forming a line.
50
51 ![gfx-example-polygon](examples/gfx-example-polygon/gfx-example-polygon.png)
52
53 [embedmd]:# (examples/gfx-example-polygon/gfx-example-polygon.go)
54 ```go
55 package main
56
57 import "github.com/xyproto/gfx"
58
59 var edg32 = gfx.PaletteEDG32
60
61 func main() {
62 m := gfx.NewNRGBA(gfx.IR(0, 0, 1024, 256))
63 p := gfx.Polygon{
64 {80, 40},
65 {440, 60},
66 {700, 200},
67 {250, 230},
68 {310, 140},
69 }
70
71 p.EachPixel(m, func(x, y int) {
72 pv := gfx.IV(x, y)
73 l := pv.To(p.Rect().Center()).Len()
74
75 gfx.Mix(m, x, y, edg32.Color(int(l/18)%32))
76 })
77
78 for n, v := range p {
79 c := edg32.Color(n * 4)
80
81 gfx.DrawCircle(m, v, 15, 8, gfx.ColorWithAlpha(c, 96))
82 gfx.DrawCircle(m, v, 16, 1, c)
83 }
84
85 gfx.SavePNG("gfx-example-polygon.png", m)
86 }
87 ```
88
89
90 ## Blocks
91
92 You can draw (isometric) blocks using the `gfx.Blocks` and `gfx.Block` types.
93
94 ![gfx-example-blocks](examples/gfx-example-blocks/gfx-example-blocks.png)
95
96 [embedmd]:# (examples/gfx-example-blocks/gfx-example-blocks.go)
97 ```go
98 package main
99
100 import "github.com/xyproto/gfx"
101
102 func main() {
103 var (
104 dst = gfx.NewPaletted(898, 330, gfx.PaletteGo, gfx.PaletteGo[14])
105 rect = gfx.BoundsToRect(dst.Bounds())
106 origin = rect.Center().ScaledXY(gfx.V(1.5, -2.5)).Vec3(0.55)
107 blocks gfx.Blocks
108 )
109
110 for i, bc := range gfx.BlockColorsGo {
111 var (
112 f = float64(i) + 0.5
113 v = f * 11
114 pos = gfx.V3(290+(v*3), 8.5*v, 9*(f+2))
115 size = gfx.V3(90, 90, 90)
116 )
117
118 blocks.AddNewBlock(pos, size, bc)
119 }
120
121 blocks.Draw(dst, origin)
122
123 gfx.SavePNG("gfx-example-blocks.png", dst)
124 }
125 ```
126
127 ## Signed Distance Functions
128
129 The `gfx.SignedDistance` type allows you to use basic [signed distance functions](http://jamie-wong.com/2016/07/15/ray-marching-signed-distance-functions/) (and operations) to produce some interesting graphics.
130
131 ![gfx-example-sdf](examples/gfx-example-sdf/gfx-example-sdf.png)
132
133 [embedmd]:# (examples/gfx-example-sdf/gfx-example-sdf.go)
134 ```go
135 package main
136
137 import "github.com/xyproto/gfx"
138
139 func main() {
140 c := gfx.PaletteEDG36.Color
141 m := gfx.NewImage(1024, 256, c(5))
142
143 gfx.EachPixel(m.Bounds(), func(x, y int) {
144 sd := gfx.SignedDistance{gfx.IV(x, y)}
145
146 if d := sd.OpRepeat(gfx.V(128, 128), func(sd gfx.SignedDistance) float64 {
147 return sd.OpSubtraction(sd.Circle(50), sd.Line(gfx.V(0, 0), gfx.V(64, 64)))
148 }); d < 40 {
149 m.Set(x, y, c(int(gfx.MathAbs(d/5))))
150 }
151 })
152
153 gfx.SavePNG("gfx-example-sdf.png", m)
154 }
155 ```
156
157 ## Domain Coloring
158
159 You can use the `CmplxPhaseAt` method on a `gfx.Palette` to do [domain coloring](https://en.wikipedia.org/wiki/Domain_coloring).
160
161 ![gfx-example-domain-coloring](examples/gfx-example-domain-coloring/gfx-example-domain-coloring.png)
162
163 [embedmd]:# (examples/gfx-example-domain-coloring/gfx-example-domain-coloring.go)
164 ```go
165 package main
166
167 import "github.com/xyproto/gfx"
168
169 const (
170 w, h = 1800, 540
171 fovY = 1.9
172 aspectRatio = float64(w) / float64(h)
173 centerReal = 0
174 centerImag = 0
175 ahc = aspectRatio*fovY/2.0 + centerReal
176 hfc = fovY/2.0 + centerImag
177 )
178
179 func pixelCoordinates(px, py int) gfx.Vec {
180 return gfx.V(
181 ((float64(px)/(w-1))*2-1)*ahc,
182 ((float64(h-py-1)/(h-1))*2-1)*hfc,
183 )
184 }
185
186 func main() {
187 var (
188 p = gfx.PaletteEN4
189 p0 = pixelCoordinates(0, 0)
190 p1 = pixelCoordinates(w-1, h-1)
191 y = p0.Y
192 d = gfx.V((p1.X-p0.X)/(w-1), (p1.Y-p0.Y)/(h-1))
193 m = gfx.NewImage(w, h)
194 )
195
196 for py := 0; py < h; py++ {
197 x := p0.X
198
199 for px := 0; px < w; px++ {
200 cc := p.CmplxPhaseAt(gfx.CmplxCos(gfx.CmplxSin(0.42 / complex(y*x, x*x))))
201
202 m.Set(px, py, cc)
203
204 x += d.X
205 }
206
207 y += d.Y
208 }
209
210 gfx.SavePNG("gfx-example-domain-coloring.png", m)
211 }
212 ```
213
214 ## Animation
215
216 There is rudimentary support for making animations using `gfx.Animation`, the animations can then be encoded into GIF.
217
218 ![gfx-example-animation](examples/gfx-example-animation/gfx-example-animation.gif)
219
220 [embedmd]:# (examples/gfx-example-animation/gfx-example-animation.go)
221 ```go
222 package main
223
224 import "github.com/xyproto/gfx"
225
226 func main() {
227 a := &gfx.Animation{}
228 p := gfx.PaletteEDG36
229
230 var fireflower = []uint8{
231 0, 1, 1, 1, 1, 1, 1, 0,
232 1, 1, 2, 2, 2, 2, 1, 1,
233 1, 2, 3, 3, 3, 3, 2, 1,
234 1, 1, 2, 2, 2, 2, 1, 1,
235 0, 1, 1, 1, 1, 1, 1, 0,
236 0, 0, 0, 4, 4, 0, 0, 0,
237 0, 0, 0, 4, 4, 0, 0, 0,
238 4, 4, 0, 4, 4, 0, 4, 4,
239 0, 4, 0, 4, 4, 0, 4, 0,
240 0, 4, 4, 4, 4, 4, 4, 0,
241 0, 0, 4, 4, 4, 4, 0, 0,
242 }
243
244 for i := 0; i < len(p)-4; i++ {
245 t := gfx.NewTile(p[i:i+4], 8, fireflower)
246
247 a.AddPalettedImage(gfx.NewScaledPalettedImage(t, 20))
248 }
249
250 a.SaveGIF("gfx-example-animation.gif")
251 }
252 ```
253
254 ## Line drawing
255
256 ### DrawInt functions
257
258 Drawing functions based on [TinyDraw](https://github.com/tinygo-org/tinydraw),
259 which in turn is based on the [Adafruit GFX library](https://github.com/adafruit/Adafruit-GFX-Library).
260
261 ![gfx-example-draw-int](examples/gfx-example-draw-int/gfx-example-draw-int.png)
262
263 [embedmd]:# (examples/gfx-example-draw-int/gfx-example-draw-int.go)
264 ```go
265 package main
266
267 import "github.com/xyproto/gfx"
268
269 func main() {
270 m := gfx.NewImage(160, 128, gfx.ColorTransparent)
271
272 p := gfx.PaletteNight16
273
274 gfx.DrawIntLine(m, 10, 10, 94, 10, p.Color(0))
275 gfx.DrawIntLine(m, 94, 16, 10, 16, p.Color(1))
276 gfx.DrawIntLine(m, 10, 20, 10, 118, p.Color(2))
277 gfx.DrawIntLine(m, 16, 118, 16, 20, p.Color(4))
278
279 gfx.DrawIntLine(m, 40, 40, 80, 80, p.Color(5))
280 gfx.DrawIntLine(m, 40, 40, 80, 70, p.Color(6))
281 gfx.DrawIntLine(m, 40, 40, 80, 60, p.Color(7))
282 gfx.DrawIntLine(m, 40, 40, 80, 50, p.Color(8))
283 gfx.DrawIntLine(m, 40, 40, 80, 40, p.Color(9))
284
285 gfx.DrawIntLine(m, 100, 100, 40, 100, p.Color(10))
286 gfx.DrawIntLine(m, 100, 100, 40, 90, p.Color(11))
287 gfx.DrawIntLine(m, 100, 100, 40, 80, p.Color(12))
288 gfx.DrawIntLine(m, 100, 100, 40, 70, p.Color(13))
289 gfx.DrawIntLine(m, 100, 100, 40, 60, p.Color(14))
290 gfx.DrawIntLine(m, 100, 100, 40, 50, p.Color(15))
291
292 gfx.DrawIntRectangle(m, 30, 106, 120, 20, p.Color(14))
293 gfx.DrawIntFilledRectangle(m, 34, 110, 112, 12, p.Color(8))
294
295 gfx.DrawIntCircle(m, 120, 30, 20, p.Color(5))
296 gfx.DrawIntFilledCircle(m, 120, 30, 16, p.Color(4))
297
298 gfx.DrawIntTriangle(m, 120, 102, 100, 80, 152, 46, p.Color(9))
299 gfx.DrawIntFilledTriangle(m, 119, 98, 105, 80, 144, 54, p.Color(6))
300
301 s := gfx.NewScaledImage(m, 6)
302
303 gfx.SavePNG("gfx-example-draw-int.png", s)
304 }
305 ```
306
307 ### Bresenham's line algorithm
308
309 `gfx.DrawLineBresenham` draws a line using [Bresenham's line algorithm](http://en.wikipedia.org/wiki/Bresenham's_line_algorithm).
310
311 ![gfx-example-bresenham-line](examples/gfx-example-bresenham-line/gfx-example-bresenham-line.png)
312
313 [embedmd]:# (examples/gfx-example-bresenham-line/gfx-example-bresenham-line.go)
314 ```go
315 package main
316
317 import "github.com/xyproto/gfx"
318
319 var (
320 red = gfx.BlockColorRed.Medium
321 green = gfx.BlockColorGreen.Medium
322 blue = gfx.BlockColorBlue.Medium
323 )
324
325 func main() {
326 m := gfx.NewImage(32, 16, gfx.ColorTransparent)
327
328 gfx.DrawLineBresenham(m, gfx.V(2, 2), gfx.V(2, 14), red)
329 gfx.DrawLineBresenham(m, gfx.V(6, 2), gfx.V(32, 2), green)
330 gfx.DrawLineBresenham(m, gfx.V(6, 6), gfx.V(30, 14), blue)
331
332 s := gfx.NewScaledImage(m, 16)
333
334 gfx.SavePNG("gfx-example-bresenham-line.png", s)
335 }
336 ```
337
338 ## Geometry and Transformation
339
340 The (2D) geometry and transformation types are based on those found in <https://github.com/faiface/pixel> (but indended for use without Pixel)
341
342 ### 2D types
343
344 #### Vec
345
346 `gfx.Vec` is a 2D vector type with X and Y components.
347
348 #### Rect
349
350 `gfx.Rect` is a 2D rectangle aligned with the axes of the coordinate system. It is defined by two `gfx.Vec`, Min and Max.
351
352 #### Matrix
353
354 `gfx.Matrix` is a 2x3 affine matrix that can be used for all kinds of spatial transforms, such as movement, scaling and rotations.
355
356 ![gfx-readme-examples-matrix](https://user-images.githubusercontent.com/565124/51478881-f8e69a00-1d8c-11e9-92c5-270c767dfc06.gif)
357
358 [embedmd]:# (examples/gfx-example-matrix/gfx-example-matrix.go)
359 ```go
360 package main
361
362 import "github.com/xyproto/gfx"
363
364 var en4 = gfx.PaletteEN4
365
366 func main() {
367 a := &gfx.Animation{Delay: 10}
368
369 c := gfx.V(128, 128)
370
371 p := gfx.Polygon{
372 {50, 50},
373 {50, 206},
374 {128, 96},
375 {206, 206},
376 {206, 50},
377 }
378
379 for d := 0.0; d < 360; d += 2 {
380 m := gfx.NewPaletted(256, 256, en4, en4.Color(3))
381
382 matrix := gfx.IM.RotatedDegrees(c, d)
383
384 gfx.DrawPolygon(m, p.Project(matrix), 0, en4.Color(2))
385 gfx.DrawPolygon(m, p.Project(matrix.Scaled(c, 0.5)), 0, en4.Color(1))
386
387 gfx.DrawCircleFilled(m, c, 5, en4.Color(0))
388
389 a.AddPalettedImage(m)
390 }
391
392 a.SaveGIF("/tmp/gfx-readme-examples-matrix.gif")
393 }
394 ```
395
396 ### 3D types
397
398 #### Vec3
399
400 `gfx.Vec3` is a 3D vector type with X, Y and Z components.
401
402 #### Box
403
404 `gfx.Box` is a 3D box. It is defined by two `gfx.Vec3`, Min and Max
405
406 ## Errors
407
408 The `gfx.Error` type is a string that implements the `error` interface.
409
410 > If you are using [Ebiten](https://github.com/hajimehoshi/ebiten) then you can return the provided `gfx.ErrDone` error to exit its run loop.
411
412 ## HTTP
413
414 You can use `gfx.GetPNG` to download and decode a PNG given an URL.
415
416 ## Log
417
418 I find that it is fairly common for me to do some logging driven development
419 when experimenting with graphical effects, so I've included `gfx.Log`,
420 `gfx.Dump`, `gfx.Printf` and `gfx.Sprintf` in this package.
421
422 ## Math
423
424 I have included a few functions that call functions in the `math` package.
425
426 There is also `gfx.Sign`, `gfx.Clamp` and `gfx.Lerp` functions for `float64`.
427
428 ## Cmplx
429
430 I have included a few functions that call functions in the `cmplx` package.
431
432 ## Reading files
433
434 It is fairly common to read files in my experiments, so I've included `gfx.ReadFile` and `gfx.ReadJSON` in this package.
435
436 ## Resizing images
437
438 You can use `gfx.ResizeImage` to resize an image. (nearest neighbor, mainly useful for pixelated graphics)
439
440 ## Noise
441
442 Different types of noise is often used in procedural generation.
443
444 ### SimplexNoise
445
446 SimplexNoise is a speed-improved simplex noise algorithm for 2D, 3D and 4D.
447
448 ![gfx-example-simplex](examples/gfx-example-simplex/gfx-example-simplex.png)
449
450 [embedmd]:# (examples/gfx-example-simplex/gfx-example-simplex.go)
451 ```go
452 package main
453
454 import "github.com/xyproto/gfx"
455
456 func main() {
457 sn := gfx.NewSimplexNoise(17)
458
459 dst := gfx.NewImage(1024, 256)
460
461 gfx.EachImageVec(dst, gfx.ZV, func(u gfx.Vec) {
462 n := sn.Noise2D(u.X/900, u.Y/900)
463 c := gfx.PaletteSplendor128.At(n / 2)
464
465 gfx.SetVec(dst, u, c)
466 })
467
468 gfx.SavePNG("gfx-example-simplex.png", dst)
469 }
470 ```
471
472 ## Colors
473
474 You can construct new colors using `gfx.ColorRGBA`, `gfx.ColorNRGBA`, `gfx.ColorGray`, `gfx.ColorGray16` and `gfx.ColorWithAlpha`.
475
476 There is also a `gfx.LerpColors` function that performs linear interpolation between two colors.
477
478 ### Default colors
479
480 There are a few default colors in this package, convenient when you just want to experiment,
481 for more ambitious projects I suggest creating a `gfx.Palette` (or even use one of the included palettes).
482
483
484 | Variable | Color
485 |------------------------|---------------------------------------------------------
486 | `gfx.ColorBlack` | ![gfx.ColorBlack](examples/gfx-colors/gfx-ColorBlack.png)
487 | `gfx.ColorWhite` | ![gfx.ColorWhite](examples/gfx-colors/gfx-ColorWhite.png)
488 | `gfx.ColorTransparent` | ![gfx.ColorTransparent](examples/gfx-colors/gfx-ColorTransparent.png)
489 | `gfx.ColorOpaque` | ![gfx.ColorOpaque](examples/gfx-colors/gfx-ColorOpaque.png)
490 | `gfx.ColorRed` | ![gfx.ColorRed](examples/gfx-colors/gfx-ColorRed.png)
491 | `gfx.ColorGreen` | ![gfx.ColorGreen](examples/gfx-colors/gfx-ColorGreen.png)
492 | `gfx.ColorBlue` | ![gfx.ColorBlue](examples/gfx-colors/gfx-ColorBlue.png)
493 | `gfx.ColorCyan` | ![gfx.ColorCyan](examples/gfx-colors/gfx-ColorCyan.png)
494 | `gfx.ColorMagenta` | ![gfx.ColorMagenta](examples/gfx-colors/gfx-ColorMagenta.png)
495 | `gfx.ColorYellow` | ![gfx.ColorYellow](examples/gfx-colors/gfx-ColorYellow.png)
496
497 ### Block colors
498
499 Each `gfx.BlockColor` consists of a `Dark`, `Medium` and `Light` shade of the same color.
500
501
502 | Variable | Block Color
503 |------------------------------|---------------------------------------------------------
504 | `gfx.BlockColorYellow` | ![gfx.BlockColorYellow](examples/gfx-colors/gfx-BlockColorYellow.png)
505 | `gfx.BlockColorOrange` | ![gfx.BlockColorOrange](examples/gfx-colors/gfx-BlockColorOrange.png)
506 | `gfx.BlockColorBrown` | ![gfx.BlockColorBrown](examples/gfx-colors/gfx-BlockColorBrown.png)
507 | `gfx.BlockColorGreen` | ![gfx.BlockColorGreen](examples/gfx-colors/gfx-BlockColorGreen.png)
508 | `gfx.BlockColorBlue` | ![gfx.BlockColorBlue](examples/gfx-colors/gfx-BlockColorBlue.png)
509 | `gfx.BlockColorPurple` | ![gfx.BlockColorPurple](examples/gfx-colors/gfx-BlockColorPurple.png)
510 | `gfx.BlockColorRed` | ![gfx.BlockColorRed](examples/gfx-colors/gfx-BlockColorRed.png)
511 | `gfx.BlockColorWhite` | ![gfx.BlockColorWhite](examples/gfx-colors/gfx-BlockColorWhite.png)
512 | `gfx.BlockColorBlack` | ![gfx.BlockColorBlack](examples/gfx-colors/gfx-BlockColorBlack.png)
513 | `gfx.BlockColorGoGopherBlue` | ![gfx.BlockColorGoGopherBlue](examples/gfx-colors/gfx-BlockColorGoGopherBlue.png)
514 | `gfx.BlockColorGoLightBlue` | ![gfx.BlockColorGoLightBlue](examples/gfx-colors/gfx-BlockColorGoLightBlue.png)
515 | `gfx.BlockColorGoAqua` | ![gfx.BlockColorGoAqua](examples/gfx-colors/gfx-BlockColorGoAqua.png)
516 | `gfx.BlockColorGoFuchsia` | ![gfx.BlockColorGoFuchsia](examples/gfx-colors/gfx-BlockColorGoFuchsia.png)
517 | `gfx.BlockColorGoBlack` | ![gfx.BlockColorGoBlack](examples/gfx-colors/gfx-BlockColorGoBlack.png)
518 | `gfx.BlockColorGoYellow` | ![gfx.BlockColorGoYellow](examples/gfx-colors/gfx-BlockColorGoYellow.png)
519
520
521 ### Palettes
522
523 There are a number of palettes in the `gfx` package,
524 most of them are found in the [Lospec Palette List](https://lospec.com/palette-list/).
525
526
527 | Variable | Colors | Lospec Palette
528 |----------------------------|-------:| -----------------------------------------------------
529 | `gfx.Palette1Bit` | 2 | ![Palette1Bit](examples/gfx-palettes/gfx-Palette1Bit.png)
530 | `gfx.Palette2BitGrayScale` | 4 | ![Palette2BitGrayScale](examples/gfx-palettes/gfx-Palette2BitGrayScale.png)
531 | `gfx.PaletteEN4` | 4 | ![PaletteEN4](examples/gfx-palettes/gfx-PaletteEN4.png)
532 | `gfx.PaletteARQ4` | 4 | ![PaletteARQ4](examples/gfx-palettes/gfx-PaletteARQ4.png)
533 | `gfx.PaletteInk` | 5 | ![PaletteInk](examples/gfx-palettes/gfx-PaletteInk.png)
534 | `gfx.Palette3Bit` | 8 | ![Palette3Bit](examples/gfx-palettes/gfx-Palette3Bit.png)
535 | `gfx.PaletteEDG8` | 8 | ![PaletteEDG8](examples/gfx-palettes/gfx-PaletteEDG8.png)
536 | `gfx.PaletteAmmo8` | 8 | ![PaletteAmmo8](examples/gfx-palettes/gfx-PaletteAmmo8.png)
537 | `gfx.PaletteNYX8` | 8 | ![PaletteNYX8](examples/gfx-palettes/gfx-PaletteNYX8.png)
538 | `gfx.Palette15PDX` | 15 | ![Palette15PDX](examples/gfx-palettes/gfx-Palette15PDX.png)
539 | `gfx.PaletteCGA` | 16 | ![PaletteCGA](examples/gfx-palettes/gfx-PaletteCGA.png)
540 | `gfx.PalettePICO8` | 16 | ![PalettePICO8](examples/gfx-palettes/gfx-PalettePICO8.png)
541 | `gfx.PaletteNight16` | 16 | ![PaletteNight16](examples/gfx-palettes/gfx-PaletteNight16.png)
542 | `gfx.PaletteAAP16` | 16 | ![PaletteAAP16](examples/gfx-palettes/gfx-PaletteAAP16.png)
543 | `gfx.PaletteArne16` | 16 | ![PaletteArne16](examples/gfx-palettes/gfx-PaletteArne16.png)
544 | `gfx.PaletteEDG16` | 16 | ![PaletteEDG16](examples/gfx-palettes/gfx-PaletteEDG16.png)
545 | `gfx.Palette20PDX` | 20 | ![Palette20PDX](examples/gfx-palettes/gfx-Palette20PDX.png)
546 | `gfx.PaletteTango` | 27 | ![PaletteTango](examples/gfx-palettes/gfx-PaletteTango.png)
547 | `gfx.PaletteEDG32` | 32 | ![PaletteEDG32](examples/gfx-palettes/gfx-PaletteEDG32.png)
548 | `gfx.PaletteEDG36` | 36 | ![PaletteEDG36](examples/gfx-palettes/gfx-PaletteEDG36.png)
549 | `gfx.PaletteEDG64` | 64 | ![PaletteEDG64](examples/gfx-palettes/gfx-PaletteEDG64.png)
550 | `gfx.PaletteAAP64` | 64 | ![PaletteAAP64](examples/gfx-palettes/gfx-PaletteAAP64.png)
551 | `gfx.PaletteFamicube` | 64 | ![PaletteFamicube](examples/gfx-palettes/gfx-PaletteFamicube.png)
552 | `gfx.PaletteSplendor128` | 128 | ![PaletteSplendor128](examples/gfx-palettes/gfx-PaletteSplendor128.png)
553
554 The palette images were generated like this:
555
556 [embedmd]:# (examples/gfx-palettes/gfx-palettes.go)
557 ```go
558 package main
559
560 import "github.com/xyproto/gfx"
561
562 func main() {
563 for size, paletteLookup := range gfx.PalettesByNumberOfColors {
564 for name, palette := range paletteLookup {
565 dst := gfx.NewImage(size, 1)
566
567 for x, c := range palette {
568 dst.Set(x, 0, c)
569 }
570
571 filename := gfx.Sprintf("gfx-Palette%s.png", name)
572
573 gfx.SavePNG(filename, gfx.NewResizedImage(dst, 1120, 96))
574 }
575 }
576 }
577 ```
578
579
580 <img src="https://assets.c7.se/svg/viking-gopher.svg" align="right" width="30%" height="300">
581
582 ## License (MIT)
583
584 Copyright (c) 2019-2025 [Peter Hellberg](https://c7.se)
585
586 > Permission is hereby granted, free of charge, to any person obtaining
587 > a copy of this software and associated documentation files (the
588 > "Software"), to deal in the Software without restriction, including
589 > without limitation the rights to use, copy, modify, merge, publish,
590 > distribute, sublicense, and/or sell copies of the Software, and to
591 > permit persons to whom the Software is furnished to do so, subject to
592 > the following conditions:
593 >
594 > The above copyright notice and this permission notice shall be
595 > included in all copies or substantial portions of the Software.
596
597 > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
598 > EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
599 > MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
600 > NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
601 > LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
602 > OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
603 > WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.