示例#1
0
func (scheme SchemeBits) Color(x, y float32) (r, g, b float32) {
	if scheme&RealBit == 0 {
		x = 0
	}
	if scheme&ImagBit == 0 {
		y = 0
	}
	θ := math32.Atan2(-y, x)
	d := math32.Hypot(x, y)
	if d > 1 || scheme&MagnitudeBit == 0 {
		d = 1.0
	}
	if scheme&PhaseBit == 0 {
		r, g, b = d, d, d
	} else {
		r, g, b = phaseColor(θ)
		r *= d
		g *= d
		b *= d
	}
	if scheme&RedBit == 0 {
		r = 0
	}
	if scheme&GreenBit == 0 {
		g = 0
	}
	if scheme&BlueBit == 0 {
		b = 0
	}
	return
}
示例#2
0
// Set maximum absolute velocity to v pixels per second.
func SetVelocityMax(v float32) {
	velocityMax = v
	for k := 1; k < len(Zoo); k++ {
		c := &Zoo[k]
		u := math32.Hypot(c.vx, c.vy)
		if u > 0.001 {
			// Scale velocity to new max
			f := velocityMax / u
			c.vx *= f
			c.vy *= f
		} else {
			// Critter is essentially stationary.  Give it a new velocity.
			c.initAlienVelocity()
		}
	}
}
// drawFrequonsSpatial draws the spatial-domain representation of Frequons.
// (xf,yf) is the location of the player.
func drawFrequonsSpatial(pm nimble.PixMap, xf, yf int32) {
	nPastel := pastels.Width()
	for k := 1; k < len(universe.Zoo); k++ {
		c := &universe.Zoo[k]
		d := int32(math32.Hypot(float32(xf)-c.Sx, float32(yf)-c.Sy))
		if c.Show || d < nPastel {
			i := c.ImageIndex()
			if i < len(critterSeq[k]) {
				j := int32(0)
				if !c.Show {
					j = d
				}
				sprite.Draw(pm, int32(math32.Round(c.Sx)), int32(math32.Round(c.Sy)), critterSeq[k][i], pastels.Pixel(j, int32(c.Id)))
			}
		}
	}
	if fourierPort.Contains(mouseX, mouseY) {
		sprite.Draw(pm, xf, yf, critterSeq[0][0], nimble.White)
	}
}
示例#4
0
func makeFragments(radius int, self bool) (frags []fragment) {
	r := float32(radius)
	for y := -r; y <= r; y++ {
		for x := -r; x <= r; x++ {
			d := math32.Hypot(x, y)
			var includePoint bool
			if self {
				// Self is hollow ring
				includePoint = r*0.9 <= d && d <= r*1.1
			} else {
				// Aliens are solid circles
				includePoint = d <= r
			}
			if includePoint {
				// Impart radial velocity to fragment
				var vx, vy, extra float32
				if d > 0 {
					vx, vy = x/d, y/d
					extra = 0.4
				} else {
					vx, vy = 0, 0
					extra = 1.4
				}
				// Random non-radial component
				uy, ux := math32.Sincos(rand.Float32() * (2 * math32.Pi))
				frags = append(frags, fragment{
					x,
					y,
					vx + ux*extra,
					vy + uy*extra,
				})
			}
		}
	}
	return frags
}