コード例 #1
0
ファイル: geometry.go プロジェクト: zzn01/draw2d
// FillStyle demonstrates the difference between even odd and non zero winding rule.
func FillStyle(gc draw2d.GraphicContext, x, y, width, height float64) {
	sx, sy := width/232, height/220
	gc.SetLineWidth(width / 40)

	draw2dkit.Rectangle(gc, x+sx*0, y+sy*12, x+sx*232, y+sy*70)

	var wheel1, wheel2 draw2d.Path
	wheel1.ArcTo(x+sx*52, y+sy*70, sx*40, sy*40, 0, 2*math.Pi)
	wheel2.ArcTo(x+sx*180, y+sy*70, sx*40, sy*40, 0, -2*math.Pi)

	gc.SetFillRule(draw2d.FillRuleEvenOdd)
	gc.SetFillColor(color.NRGBA{0, 0xB2, 0, 0xFF})

	gc.SetStrokeColor(image.Black)
	gc.FillStroke(&wheel1, &wheel2)

	draw2dkit.Rectangle(gc, x, y+sy*140, x+sx*232, y+sy*198)
	wheel1.Clear()
	wheel1.ArcTo(x+sx*52, y+sy*198, sx*40, sy*40, 0, 2*math.Pi)
	wheel2.Clear()
	wheel2.ArcTo(x+sx*180, y+sy*198, sx*40, sy*40, 0, -2*math.Pi)

	gc.SetFillRule(draw2d.FillRuleWinding)
	gc.SetFillColor(color.NRGBA{0, 0, 0xE5, 0xFF})
	gc.FillStroke(&wheel1, &wheel2)
}
コード例 #2
0
ファイル: geometry.go プロジェクト: zzn01/draw2d
// FillString draws a filled and stroked string.
func FillString(gc draw2d.GraphicContext, x, y, width, height float64) {
	sx, sy := width/100, height/100
	gc.Save()
	gc.SetStrokeColor(image.Black)
	gc.SetLineWidth(1)
	draw2dkit.RoundedRectangle(gc, x+sx*5, y+sy*5, x+sx*95, y+sy*95, sx*10, sy*10)
	gc.FillStroke()
	gc.SetFillColor(image.Black)
	gc.SetFontSize(height / 6)
	gc.Translate(x+sx*6, y+sy*52)
	gc.SetFontData(draw2d.FontData{
		Name:   "luxi",
		Family: draw2d.FontFamilyMono,
		Style:  draw2d.FontStyleBold | draw2d.FontStyleItalic})
	w := gc.FillString("Hug")
	gc.Translate(w+sx, 0)
	left, top, right, bottom := gc.GetStringBounds("cou")
	gc.SetStrokeColor(color.NRGBA{255, 0x33, 0x33, 0x80})
	draw2dkit.Rectangle(gc, left, top, right, bottom)
	gc.SetLineWidth(height / 50)
	gc.Stroke()
	gc.SetFillColor(color.NRGBA{0x33, 0x33, 0xff, 0xff})
	gc.SetStrokeColor(color.NRGBA{0x33, 0x33, 0xff, 0xff})
	gc.SetLineWidth(height / 100)
	gc.StrokeString("Hug")
	gc.Restore()
}
コード例 #3
0
ファイル: demo.go プロジェクト: google/hilbert
func (h *spaceFillingImage) drawRectange(gc draw2d.GraphicContext, px1, py1, px2, py2 float64) {
	gc.SetFillColor(h.BackgroundColor)
	gc.SetStrokeColor(h.GridColor)
	gc.SetLineWidth(1)

	draw2dkit.Rectangle(gc, px1, py1, px2, py2)
	gc.FillStroke()
}
コード例 #4
0
ファイル: gc.go プロジェクト: zzn01/draw2d
// clearRect draws a white rectangle
func clearRect(gc *GraphicContext, x1, y1, x2, y2 float64) {
	// save state
	f := gc.Current.FillColor
	x, y := gc.pdf.GetXY()
	// cover page with white rectangle
	gc.SetFillColor(white)
	draw2dkit.Rectangle(gc, x1, y1, x2, y2)
	gc.Fill()
	// restore state
	gc.SetFillColor(f)
	gc.pdf.MoveTo(x, y)
}
コード例 #5
0
ファイル: main_test.go プロジェクト: Kimau/GoDriveTracker
// Draw "Hello World"
func DrawHello(gc draw2d.GraphicContext, text string) {
	draw2d.SetFontFolder("static")
	gc.SetFontData(draw2d.FontData{
		Name: "Roboto",
	})

	gc.SetFontSize(14)
	l, t, r, b := gc.GetStringBounds(text)
	//log.Println(t, l, r, b)

	draw2dkit.Rectangle(gc, 0, 0, r-l+30, b-t+30)
	gc.SetFillColor(image.White)
	gc.FillStroke()

	draw2dkit.Rectangle(gc, 10, 10, r-l+20, b-t+20)
	gc.SetFillColor(image.White)
	gc.FillStroke()

	gc.SetFillColor(color.NRGBA{R: 255, G: 0, B: 0, A: 255})
	gc.FillStringAt(text, 15-l, 15-t)

}
コード例 #6
0
ファイル: android.go プロジェクト: zzn01/draw2d
// Draw the droid on a certain position.
func Draw(gc draw2d.GraphicContext, x, y float64) {
	// set the fill and stroke color of the droid
	gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
	gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})

	// set line properties
	gc.SetLineCap(draw2d.RoundCap)
	gc.SetLineWidth(5)

	// head
	gc.MoveTo(x+30, y+70)
	gc.ArcTo(x+80, y+70, 50, 50, 180*(math.Pi/180), 180*(math.Pi/180))
	gc.Close()
	gc.FillStroke()
	gc.MoveTo(x+60, y+25)
	gc.LineTo(x+50, y+10)
	gc.MoveTo(x+100, y+25)
	gc.LineTo(x+110, y+10)
	gc.Stroke()

	// left eye
	draw2dkit.Circle(gc, x+60, y+45, 5)
	gc.FillStroke()

	// right eye
	draw2dkit.Circle(gc, x+100, y+45, 5)
	gc.FillStroke()

	// body
	draw2dkit.RoundedRectangle(gc, x+30, y+75, x+30+100, y+75+90, 10, 10)
	gc.FillStroke()
	draw2dkit.Rectangle(gc, x+30, y+75, x+30+100, y+75+80)
	gc.FillStroke()

	// left arm
	draw2dkit.RoundedRectangle(gc, x+5, y+80, x+5+20, y+80+70, 10, 10)
	gc.FillStroke()

	// right arm
	draw2dkit.RoundedRectangle(gc, x+135, y+80, x+135+20, y+80+70, 10, 10)
	gc.FillStroke()

	// left leg
	draw2dkit.RoundedRectangle(gc, x+50, y+150, x+50+20, y+150+50, 10, 10)
	gc.FillStroke()

	// right leg
	draw2dkit.RoundedRectangle(gc, x+90, y+150, x+90+20, y+150+50, 10, 10)
	gc.FillStroke()
}
コード例 #7
0
func (l *BackgroundLayout) Render(ctx *Context, bounds Rect) error {
	dw, dh := bounds.Width(), bounds.Height()

	if l.Image != "" {
		f, err := os.Open(l.Image)
		if err != nil {
			return err
		}
		defer f.Close()

		src, _, err := image.Decode(f)
		if err != nil {
			return err
		}

		if l.Grayscale {
			src = &Converted{src, color.GrayModel}
		}

		sw, sh := float64(src.Bounds().Dx()), float64(src.Bounds().Dy())
		scale := math.Max(dw/sw, dh/sh)
		ctx.Save()
		ctx.Translate(bounds.Left+(dw-sw*scale)/2, bounds.Top+(dh-sh*scale)/2)
		ctx.Scale(scale, scale)
		ctx.DrawImage(src)
		ctx.Restore()
	}

	if l.Color {
		ctx.SetFillColor(ctx.Style.ColorDarkPrimary)
		draw2dkit.Rectangle(ctx, bounds.Left, bounds.Top, bounds.Right, bounds.Bottom)
		ctx.Fill()
	}

	return nil
}
コード例 #8
0
ファイル: draw_graph.go プロジェクト: Kimau/GoDriveTracker
//
// Histograms Charts
//
func dailyWordHistChart(filename string, width, height int, days []*stat.DailyUserStat, dateLine []time.Time) {

	dest := image.NewRGBA(image.Rect(0, 0, width, height))
	gc := draw2dimg.NewGraphicContext(dest)

	var minVal, maxVal float64 = 0, 0
	dayLen := len(days)
	xStep := float64(width) / float64(dayLen)
	baseLineY := float64(50)

	dayAdd := make([]float64, dayLen)
	daySub := make([]float64, dayLen)

	for i := 0; i < dayLen; i += 1 {
		if days[i] == nil {
			dayAdd[i] = 0
			daySub[i] = 0
		} else {
			dayAdd[i] = float64(days[i].WordAdd)
			daySub[i] = float64(0 - days[i].WordSub)

			if dayAdd[i] > maxVal {
				maxVal = dayAdd[i]
			}
			if daySub[i] > minVal {
				minVal = daySub[i]
			}
		}
	}

	hf := float64(height)
	wf := float64(width)

	for i := 0; i < dayLen; i += 1 {
		dayAdd[i] = (hf - baseLineY) * dayAdd[i] / maxVal
		daySub[i] = (baseLineY) * daySub[i] / minVal
	}

	// Draw Grid Lines
	{
		gc.SetFillColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
		gc.SetStrokeColor(color.RGBA{0x00, 0x00, 0x00, 0xff})
		gc.SetLineWidth(0.2)

		yStep := 100.0
		if maxVal > 10000 {
			yStep = 1000.0
		} else if maxVal > 1000 {
			yStep = 250.0
		}

		gc.SetFontData(draw2d.FontData{Name: "Roboto", Family: draw2d.FontFamilySans})
		for y := yStep; y < maxVal; y += yStep {
			yf := (hf - baseLineY) - (hf-baseLineY)*y/maxVal
			gc.MoveTo(0, yf)
			gc.LineTo(wf, yf)
			gc.Stroke()

			gc.FillStringAt(fmt.Sprintf("%.0f", y), 10, yf)
		}

		yStep = 100.0
		if minVal > 10000 {
			yStep = 1000.0
		} else if minVal > 1000 {
			yStep = 250.0
		}

		for y := yStep; y < minVal; y += yStep {
			yf := (hf - baseLineY) + baseLineY*y/minVal
			gc.MoveTo(0, yf)
			gc.LineTo(wf, yf)
		}

		gc.Stroke()
	}

	// Add
	gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
	for i := 0; i < dayLen; i += 1 {
		x := float64(i) * xStep
		draw2dkit.Rectangle(gc, x, hf-baseLineY, x+xStep, hf-baseLineY-dayAdd[i])
	}
	gc.Fill()

	// Sub
	gc.SetFillColor(color.RGBA{0xff, 0x44, 0x44, 0xff})
	for i := 0; i < dayLen; i += 1 {
		x := float64(i) * xStep
		draw2dkit.Rectangle(gc, x, hf-baseLineY, x+xStep, hf-baseLineY+daySub[i])
	}
	gc.Fill()

	// Draw Base Line
	{
		gc.SetStrokeColor(color.RGBA{0x00, 0x00, 0x00, 0xff})
		gc.SetLineWidth(1)
		gc.MoveTo(0, 0)
		gc.LineTo(0, hf)
		gc.MoveTo(0, hf-baseLineY)
		gc.LineTo(wf, hf-baseLineY)
		gc.MoveTo(wf, 0)
		gc.LineTo(wf, hf)

		for i := 0; i < dayLen; i += 1 {
			if dateLine[i].Weekday() == time.Monday {
				x := float64(i) * xStep
				gc.MoveTo(x, hf-baseLineY-10)
				gc.LineTo(x, hf-baseLineY+10)
			}
		}

		gc.Stroke()
	}

	draw2dimg.SaveToPngFile(filename, dest)
}