Exemple #1
0
func (s *christmas) animateNextFrame(frameCount int, frame framebuffer.Segment) {

	// Time to change lights
	if time.Now().Sub(s.changeTime) > 0 {
		s.changeTime = time.Now().Add(s.period)

		// Move on to next light colour
		if s.nextColour == uint(len(s.lightColours))-1 {
			s.nextColour = 0
		} else {
			s.nextColour++
		}

		// Set each LED appropriately
		off := framebuffer.NewRgbFromInt(0)
		for i := uint(0); i < frame.Len(); i++ {

			// Which colour index should this be
			c := (i / s.lightSize) % uint(len(s.lightColours))

			// Either turn colour on or turn LED off
			if c == s.nextColour {
				frame.Set(i, s.lightColours[s.nextColour])
			} else {
				frame.Set(i, off)
			}
		}
	}
}
Exemple #2
0
func (sc *staticColour) animateNextFrame(frameCount int, frame framebuffer.Segment) {

	if frameCount == 0 {
		for s := uint(0); s < frame.Len(); s++ {
			frame.Set(s, sc.colour)
		}
	}
}
Exemple #3
0
func (s *sweetshop) animateNextFrame(frameCount int, frame framebuffer.Segment) {

	if time.Now().Sub(s.changeTime) > 0 {

		// Set next change time
		s.changeTime = time.Now().Add(s.period)

		// Refresh the random colours
		for i := uint(0); i < frame.Len(); i++ {
			frame.Set(i, framebuffer.NewRgbFromInt(rand.Int()&(1<<24-1)))
		}
	}
}
Exemple #4
0
func (r *rainbow) animateNextFrame(frameCount int, frame framebuffer.Segment) {

	hue := r.startDegree
	hueIncrement := 360.0 / float32(frame.Len())
	for i := uint(0); i < frame.Len(); i++ {
		frame.Set(i, framebuffer.NewRgbFromHsl(uint(hue), 100, 50))
		hue += hueIncrement
	}
	r.startDegree += r.degreesPerFrame
	if r.startDegree > 360 {
		r.startDegree -= 360
	}
}
Exemple #5
0
func (c *cylon) animateNextFrame(frameCount int, frame framebuffer.Segment) {

	frame.Set(c.pos, framebuffer.NewRgb(0, 0, 0))

	if c.dir {
		if c.pos == frame.Len()-1 {
			c.dir = false
		} else {
			c.pos++
		}
	} else {
		if c.pos == 0 {
			c.dir = true
		} else {
			c.pos--
		}
	}

	frame.Set(c.pos, framebuffer.NewRgb(255, 0, 0))
}
Exemple #6
0
func (p *pulse) animateNextFrame(frameCount int, frame framebuffer.Segment) {

	if p.up {
		if p.val != 255 {
			p.val++
		} else {
			p.up = false
			p.val--
		}
	} else {
		if p.val != 0 {
			p.val--
		} else {
			p.up = true
			p.val++
		}
	}

	colour := framebuffer.NewRgb(p.val, p.val, p.val)
	for s := uint(0); s < frame.Len(); s++ {
		frame.Set(s, colour)
	}
}
Exemple #7
0
func (r *runner) animateNextFrame(frameCount int, frame framebuffer.Segment) {

	frame.Set(r.pos, framebuffer.NewRgb(0, 0, 0))
	r.pos = nextPos(r.pos, frame.Len())
	frame.Set(r.pos, r.colour)
}