示例#1
0
func drawBackground(ctx *html.Context, delta float64) {
	ctx.FillStyle = html.NewRGBColor(0, 19, 41)
	ctx.FillRect(0, 0, 800, 480)

	ctx.BeginPath()
	ctx.ShadowBlur = 50
	ctx.ShadowColor = html.NewRGBColor(220, 220, 220)
	ctx.FillStyle = html.NewRGBColor(255, 255, 255)
	ctx.Arc(
		400+int(450*math.Cos(moonPosition)),
		300+int(200*math.Sin(moonPosition)),
		50, 0, math.Pi*2, false)
	ctx.Fill()
	moonPosition += delta * 0.001
	ctx.ShadowBlur = 0

	for i := 0; i < len(clouds); i++ {
		c := clouds[i]
		ctx.BeginPath()
		ctx.FillStyle = html.Color("rgba(255, 255, 255, 0.2)")
		ctx.Save()
		ctx.Translate(int(c.X), int(c.Y))
		for _, p := range c.parts {
			ctx.Arc(p.X, p.Y, p.R, 0, math.Pi*2, false)
			ctx.ClosePath()
		}
		ctx.Fill()
		ctx.Restore()
		c.X += c.Speed
		if c.X > 820 {
			c.parts = c.parts[:0]
			c.init()
			c.X = -100
		}
	}
}
示例#2
0
func (ps *ParticleSystem) Draw(ctx *html.Context, delta float64) {
	living := 0
	ctx.BeginPath()
	ctx.FillStyle = ps.Color
	ctx.Save()
	ctx.Translate(int(ps.X*tileSize), int(ps.Y*tileSize))
	for _, p := range ps.particles {
		if p.Life > 15 {
			continue
		}
		living++
		p.Life += delta
		p.X += p.DX
		p.Y += p.DY
		p.DX += 0.1 * delta
		ctx.Arc(int(p.X), int(p.Y), ps.Size, 0, math.Pi*2, false)
		ctx.ClosePath()
	}
	ctx.Fill()
	ctx.Restore()
	if living == 0 {
		RemoveEntity(ps)
	}
}