https://github.com/xyproto/shapes
Go module for dealing with shapes and points. Includes an animated example.
https://github.com/xyproto/shapes
ascii-graphics fractions points shapes software-rendering
Last synced: 5 months ago
JSON representation
Go module for dealing with shapes and points. Includes an animated example.
- Host: GitHub
- URL: https://github.com/xyproto/shapes
- Owner: xyproto
- License: mit
- Created: 2019-01-02T10:18:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-03T19:22:37.000Z (almost 7 years ago)
- Last Synced: 2025-01-11T00:46:32.458Z (9 months ago)
- Topics: ascii-graphics, fractions, points, shapes, software-rendering
- Language: Go
- Homepage:
- Size: 1.06 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shapes
Deal with points and triangles.
It is possible to add a triangle and get the coordinates as human-readable fractions.
Here is a sample program, that animates three ASCII triangles and outputs coordinates as both floats and fractions:

```go
package mainimport (
"fmt"
"github.com/xyproto/shapes"
"math"
"time"
)const (
twoPi = 2.0 * math.Pi// ASCII viewport
fromX = -5
toX = 10
fromY = -4
toY = 5// Terminal codes for the forground characters
y = "\033[1;93mo\033[0m"
b = "\033[1;94m@\033[0m"
r = "\033[1;31m#\033[0m"// The background character
bg = " "// Terminal code for clearing the rest of the line
clearToEnd = "\033[K"
)func init() {
fmt.Print("\033[H\033[2J")
}func reset() {
// Reset the cursor
fmt.Print("\033[H")
}func main() {
var (
// The original triangle
ot = shapes.NewTrianglef(0, 0, 4, 0, 4, 2)// The center position of the original triangle
center = ot.Center()// Three triangles
t1, t2, t3 *shapes.Tri// Angle, in radians
angle = 0.0
)
for {
// Create three new triangles, by rotating ot with different angles
t1 = ot.RotateAround(angle, center)
t2 = ot.RotateAround(angle-(math.Pi/3.0), center)
t3 = ot.RotateAround(angle-(math.Pi/3.0)*2.0, center)// Increase the angle just a bit, with wraparound
angle += 0.07
if angle >= twoPi {
angle -= twoPi
}// Reset the cursor
reset()// Draw three triangles, using ASCII graphics.
fmt.Println(t1.Draw(fromX, toX, fromY, toY, y, bg), clearToEnd)
fmt.Println(t2.Draw(fromX, toX, fromY, toY, b, bg), clearToEnd)
fmt.Println(t3.Draw(fromX, toX, fromY, toY, r, bg), clearToEnd)// Output the coordinates of the third triangle, as floats
shapes.FloatOutput = true
fmt.Println(t3.Points(), clearToEnd)// Output the coordinates of the third triangle, as fractions
shapes.FloatOutput = false
fmt.Println(t3.Points(), clearToEnd)// Wait a bit
time.Sleep(10 * time.Millisecond)
}
}
```## General Info
* License: MIT
* Version: 0.0.0