示例#1
0
文件: clip.go 项目: Ebiroll/openvg
func main() {
	var cx, cy, cw, ch, midy int
	message := "Now is the time for all good men to come to the aid of the party"

	w, h := openvg.Init()
	var speed openvg.VGfloat = 0.5
	var x openvg.VGfloat = 0
	midy = (h / 2)
	fontsize := w / 50
	cx = 0
	ch = fontsize * 2
	cw = w
	cy = midy - (ch / 2)

	rx, ry, rw, rh := openvg.VGfloat(cx), openvg.VGfloat(cy), openvg.VGfloat(cw), openvg.VGfloat(ch)
	// scroll the text, only in the clipping rectangle
	for x = 0; x < rw+speed; x += speed {
		openvg.Start(w, h)
		openvg.Background(255, 255, 255)
		openvg.FillRGB(0, 0, 0, .2)
		openvg.Rect(rx, ry, rw, rh)
		openvg.ClipRect(cx, cy, cw, ch)
		openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
		openvg.FillRGB(0, 0, 0, 1)
		openvg.Text(0, 0, message, "sans", fontsize)
		openvg.ClipEnd()
		openvg.End()
	}
	bufio.NewReader(os.Stdin).ReadBytes('\n')
	openvg.Finish()
	os.Exit(0)
}
示例#2
0
文件: sl.go 项目: Ebiroll/openvg
func main() {
	var sreenHeight, cx, cy, cw, ch, midy int
	message := "Scrolling texts could be useful if the information does not fit on screen"

	w, h := openvg.Init()
	sreenHeight = h
	var speed openvg.VGfloat = 0.5
	var x openvg.VGfloat = 0
	midy = (h / 2)
	fontsize := w / 50
	cx = 0
	ch = fontsize * 2
	cw = w
	cy = midy - (ch / 2)
	var jsonData SLData

	for {
		response, err := http.Get("http://localhost:8000")

		if err == nil {
			defer response.Body.Close()
			contents, err := ioutil.ReadAll(response.Body)
			if err != nil {
				fmt.Printf("Error reading http data, %s", err)
			} else {
				fmt.Printf("Got: %s\n", string(contents))
				if err := json.Unmarshal(contents, &jsonData); err != nil {
					panic(err)
				}
				fmt.Println(jsonData)
			}
		}

		openvg.Start(w, h)
		imgw, imgh := 0, 0
		openvg.Background(255, 255, 255)

		//SLHeight = 60
		var imgPosY = openvg.VGfloat(sreenHeight - 70)
		openvg.Image(4, imgPosY, imgw, imgh, "SL.jpg")

		var TAB1 = openvg.VGfloat(4 * w / 20)
		var TAB2 = openvg.VGfloat(8 * w / 20)

		rx1, rw1, rh1 := openvg.VGfloat(cx), openvg.VGfloat(cw), openvg.VGfloat(ch)
		ty := 0
		rix := 0

		// Buses
		for ty = sreenHeight - (80 + int(rh1)); ty > 0 && rix < len(jsonData.ResponseData.Buses); ty -= ch {
			tempy := openvg.VGfloat(ty)
			//ry := openvg.VGfloat(ty)
			if rix%2 == 0 {
				openvg.FillRGB(0, 0, 0, .2)
				//openvg.Rect(rx1, tempy, rw1, rh1)
				openvg.FillRGB(0, 0, 0, 1)
				tempy = tempy + 6.0
			} else {
				openvg.FillRGB(0, 0, 0, .4)
				openvg.Rect(rx1, tempy, rw1, rh1)
				tempy = tempy + 6.0
				openvg.FillRGB(0, 0, 0, 1)
			}
			openvg.Text(rx1, tempy, jsonData.ResponseData.Buses[rix].LineNumber, "sans", fontsize)
			drawTypeOfTransport(rx1+60, tempy+2, rw1, ch-20, jsonData.ResponseData.Buses[rix].TransportMode)

			openvg.Text(rx1+100, tempy, jsonData.ResponseData.Buses[rix].StopPointDesignation, "sans", fontsize)
			openvg.Text(rx1+TAB1, tempy, jsonData.ResponseData.Buses[rix].DisplayTime, "sans", fontsize)
			var dest = jsonData.ResponseData.Buses[rix].Destination
			dest = replaceAO(dest)
			openvg.Text(rx1+TAB2, tempy, dest, "sans", fontsize)

			//openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
			//openvg.Background(255,255,0)
			rix = rix + 1
		}
		var trainIx = 0
		for ty = ty - 20; ty > 0 && trainIx < len(jsonData.ResponseData.Trains); ty -= ch {
			tempy := openvg.VGfloat(ty)
			//ry := openvg.VGfloat(ty)
			if rix%2 == 0 {
				openvg.FillRGB(0, 0, 0, .2)
				//openvg.Rect(rx1, tempy, rw1, rh1)
				openvg.FillRGB(0, 0, 0, 1)
				tempy = tempy + 6.0
			} else {
				openvg.FillRGB(0, 0, 0, .4)
				openvg.Rect(rx1, tempy, rw1, rh1)
				tempy = tempy + 6.0
				openvg.FillRGB(0, 0, 0, 1)
			}
			openvg.Text(rx1, tempy, jsonData.ResponseData.Trains[trainIx].LineNumber, "sans", fontsize)
			drawTypeOfTransport(rx1+55, tempy+4, rw1, ch-20, jsonData.ResponseData.Trains[trainIx].TransportMode)
			openvg.Text(rx1+TAB1, tempy, jsonData.ResponseData.Trains[trainIx].DisplayTime, "sans", fontsize)
			var dest = jsonData.ResponseData.Trains[trainIx].Destination
			dest = replaceAO(dest)
			openvg.Text(rx1+TAB2, tempy, dest, "sans", fontsize)

			//openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
			//openvg.Background(255,255,0)
			trainIx = trainIx + 1
			rix = rix + 1
		}

		//openvg.End()
		openvg.SaveEnd("dump.raw")

		time.Sleep(60 * time.Second)
	}

	bufio.NewReader(os.Stdin).ReadBytes('\n')

	rx, ry, rw, rh := openvg.VGfloat(cx), openvg.VGfloat(cy), openvg.VGfloat(cw), openvg.VGfloat(ch)
	// scroll the text, only in the clipping rectangle
	for x = 0; x < rw+speed; x += speed {
		openvg.Start(w, h)
		openvg.Background(255, 255, 255)
		openvg.FillRGB(0, 0, 0, .2)
		openvg.Rect(rx, ry, rw, rh)
		openvg.ClipRect(cx, cy, cw, ch)
		openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
		openvg.FillRGB(0, 0, 0, 1)
		openvg.Text(0, 0, message, "sans", fontsize)
		openvg.ClipEnd()
		openvg.End()
	}
	bufio.NewReader(os.Stdin).ReadBytes('\n')
	openvg.Finish()
	os.Exit(0)
}
示例#3
0
func main() {
	var cy, ch, midy int
	var message []string
	message = []string{" Black", "cats", "skitter", "and", "ghouls", "patter", "Happy", "Halloween"}

	w, h := openvg.Init()
	//var speed openvg.VGfloat = 0.5
	var x openvg.VGfloat = 0
	var vw, vh openvg.VGfloat
	var midxx openvg.VGfloat = openvg.VGfloat(w / 2)
	midy = (h / 2)
	fontsize := w / 8
	//cx = 0
	ch = fontsize * 2
	//cw = w
	cy = midy - (ch / 2)
	var redness uint8
	var index int

	//rx , rw, rh := openvg.VGfloat(cx) , openvg.VGfloat(cw), openvg.VGfloat(ch)
	ry := openvg.VGfloat(cy)
	// scroll the text, only in the clipping rectangle
	index = 0
	for {
		for redness = 255; redness > 16; redness -= 2 {

			ch = fontsize * 2
			//cw = w
			cy = midy - (ch / 2)
			openvg.Start(w, h)
			openvg.Background(redness, 0, 0)
			openvg.FillRGB(0, 0, 0, .2)
			//openvg.Rect(rx, ry, rw, rh)
			//openvg.ClipRect(cx, cy, cw, ch)
			openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
			openvg.FillRGB(0, 0, 0, 1)
			var fsiz int
			fsiz = int(255 - redness)
			openvg.TextMid(midxx, 0, message[index], "shf", fsiz)
			openvg.ClipEnd()
			openvg.End()
		}
		index = (index + 1) % 8
		if index == 0 {
			vw = openvg.VGfloat(w) - 200
			vh = openvg.VGfloat(h) - 200
			openvg.Video(100.0, 100.0, vw, vh, "test.h264")
		}
		if index == 0 {
			var test, oix int
			var xpos [40]float32
			var ypos [40]float32
			var rotate [40]float32
			var spdx [40]float32
			var spdy [40]float32

			// Init positions
			for test = 0; test < 40; test++ {
				var rot = rand.Float32()
				var rax = rand.Float32()
				rax = float32(w) * rax
				var ray = rand.Float32()
				ray = float32(h) * ray

				spdx[test] = float32(test) * rand.Float32()
				spdy[test] = float32(test) * rand.Float32()

				ypos[test] = ray
				xpos[test] = rax
				rot = 0
				rotate[test] = rot

			}

			// Move around
			for oix = 0; oix < 100; oix++ {
				openvg.Start(w, h)
				openvg.Background(0, 0, 0)
				openvg.FillColor("red")

				for test = 0; test < 40; test++ {
					var rot = rand.Float32()
					var rax = rand.Float32()*float32(4.0) - float32(2.0)
					var ray = float32(4.0)*rand.Float32() - float32(2.0)

					spdy[test] += ray
					spdx[test] += rax

					xpos[test] = xpos[test] + spdx[test]
					ypos[test] = ypos[test] + spdy[test]
					rotate[test] = rotate[test] + float32(rot*4-2)

					openvg.Rotate(openvg.VGfloat(rotate[test]))
					openvg.Translate(openvg.VGfloat(xpos[test]), openvg.VGfloat(ypos[test]))

					openvg.TextMid(0, 0, "Happy Halloween", "shf", 30)

					openvg.Translate(-openvg.VGfloat(xpos[test]), -openvg.VGfloat(ypos[test]))
					openvg.Rotate(-openvg.VGfloat(rotate[test]))

				}
				openvg.End()
			}

		}
	}
	bufio.NewReader(os.Stdin).ReadBytes('\n')
	openvg.Finish()
	os.Exit(0)
}