func draw(p Pendulum, canvas gxui.Canvas, x, y int) {
	attachment := math.Point{X: ANIMATION_WIDTH/2 + x, Y: y}

	phi := p.GetPhi()
	ball := math.Point{X: x + ANIMATION_WIDTH/2 + math.Round(float32(l*omath.Sin(phi))), Y: y + math.Round(float32(l*omath.Cos(phi)))}

	line := gxui.Polygon{gxui.PolygonVertex{attachment, 0}, gxui.PolygonVertex{ball, 0}}

	canvas.DrawLines(line, gxui.DefaultPen)

	m := math.Point{int(BALL_RADIUS), int(BALL_RADIUS)}
	rect := math.Rect{ball.Sub(m), ball.Add(m)}
	canvas.DrawRoundedRect(rect, BALL_RADIUS, BALL_RADIUS, BALL_RADIUS, BALL_RADIUS, gxui.TransparentPen, gxui.CreateBrush(gxui.Yellow))
}
Esempio n. 2
0
func drawTimeAxis(canvas gxui.Canvas) {
	p := gxui.Polygon{
		gxui.PolygonVertex{
			Position: math.Point{
				X: 0,
				Y: 400,
			},
			RoundedRadius: 0,
		},
		gxui.PolygonVertex{
			Position: math.Point{
				X: 400,
				Y: 400,
			},
			RoundedRadius: 0,
		},
	}

	canvas.DrawLines(p, gxui.CreatePen(1.0, gxui.White))
}
Esempio n. 3
0
func (s Snake) Draw(canvas gxui.Canvas) {
	bendCount := len(s.bends)
	p := make(gxui.Polygon, 2+bendCount)

	p[0] = gxui.PolygonVertex{
		Position:      s.head,
		RoundedRadius: 0,
	}

	for i, bend := range s.bends {
		p[i+1] = gxui.PolygonVertex{
			Position:      bend.point,
			RoundedRadius: 0,
		}
	}

	p[bendCount+1] = gxui.PolygonVertex{
		Position:      s.tail,
		RoundedRadius: 0,
	}

	canvas.DrawLines(p, gxui.CreatePen(float32(s.width), gxui.Green70))
}
Esempio n. 4
0
func (f Field) drawVerticalLines(canvas gxui.Canvas) {
	for x := f.cellWidth; x < f.width; x += f.cellWidth {
		p := make(gxui.Polygon, 2)

		p[0] = gxui.PolygonVertex{
			Position: math.Point{
				X: x,
				Y: 0,
			},
			RoundedRadius: 0,
		}

		p[1] = gxui.PolygonVertex{
			Position: math.Point{
				X: x,
				Y: f.height,
			},
			RoundedRadius: 0,
		}

		canvas.DrawLines(p, gxui.CreatePen(1, gxui.Gray80))
	}
}
Esempio n. 5
0
func (f Field) drawHorizontalLines(canvas gxui.Canvas) {
	for y := f.cellHeight; y < f.height; y += f.cellHeight {
		p := make(gxui.Polygon, 2)

		p[0] = gxui.PolygonVertex{
			Position: math.Point{
				X: 0,
				Y: y,
			},
			RoundedRadius: 0,
		}

		p[1] = gxui.PolygonVertex{
			Position: math.Point{
				X: f.width,
				Y: y,
			},
			RoundedRadius: 0,
		}

		canvas.DrawLines(p, gxui.CreatePen(1, gxui.Gray80))
	}
}