func (p *GesturePane) Render() (*image.RGBA, error) {
	img := image.NewRGBA(image.Rect(0, 0, 16, 16))

	if p.last != nil {

		x := math.Floor(float64(p.last.Position.X)/float64(0xffff)*float64(16)) + 0.5
		y := math.Floor(float64(p.last.Position.Y)/float64(0xffff)*float64(16)) + 0.5
		z := math.Floor(float64(p.last.Position.Z)/float64(0xffff)*float64(16)) + 0.5

		r, _ := colorful.Hex("#FF000")
		g, _ := colorful.Hex("#00FF00")
		b, _ := colorful.Hex("#0000FF")

		gc := draw2d.NewGraphicContext(img)

		gc.SetStrokeColor(r)
		gc.MoveTo(0, x)
		gc.LineTo(16, x)
		gc.Stroke()

		gc.SetStrokeColor(g)
		gc.MoveTo(y, 0)
		gc.LineTo(y, 16)
		gc.Stroke()

		gc.SetStrokeColor(b)
		gc.MoveTo(16-z, 0)
		gc.LineTo(16-z, 16)
		gc.Stroke()
	}

	return img, nil
}
Beispiel #2
0
func test(t *testing.T, draw sample) {
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2dimg.NewGraphicContext(dest)
	// Draw Android logo
	output, err := draw(gc, "png")
	if err != nil {
		t.Errorf("Drawing %q failed: %v", output, err)
		return
	}
	// Save to png
	err = draw2dimg.SaveToPngFile(output, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", output, err)
	}
}
Beispiel #3
0
func imgPng(w http.ResponseWriter, r *http.Request) *appError {
	w.Header().Set("Content-type", "image/png")

	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2dimg.NewGraphicContext(dest)

	// Draw sample
	android.Draw(gc, 65, 0)

	err := png.Encode(w, dest)
	if err != nil {
		return &appError{err, fmt.Sprintf("Can't encode: %s", err), 500}
	}

	return nil
}
Beispiel #4
0
func TestCircle(t *testing.T) {
	width := 200
	height := 200
	img := image.NewRGBA(image.Rect(0, 0, width, height))
	gc := draw2dimg.NewGraphicContext(img)

	gc.SetStrokeColor(color.NRGBA{255, 255, 255, 255})
	gc.SetFillColor(color.NRGBA{255, 255, 255, 255})
	gc.Clear()

	gc.SetStrokeColor(color.NRGBA{255, 0, 0, 255})
	gc.SetLineWidth(1)

	// Draw a circle
	Circle(gc, 100, 100, 50)
	gc.Stroke()

	draw2dimg.SaveToPngFile("../output/draw2dkit/TestCircle.png", img)
}
Beispiel #5
0
func DrawPoint(toilets []models.Toilet, b *models.Bounds, imgWidth int, imgHeight int) string {
	// fmt.Println(imgWidth,imgHeight);
	filename := strconv.Itoa(b.Min.X) + "_" + strconv.Itoa(b.Min.Y)
	filename += "_" + strconv.Itoa(b.Max.X) + "_" + strconv.Itoa(b.Max.Y)
	filename += "_" + strconv.Itoa(imgWidth) + "_" + strconv.Itoa(imgHeight) + ".png"
	HRes := b.GetWidth() / imgWidth
	VRes := b.GetHeight() / imgHeight
	dest := image.NewRGBA(image.Rect(0, 0, imgWidth, imgHeight))
	gc := draw2dimg.NewGraphicContext(dest)
	gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
	gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})

	for _, toilet := range toilets {
		dx := (toilet.Geom.Lng - float64(b.Min.X)) / float64(HRes)                  //x
		dy := float64(imgHeight) - (toilet.Geom.Lat-float64(b.Min.Y))/float64(VRes) //y
		// fmt.Println("toilet :", toilet,dx,dy);
		draw2dkit.Circle(gc, dx, dy, 3)
		gc.FillStroke()
	}
	gc.Close()
	draw2dimg.SaveToPngFile(revel.BasePath+"/output/wms/"+filename, dest)
	return filename
}
Beispiel #6
0
// Get a new Graphic Context where to draw
func (c *Canvas) GetContext() *CanvasContext {
	gc := draw2dimg.NewGraphicContext(&(c.RGBA))
	cnv := CanvasContext{*gc, (*c).size}
	return &cnv
}