Example #1
0
func (c *candle) animateNextFrame(frameCount int, frame framebuffer.Segment) {

	// Yellow
	r := byte(rand.Intn(120) + 135)
	frame.Set(0, framebuffer.NewRgb(r, r, 0))
	// Red
	r = byte(rand.Intn(120) + 135)
	frame.Set(1, framebuffer.NewRgb(r, 0, 0))
	// Yellow
	r = byte(rand.Intn(120) + 135)
	frame.Set(2, framebuffer.NewRgb(r, r, 0))
}
Example #2
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))
}
Example #3
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)
	}
}
Example #4
0
// Append an animation specified as a string
func appendAnimatorsForAction(animators *[]segNameAndAnimator, seg SegmentAction) {

	switch seg.Animation {
	case "Static":
		if colour, err := strconv.ParseInt(seg.Params, 16, 32); err == nil {
			*animators = append(*animators, segNameAndAnimator{seg.Segment,
				newStaticColour(framebuffer.NewRgbFromInt(int(colour)))})
		} else {
			log.WithFields(log.Fields{"params": seg.Params, "Error": err.Error()}).Warn("Bad animataion parameter")
		}

	case "Runner":
		*animators = append(*animators, segNameAndAnimator{seg.Segment,
			newRunner(framebuffer.NewRgb(0, 0, 255))})

	case "Cylon":
		*animators = append(*animators, segNameAndAnimator{seg.Segment, newCylon()})

	case "Rainbow": // TODO MAKE TIME A PARAMETER
		*animators = append(*animators, segNameAndAnimator{seg.Segment, newRainbow(time.Second * 15)})

	case "Sweet Shop": // TODO MAKE TIME A PARAMETER
		*animators = append(*animators, segNameAndAnimator{seg.Segment, newSweetshop(time.Second * 1)})

	case "Candle": // TODO MAKE POSITION AND REPEAT PARAMETERS
		*animators = append(*animators, segNameAndAnimator{seg.Segment, newCandle()})

	case "Christmas": // TODO MAKE TIME A PARAMETER
		*animators = append(*animators, segNameAndAnimator{seg.Segment, newChristmas(time.Second * 1)})

	case "Pulse":
		*animators = append(*animators, segNameAndAnimator{seg.Segment, newPulse()})

	default:
		log.WithField("action", seg.Animation).Warn("Unknown animataion action")
	}
}
Example #5
0
func newChristmas(period time.Duration) *christmas {

	return &christmas{period: period, lightSize: 3,
		lightColours: []framebuffer.Rgb{framebuffer.NewRgb(255, 0, 0), framebuffer.NewRgb(0, 255, 0), framebuffer.NewRgb(0, 0, 255)}}
}
Example #6
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)
}