-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometry.go
More file actions
132 lines (124 loc) · 2.91 KB
/
geometry.go
File metadata and controls
132 lines (124 loc) · 2.91 KB
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
package main
import (
"image"
"image/color"
"image/png"
"os"
)
func translasi() {
file, err := os.Open("./Input/image2.png")
if err != nil {
panic(err.Error())
}
defer file.Close()
img, err := png.Decode(file)
if err != nil {
panic(err.Error())
}
bounds := img.Bounds()
width, height := bounds.Max.X, bounds.Max.Y
shift := 100
Image := image.NewRGBA64(image.Rect(0, 0, width, height))
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
r, g, b, a := img.At(x, y).RGBA()
Image.Set(x+shift, y, color.RGBA64{R: uint16(r), G: uint16(g), B: uint16(b), A: uint16(a)})
}
}
outFile, err := os.Create("./Output/output.png")
if err != nil {
panic(err.Error())
}
defer outFile.Close()
err = png.Encode(outFile, Image)
if err != nil {
panic(err.Error())
}
}
func rotation() {
file, err := os.Open("./Input/image.png")
if err != nil {
panic(err.Error())
}
defer file.Close()
img, err := png.Decode(file)
if err != nil {
panic(err.Error())
}
bounds := img.Bounds()
width, height := bounds.Max.X, bounds.Max.Y
Image := image.NewRGBA64(image.Rect(0, 0, width, height))
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
r, g, b, a := img.At(x, y).RGBA()
Image.Set((width - x - 1), (height - y - 1), color.RGBA64{R: uint16(r), G: uint16(g), B: uint16(b), A: uint16(a)})
}
}
outFile, err := os.Create("./Output/output.png")
if err != nil {
panic(err.Error())
}
defer outFile.Close()
err = png.Encode(outFile, Image)
if err != nil {
panic(err.Error())
}
}
func zoom_out() {
file, err := os.Open("./Input/image.png")
if err != nil {
panic(err.Error())
}
defer file.Close()
img, err := png.Decode(file)
if err != nil {
panic(err.Error())
}
bounds := img.Bounds()
width, height := bounds.Max.X, bounds.Max.Y
Image := image.NewRGBA64(image.Rect(0, 0, width/2, height/2))
for x := 0; x < width; x += 2 {
for y := 0; y < height; y += 2 {
r, g, b, a := img.At(x, y).RGBA()
Image.Set(x/2, y/2, color.RGBA64{R: uint16(r), G: uint16(g), B: uint16(b), A: uint16(a)})
}
}
outFile, err := os.Create("./Output/output.png")
if err != nil {
panic(err.Error())
}
defer outFile.Close()
err = png.Encode(outFile, Image)
if err != nil {
panic(err.Error())
}
}
func flipping() {
file, err := os.Open("./Input/image.png")
if err != nil {
panic(err.Error())
}
defer file.Close()
img, err := png.Decode(file)
if err != nil {
panic(err.Error())
}
bounds := img.Bounds()
width, height := bounds.Max.X, bounds.Max.Y
Image := image.NewRGBA64(image.Rect(0, 0, width, height))
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
r, g, b, a := img.At(x, y).RGBA()
Image.Set(x, (height - y - 1), color.RGBA64{R: uint16(r), G: uint16(g), B: uint16(b), A: uint16(a)})
}
}
outFile, err := os.Create("./Output/output.png")
if err != nil {
panic(err.Error())
}
defer outFile.Close()
err = png.Encode(outFile, Image)
if err != nil {
panic(err.Error())
}
}