コード例 #1
0
ファイル: main.go プロジェクト: GargouillePao/gosfml2ex
func main() {
	ticker := time.NewTicker(time.Second / 30)
	setting := sf.DefaultContextSettings()
	setting.AntialiasingLevel = 8
	renderWindow := sf.NewRenderWindow(sf.VideoMode{800, 600, 32}, "Events (GoSFML2)", sf.StyleDefault, setting)

	grid, err := shapes.NewGirdShape(sf.Vector2f{500, 400}, sf.Vector2f{50, 40}, sf.ColorWhite())

	imageGot, _, err := images.ReadImage("./011.jpg", 0, 0, 500, 400)
	texture, err := images.ReadTextureFromImage(*imageGot)
	if err != nil {
		fmt.Println(err)
		return
	}
	texture.SetSmooth(true)
	grid.SetTexture(texture)
	grid.Move(sf.Vector2f{100, 100})
	grid.Rotate(15)
	var pointX, pointY int
	var gotPoint bool

	for renderWindow.IsOpen() {
		select {
		case <-ticker.C:
			mousePosi := sf.MouseGetPosition(renderWindow)
			mousePosf := sf.Vector2f{float32(mousePosi.X), float32(mousePosi.Y)}
			for event := renderWindow.PollEvent(); event != nil; event = renderWindow.PollEvent() {
				switch event.(type) {
				case sf.EventClosed:
					renderWindow.Close()
				case sf.EventMouseButtonPressed:
					pointX, pointY, gotPoint = grid.GetNearestPointIndex(mousePosf)
				}
			}
			if sf.IsMouseButtonPressed(0) {
				if gotPoint {
					grid.SmoothPointsTo(pointX, pointY, mousePosf, 10, func(data float32) float32 {
						return (mathUtil.Sin(data, -0.5, 1)/2 + 0.5) / 5
					})
				}
			}
		}
		renderWindow.Clear(sf.ColorWhite())
		renderWindow.Draw(grid, sf.DefaultRenderStates())
		renderWindow.Display()
	}
}
コード例 #2
0
ファイル: colors.go プロジェクト: GargouillePao/gosfml2ex
func main() {

	if len(os.Args) < 3 {
		fmt.Println("add the color range function: operiation x ,like + 2 ")
		return
	}

	colorRangeFunc := func(r, g, b, anivalue float32) (outr, outg, outb float32) {
		if os.Args[len(os.Args)-1] != "a" {
			anivalue = 0
		}
		outr = argsCheckAndAddColor(r, 1, anivalue)
		outg = argsCheckAndAddColor(g, 2, anivalue)
		outb = argsCheckAndAddColor(g, 3, anivalue)
		return
	}

	ticker := time.NewTicker(time.Second / 30)
	setting := sf.DefaultContextSettings()
	setting.AntialiasingLevel = 8
	renderWindow := sf.NewRenderWindow(sf.VideoMode{800, 600, 32}, "Events (GoSFML2)", sf.StyleDefault, setting)

	round, err := sf.NewCircleShape()

	imageGot, _, err := images.ReadImage("./011.jpg", -50, -50, 600, 600)
	if err != nil {
		fmt.Println(err)
		return
	}
	imageGot__ := images.ImageEnhanceRGBWithFunc(imageGot, func(r, g, b float32) (outr, outg, outb float32) {
		outr = 127 * float32(math.Sin(float64(r-127)/255*math.Pi+1))
		outg = g
		outb = b
		return
	})
	texture, err := images.ReadTextureFromImage(*imageGot__)
	if err != nil {
		fmt.Println(err)
		return
	}
	texture.SetSmooth(true)
	round.SetPosition(sf.Vector2f{100, 50})
	round.SetRadius(300)
	round.SetTexture(texture, true)

	clip := animations.NewLoopAnimation([]float32{0}, []float32{255}, -1, animations.Pingpong, func(values []float32) {
		imageGot__ = images.ImageEnhanceRGBWithFunc(imageGot, func(r, g, b float32) (outr, outg, outb float32) {
			outr, outg, outb = colorRangeFunc(r, g, b, values[0])
			return
		})
		texture, _ := images.ReadTextureFromImage(*imageGot__)
		round.SetTexture(texture, true)
	}, nil)
	clip.SetFrameCount(60)
	animation := animations.NewAnimation(0)
	animation.AddClip(clip)
	animation.Play()
	for renderWindow.IsOpen() {
		select {
		case <-ticker.C:
			for event := renderWindow.PollEvent(); event != nil; event = renderWindow.PollEvent() {
				switch event.(type) {
				case sf.EventClosed:
					renderWindow.Close()
				}
			}
		}
		animation.Animate()
		renderWindow.Clear(sf.ColorWhite())
		renderWindow.Draw(round, sf.DefaultRenderStates())
		renderWindow.Display()
	}
}