/
api.go
159 lines (129 loc) · 3.85 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright ©2020 The go-p5 Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package p5
import (
"image"
"image/color"
"log"
"gioui.org/text"
)
// Push saves the current drawing style settings and transformations.
func Push() {
gproc.Push()
}
// Pop restores the previous drawing style settings and transformations.
func Pop() {
gproc.Pop()
}
// Canvas defines the dimensions of the painting area, in pixels.
func Canvas(w, h int) {
gproc.Canvas(w, h)
}
// PhysCanvas sets the dimensions of the painting area, in pixels, and
// associates physical quantities.
func PhysCanvas(w, h int, xmin, xmax, ymin, ymax float64) {
gproc.PhysCanvas(w, h, xmin, xmax, ymin, ymax)
}
// Background defines the background color for the painting area.
// The default color is transparent.
func Background(c color.Color) {
gproc.Background(c)
}
// Stroke sets the color of the strokes.
func Stroke(c color.Color) {
gproc.Stroke(c)
}
// StrokeWidth sets the size of the strokes.
func StrokeWidth(v float64) {
gproc.StrokeWidth(v)
}
// Fill sets the color used to fill shapes.
func Fill(c color.Color) {
gproc.Fill(c)
}
// LoadFonts sets the fonts collection to use for text.
func LoadFonts(fnt []text.FontFace) {
gproc.LoadFonts(fnt)
}
// TextSize sets the text size.
func TextSize(size float64) {
gproc.TextSize(size)
}
// TextFont sets the text font.
func TextFont(fnt text.Font) {
gproc.TextFont(fnt)
}
// Text draws txt on the screen at (x,y).
func Text(txt string, x, y float64) {
gproc.Text(txt, x, y)
}
// Screenshot saves the current canvas to the provided file.
// Supported file formats are: PNG, JPEG and GIF.
func Screenshot(fname string) {
err := gproc.Screenshot(fname)
if err != nil {
log.Printf("%+v", err)
}
}
// Rotate rotates the graphical context by angle radians.
// Positive angles rotate counter-clockwise.
func Rotate(angle float64) {
gproc.Rotate(angle)
}
// Scale rescales the graphical context by x and y.
func Scale(x, y float64) {
gproc.Scale(x, y)
}
// Translate applies a translation by x and y.
func Translate(x, y float64) {
gproc.Translate(x, y)
}
// Shear shears the graphical context by the given x and y angles in radians.
func Shear(x, y float64) {
gproc.Shear(x, y)
}
// Matrix sets the affine matrix transformation.
func Matrix(a, b, c, d, e, f float64) {
gproc.Matrix(a, b, c, d, e, f)
}
// RandomSeed changes the sequence of numbers generated by Random.
func RandomSeed(seed uint64) {
gproc.RandomSeed(seed)
}
// Random returns a pseudo-random number in [min,max).
// Random will produce the same sequence of numbers every time the program runs.
// Use RandomSeed with a seed that changes (like time.Now().UnixNano()) in order to
// produce different sequence of numbers.
func Random(min, max float64) float64 {
return gproc.Random(min, max)
}
// RandomGaussian returns a random number fitting a Gaussian (normal) distribution.
func RandomGaussian(mean, stdDev float64) float64 {
return gproc.RandomGaussian(mean, stdDev)
}
// FrameCount returns the number of frames that have been displayed since the program started.
func FrameCount() uint64 {
return gproc.FrameCount()
}
// By default, p5 continuously executes the code within Draw.
// Loop starts the draw loop again, if it was stopped previously by calling NoLoop.
func Loop() {
gproc.Loop()
}
// NoLoop stops p5 from continuously executing the code within Draw.
func NoLoop() {
gproc.NoLoop()
}
// IsLooping checks whether p5 is continuously executing the code within Draw.
func IsLooping() bool {
return gproc.IsLooping()
}
// ReadImage reads a BMP, JPG, GIF, PNG or TIFF image from the provided path.
func ReadImage(fname string) (image.Image, error) {
return gproc.ReadImage(fname)
}
// DrawImage draws the provided image at (x,y).
func DrawImage(img image.Image, x, y float64) {
gproc.DrawImage(img, x, y)
}