func appMain(driver gxui.Driver) {
	theme := dark.CreateTheme(driver)

	window := theme.CreateWindow(ANIMATION_WIDTH, 2*ANIMATION_HEIGHT, "Pendulum")
	window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))

	image := theme.CreateImage()

	ticker := time.NewTicker(time.Millisecond * 15)
	pendulum := &mathematicalPendulum{}
	pendulum2 := &numericalPendulum{PHI_ZERO, 0.0, 0.0, time.Time{}}

	go func() {
		for _ = range ticker.C {
			canvas := driver.CreateCanvas(math.Size{ANIMATION_WIDTH, 2 * ANIMATION_HEIGHT})
			canvas.Clear(gxui.White)

			draw(pendulum, canvas, 0, 0)
			draw(pendulum2, canvas, 0, ANIMATION_HEIGHT)

			canvas.Complete()
			driver.Call(func() {
				image.SetCanvas(canvas)
			})
		}
	}()

	window.AddChild(image)

	window.OnClose(ticker.Stop)
	window.OnClose(driver.Terminate)
}
Esempio n. 2
0
File: main.go Progetto: gbember/gt
//画行走路线
func drawWalkPath(window gxui.Window, theme gxui.Theme, driver gxui.Driver, x1, y1, x2, y2 int64) {
	ps, isWalk := nm.FindPath(nmastar, x1, y1, x2, y2)
	if !isWalk {
		return
	}
	canvas := driver.CreateCanvas(math.Size{W: int(nmj.Width), H: int(nmj.Heigth)})

	var polys []gxui.PolygonVertex
	for i := 0; i < len(ps); i++ {

		polys = append(polys,
			gxui.PolygonVertex{
				Position: math.Point{
					int(ps[i].X),
					int(ps[i].Y),
				}})
	}
	canvas.DrawLines(polys, gxui.CreatePen(2, gxui.Green))

	canvas.Complete()
	image := theme.CreateImage()
	image.SetCanvas(canvas)
	window.AddChild(image)

}
Esempio n. 3
0
func route(driver gxui.Driver, src_id, dest_id int32, src, dest Point3) (canvas gxui.Canvas) {
	defer func() {
		canvas.Complete()
	}()
	canvas = driver.CreateCanvas(math.Size{W: 800, H: 600})
	t0 := time.Now()
	// Phase 1. Use Dijkstra to find shortest path on Triangles
	path := dijkstra.Run(src_id)

	// Phase 2.  construct path indices
	// Check if this path include src & dest
	path_triangle := [][3]int32{triangles[dest_id]}
	prev_id := dest_id
	for {
		cur_id, ok := path[prev_id]
		if !ok {
			return canvas
		}
		path_triangle = append([][3]int32{triangles[cur_id]}, path_triangle...)
		if cur_id == src_id {
			break
		}
		prev_id = cur_id
	}

	// Phase 3. use Navmesh to construct line
	start, end := &Point3{X: src.X, Y: src.Y}, &Point3{X: dest.X, Y: dest.Y}
	nm := NavMesh{}
	trilist := TriangleList{vertices, path_triangle}
	r, _ := nm.Route(trilist, start, end)
	log.Println("navmesh time:", time.Now().Sub(t0))

	var poly []gxui.PolygonVertex
	poly = append(poly,
		gxui.PolygonVertex{
			Position: math.Point{
				int(SCALE_FACTOR * start.X),
				int(SCALE_FACTOR * start.Y),
			}})

	for k := range r.Line {
		poly = append(poly,
			gxui.PolygonVertex{
				Position: math.Point{
					int(SCALE_FACTOR * r.Line[k].X),
					int(SCALE_FACTOR * r.Line[k].Y),
				}})
	}
	poly = append(poly,
		gxui.PolygonVertex{
			Position: math.Point{
				int(SCALE_FACTOR * end.X),
				int(SCALE_FACTOR * end.Y),
			}})

	canvas.DrawLines(poly, gxui.CreatePen(2, gxui.Green))
	return
}
Esempio n. 4
0
func drawScene(driver gxui.Driver) {
	window.RemoveAll()

	canvas = driver.CreateCanvas(math.Size{W: 800, H: 600})

	sn.Draw(canvas)
	playGround.Draw(canvas)

	canvas.Complete()
	image := theme.CreateImage()
	image.SetCanvas(canvas)
	window.AddChild(image)
}
Esempio n. 5
0
File: main.go Progetto: gbember/gt
func appMain(driver gxui.Driver) {
	theme := flags.CreateTheme(driver)
	width := int(nmj.Width)
	height := int(nmj.Heigth)

	window := theme.CreateWindow(width, height, "navmesh")
	canvas := driver.CreateCanvas(math.Size{W: width, H: height})

	ps := nmj.Points

	// mouse
	isStart := true
	x1, y1, x2, y2 := int64(0), int64(0), int64(0), int64(0)

	window.OnMouseDown(func(me gxui.MouseEvent) {
		if nm.IsWalkOfPoint(navmesh.Point{X: int64(me.Point.X), Y: int64(me.Point.Y)}) {
			if isStart {
				x1 = int64(me.Point.X)
				y1 = int64(me.Point.Y)
			} else {
				x2 = int64(me.Point.X)
				y2 = int64(me.Point.Y)
			}
			if !isStart {
				drawWalkPath(window, theme, driver, x1, y1, x2, y2)
			}
			isStart = !isStart
		}
	})

	// draw mesh
	for i := 0; i < len(ps); i++ {
		polys := make([]gxui.PolygonVertex, 0, len(ps[i]))
		for j := 0; j < len(ps[i]); j++ {
			polys = append(polys, gxui.PolygonVertex{
				Position: math.Point{
					int(ps[i][j].X),
					int(ps[i][j].Y),
				}})
		}
		//		canvas.DrawPolygon(polys, gxui.CreatePen(2, gxui.Gray80), gxui.CreateBrush(gxui.Gray40))
		canvas.DrawPolygon(polys, gxui.CreatePen(2, gxui.Red), gxui.CreateBrush(gxui.Yellow))
	}

	canvas.Complete()
	image := theme.CreateImage()
	image.SetCanvas(canvas)
	window.AddChild(image)
	window.OnClose(driver.Terminate)
}
Esempio n. 6
0
func appMain(driver gxui.Driver) {
	theme := flags.CreateTheme(driver)

	canvas := driver.CreateCanvas(math.Size{W: 500, H: 300})

	layout := theme.CreateLinearLayout()
	layout.SetSizeMode(gxui.Fill)
	layout.SetDirection(gxui.TopToBottom)

	buttonsLayout := theme.CreateLinearLayout()
	buttonsLayout.SetSizeMode(gxui.Fill)
	buttonsLayout.SetDirection(gxui.LeftToRight)

	button := func(name string, action func()) gxui.Button {
		b := theme.CreateButton()
		b.SetText(name)
		b.OnClick(func(gxui.MouseEvent) { action() })
		return b
	}

	okayButton := button("Okay", func() { log.Println("Okay") })
	buttonsLayout.AddChild(okayButton)
	cancelButton := button("Cancel", func() { log.Println("Cancel") })
	buttonsLayout.AddChild(cancelButton)

	drawPlot(canvas)
	canvas.Complete()

	image := theme.CreateImage()
	image.SetCanvas(canvas)

	window := theme.CreateWindow(800, 600, "bview")
	window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))
	layout.AddChild(buttonsLayout)
	layout.AddChild(image)
	window.AddChild(layout)
	window.OnClose(driver.Terminate)
	window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10})

	window.OnResize(func() { log.Println(layout.Children().String()) })

}
Esempio n. 7
0
File: main.go Progetto: langxj/gxui
func appMain(driver gxui.Driver) {
	theme := flags.CreateTheme(driver)
	window := theme.CreateWindow(800, 600, "Polygon")
	window.SetScale(flags.DefaultScaleFactor)

	canvas := driver.CreateCanvas(math.Size{W: 1000, H: 1000})
	drawStar(canvas, math.Point{X: 100, Y: 100}, 50, 0.2, 6)
	drawStar(canvas, math.Point{X: 650, Y: 170}, 70, 0.5, 7)
	drawStar(canvas, math.Point{X: 40, Y: 300}, 20, 0, 5)
	drawStar(canvas, math.Point{X: 410, Y: 320}, 25, 0.9, 5)
	drawStar(canvas, math.Point{X: 220, Y: 520}, 45, 0, 6)

	drawMoon(canvas, math.Point{X: 400, Y: 300}, 200)
	canvas.Complete()

	image := theme.CreateImage()
	image.SetCanvas(canvas)
	window.AddChild(image)

	window.OnClose(driver.Terminate)
}
Esempio n. 8
0
func appMain(driver gxui.Driver) {
	theme := dark.CreateTheme(driver)

	canvas := driver.CreateCanvas(math.Size{W: 800, H: 600})

	for i := 0; i < 800; i++ {
		var fy = maths.Sin(float64(i) * (maths.Pi / 180))
		y := (int(fy*100) + 240)
		plot(canvas, i, y)
	}

	canvas.Complete()

	image := theme.CreateImage()
	image.SetCanvas(canvas)

	window := theme.CreateWindow(800, 600, "")
	window.AddChild(image)
	window.OnClose(driver.Terminate)

}
Esempio n. 9
0
func appMain(driver gxui.Driver) {
	theme := flags.CreateTheme(driver)
	window := theme.CreateWindow(800, 600, "navmesh")
	canvas := driver.CreateCanvas(math.Size{W: 800, H: 600})

	// mouse
	isStart := true
	var src_id, dest_id int32 // source & dest triangle id
	var src, dest Point3
	window.OnMouseDown(func(me gxui.MouseEvent) {
		pt := Point3{X: float32(me.Point.X) / SCALE_FACTOR, Y: float32(me.Point.Y) / SCALE_FACTOR}
		id := getTriangleId(pt)
		if isStart {
			src_id = id
			src = pt
		} else {
			dest_id = id
			dest = pt
		}
		if !isStart {
			if src_id != -1 && dest_id != -1 {
				canvas := route(driver, src_id, dest_id, src, dest)
				image := theme.CreateImage()
				image.SetCanvas(canvas)
				window.AddChild(image)
			}
		}
		isStart = !isStart
	})

	// draw mesh
	for k := 0; k < len(triangles); k++ {
		poly := []gxui.PolygonVertex{
			gxui.PolygonVertex{
				Position: math.Point{
					int(SCALE_FACTOR * vertices[triangles[k][0]].X),
					int(SCALE_FACTOR * vertices[triangles[k][0]].Y),
				}},

			gxui.PolygonVertex{
				Position: math.Point{
					int(SCALE_FACTOR * vertices[triangles[k][1]].X),
					int(SCALE_FACTOR * vertices[triangles[k][1]].Y),
				}},

			gxui.PolygonVertex{
				Position: math.Point{
					int(SCALE_FACTOR * vertices[triangles[k][2]].X),
					int(SCALE_FACTOR * vertices[triangles[k][2]].Y),
				}},
		}
		canvas.DrawPolygon(poly, gxui.CreatePen(3, gxui.Gray80), gxui.CreateBrush(gxui.Gray40))
		//canvas.DrawPolygon(poly, gxui.CreatePen(2, gxui.Red), gxui.CreateBrush(gxui.Yellow))
	}

	canvas.Complete()
	image := theme.CreateImage()
	image.SetCanvas(canvas)
	window.AddChild(image)
	window.OnClose(driver.Terminate)
}