Ejemplo n.º 1
0
func main() {
	oOlliImage := olliImage.NewImage(256, 256)
	for iX := 0; iX < oOlliImage.Width(); iX++ {
		for iY := 0; iY < oOlliImage.Height(); iY++ {
			oOlliImage.DrawPoint(iX, iY, olliImage.NewColor(iX, iY, (iX+iY/2), 255))
		}
	}
	oOlliImage.SaveAsPNG("test.png")
}
Ejemplo n.º 2
0
func main() {

	aArgs := base.GetArgs(map[string]int{})
	sCurrentDir, _ := os.Getwd()

	base.Dump(aArgs)
	base.Dump(sCurrentDir)

	oStream := audio.NewStream()

	var iSampleRate = 44100

	var oRand = rand.New(rand.NewSource(time.Now().Unix()))

	var cSamplesWritten = oStream.Start(iSampleRate, time.Duration(100)*time.Millisecond)
	defer oStream.Stop()

	var oStartTime = time.Now()

	//var iCooldownSamples = iSampleRate * 44 / 100;
	//var oCooldownDuration = (1000 * time.Duration(iCooldownSamples) / time.Duration(iSampleRate)) * time.Millisecond;
	var sDuration = "1h"
	if len(aArgs[""]) > 0 {
		sDuration = aArgs[""][0]
	}
	var oDuration, errParse = time.ParseDuration(sDuration)
	if errParse != nil {
		oDuration = time.Duration(60) * time.Minute
	}
	base.Dump(oDuration)

	var oImage = image.NewImage(20000, 200)
	oImage.FillRect(0, 0, oImage.Width(), oImage.Height(), image.NewColor(255, 255, 255, 255))
	oImage.DrawPoint(10, 10, image.NewColor(255, 0, 0, 255))

	var iNextPlayStart = 0
	for {
		var iSamplesWritten = <-cSamplesWritten
		if iSamplesWritten > iNextPlayStart-5*iSampleRate {
			base.Dump(time.Now())
			var aSound = SoundA(iSampleRate, time.Duration(2)*time.Second/time.Duration(8), 16, 32)
			for iKey := range aSound {
				var nWavePart = float64(iKey) / float64(len(aSound))
				var nVolume = 0.75 + 0.25*float32(math.Sin(math.Pi*nWavePart))
				//nVolume = float32(1.0);
				aSound[iKey] = nVolume * aSound[iKey]
			}
			// for iS := 0; iS < len(aSound); iS ++ {}
			if true || oRand.Intn(32) > 0 {
				oStream.Play(iNextPlayStart, &aSound)
				drawSound(oImage, &aSound, iNextPlayStart, 8)
			}
			iNextPlayStart += len(aSound)
		}
		var oTimePassed = time.Now().Sub(oStartTime)
		if oTimePassed > oDuration {
			break
		}
		time.Sleep(time.Duration(50) * time.Millisecond)
	}

	/*oStream.Play(0, aSound);
	  oStream.Play(0, aSound);*/

	/*for {
	        //aSound = []float32{-1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1};
	//base.Dump("play");
	        //oStream.PlayNow(aSound);
	        time.Sleep(time.Duration(500) * time.Millisecond);
	    }*/

	time.Sleep(time.Second)

}