This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c.processor = &triangle.Processor{ | |
BlurRadius: 2, | |
Noise: 0, | |
BlurFactor: 2, | |
EdgeFactor: 4, | |
PointRate: c.pointRate, | |
MaxPoints: c.trianglePoints, | |
PointsThreshold: c.pointsThreshold, | |
Wireframe: c.wireframe, | |
StrokeWidth: c.strokeWidth, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8Arr := js.Global().Get("Uint8Array").New(width * height * 4) | |
js.CopyBytesToJS(uint8Arr2, pixels.ImgToPix(blurred)) | |
uint8Clamped := js.Global().Get("Uint8ClampedArray").New(uint8Arr2) | |
rawData := js.Global().Get("ImageData").New(uint8Clamped, width, height) | |
c.ctx.Call("putImageData", rawData, 0, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rgba := c.ctx.Call("getImageData", 0, 0, width, height).Get("data") | |
// Convert the rgba value of type Uint8ClampedArray to Uint8Array in order to | |
// be able to transfer it from Javascript to Go via the js.CopyBytesToGo function. | |
uint8Arr := js.Global().Get("Uint8Array").New(rgba) | |
js.CopyBytesToGo(data, uint8Arr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ImgToPix converts an image to an 1D uint8 pixel array. | |
// In order to preserve the color information per pixel we need to reconstruct the array to a specific format. | |
func ImgToPix(src *image.NRGBA) []uint8 { | |
size := src.Bounds().Size() | |
width, height := size.X, size.Y | |
pixels := make([][][3]uint8, height) | |
for y := 0; y < height; y++ { | |
row := make([][3]uint8, width) | |
for x := 0; x < width; x++ { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package draw | |
import ( | |
"image" | |
"image/color" | |
) | |
// ellipse defines the struct components required to apply the ellipse's formula. | |
type ellipse struct { | |
cx int // center x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
draw.DrawMask(source.(*image.NRGBA), source.Bounds(), ellipse, image.Point{}, mask, image.Point{}, draw.Over) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<script src="js/wasm_exec.js"></script> | |
<script type="text/javascript"> | |
function fetchAndInstantiate(url, importObject) { | |
return fetch(url).then(response => | |
response.arrayBuffer() | |
).then(bytes => | |
WebAssembly.instantiate(bytes, importObject) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ifeq ($(OS),Windows_NT) | |
BROWSER = start | |
else | |
UNAME := $(shell uname -s) | |
ifeq ($(UNAME), Linux) | |
BROWSER = xdg-open | |
endif | |
ifeq ($(UNAME), Darwin) | |
BROWSER = open | |
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +build js,wasm | |
package main | |
import ( | |
"fmt" | |
"github.com/esimov/pigo/wasm/canvas" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"math/rand" | |
"os" | |
"runtime" | |
"strconv" | |
"time" |
NewerOlder