Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Draw-a-pixel/Go/draw-a-pixel-1.go
Normal file
28
Task/Draw-a-pixel/Go/draw-a-pixel-1.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rect := image.Rect(0, 0, 320, 240)
|
||||
img := image.NewRGBA(rect)
|
||||
|
||||
// Use green background, say.
|
||||
green := color.RGBA{0, 255, 0, 255}
|
||||
draw.Draw(img, rect, &image.Uniform{green}, image.ZP, draw.Src)
|
||||
|
||||
// Set color of pixel at (100, 100) to red
|
||||
red := color.RGBA{255, 0, 0, 255}
|
||||
img.Set(100, 100, red)
|
||||
|
||||
// Check it worked.
|
||||
cmap := map[color.Color]string{green: "green", red: "red"}
|
||||
c1 := img.At(0, 0)
|
||||
c2 := img.At(100, 100)
|
||||
fmt.Println("The color of the pixel at ( 0, 0) is", cmap[c1], "\b.")
|
||||
fmt.Println("The color of the pixel at (100, 100) is", cmap[c2], "\b.")
|
||||
}
|
||||
22
Task/Draw-a-pixel/Go/draw-a-pixel-2.go
Normal file
22
Task/Draw-a-pixel/Go/draw-a-pixel-2.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create a 320 x 240 image
|
||||
img := image.NewRGBA(image.Rect(0, 0, 320, 240))
|
||||
// fill img in white
|
||||
draw.Draw(img, img.Bounds(), &image.Uniform{color.RGBA{0, 0, 0, 0}}, image.ZP, draw.Src)
|
||||
// Draw a red dot at (100, 100)
|
||||
img.Set(100, 100, color.RGBA{255, 0, 0, 255})
|
||||
// Save to new.png
|
||||
w, _ := os.OpenFile("new.png", os.O_WRONLY|os.O_CREATE, 0600)
|
||||
defer w.Close()
|
||||
png.Encode(w, img)
|
||||
}
|
||||
10
Task/Draw-a-pixel/Go/draw-a-pixel-3.go
Normal file
10
Task/Draw-a-pixel/Go/draw-a-pixel-3.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package main
|
||||
// first run" go get github.com/zserge/webview"
|
||||
// simple GUI "window"
|
||||
import "github.com/zserge/webview"
|
||||
|
||||
func main() {
|
||||
// Open wikipedia in a 320*240 resizable window
|
||||
webview.Open("Minimal webview example",
|
||||
"https://en.m.wikipedia.org/wiki/Main_Page", 320, 240, true)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue