Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tidwall/pinhole
3D Wireframe Drawing Library for Go
https://github.com/tidwall/pinhole
graphics
Last synced: 3 days ago
JSON representation
3D Wireframe Drawing Library for Go
- Host: GitHub
- URL: https://github.com/tidwall/pinhole
- Owner: tidwall
- License: isc
- Created: 2017-05-19T04:58:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-30T16:25:08.000Z (almost 4 years ago)
- Last Synced: 2025-01-04T22:15:29.531Z (10 days ago)
- Topics: graphics
- Language: Go
- Homepage:
- Size: 580 KB
- Stars: 570
- Watchers: 10
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - pinhole - 3D wireframe drawing (Open source library / Charts)
README
# `pinhole`
3D Wireframe Drawing Library for Go
[Javascript Version](https://github.com/tidwall/pinhole-js)
[Demo](https://tidwall.com/pinhole/)
## Why does this exist?
I needed a CPU based 3D rendering library with a very simple API for visualizing data structures. No bells or whistles, just clean lines and solid colors.
## Getting Started
### Installing
To start using `pinhole`, install Go and run `go get`:
```sh
$ go get -u github.com/tidwall/pinhole
```This will retrieve the library.
### Using
The coordinate space has a locked origin of `0,0,0` with the min/max boundaries of `-1,-1,-1` to `+1,+1,+1`.
The `Z` coordinate extends from `-1` (nearest) to `+1` (farthest).There are four types of shapes; `line`, `cube`, `circle`, and `dot`.
These can be transformed with the `Scale`, `Rotate`, and `Translate` functions.
Multiple shapes can be transformed by nesting in a `Begin/End` block.A simple cube:
```go
p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.SavePNG("cube.png", 500, 500, nil)
```Rotate the cube:
```go
p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.Rotate(math.Pi/3, math.Pi/6, 0)
p.SavePNG("cube.png", 500, 500, nil)
```Add, rotate, and transform a circle:
```go
p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.Rotate(math.Pi/3, math.Pi/6, 0)p.Begin()
p.DrawCircle(0, 0, 0, 0.2)
p.Rotate(0, math.Pi/2, 0)
p.Translate(-0.6, -0.4, 0)
p.Colorize(color.RGBA{255, 0, 0, 255})
p.End()p.SavePNG("cube.png", 500, 500, nil)
```## Contact
Josh Baker [@tidwall](http://twitter.com/tidwall)
## License
`pinhole` source code is available under the ISC [License](/LICENSE).