Ejemplo n.º 1
0
func main() {
	runtime.LockOSThread()

	flag.Parse()
	err := sdl.Init(sdl.INIT_EVERYTHING)
	ck(err)
	defer sdl.Quit()

	sdl.GLSetAttribute(sdl.GL_DOUBLEBUFFER, 1)
	screen = NewDisplay(W, H, sdl.WINDOW_OPENGL|sdl.WINDOW_RESIZABLE)
	ck(err)
	screen.SetLogicalSize(W, H)

	texture, err = screen.CreateTexture(sdl.PIXELFORMAT_ARGB8888, sdl.TEXTUREACCESS_STREAMING, W, H)
	ck(err)
	pixels = make([]uint32, W*H)

	screen.SetTitle("Mandelbrot Set")
	palette = make([]sdl.Color, seqlen)
	buf := make([]int, W*H)
	div = make([][]int, H)
	for i := range div {
		div[i] = buf[W*i:]
	}

	for i := range palette {
		hsv := sdlcolor.HSV{math.Pi / 2, 1, float64(i) / float64(len(palette)) / 0.1}
		palette[i] = sdl.ColorModel.Convert(hsv).(sdl.Color)
	}

	for run {
		event()
		draw()
	}
}
Ejemplo n.º 2
0
func main() {
	log.SetFlags(0)
	runtime.LockOSThread()
	flag.Parse()

	err := sdl.Init(sdl.INIT_VIDEO | sdl.INIT_TIMER)
	ck(err)
	defer sdl.Quit()

	sdl.SetHint(sdl.HINT_RENDER_SCALE_QUALITY, "best")
	window, renderer, err = sdl.CreateWindowAndRenderer(W, H, sdl.WINDOW_RESIZABLE)
	ck(err)

	renderer.SetLogicalSize(W, H)
	window.SetTitle("Cat Clock")

	cat = loadImage(catb)
	eyes = loadImage(eyesb)
	hand.minute = makeTexture(ML*2, ML*2)
	hand.hour = makeTexture(HL+5, HL+5)
	for i := 0; i <= C; i++ {
		tail = append(tail, renderTail(float64(i)*math.Pi/C))
		eye = append(eye, renderEye(float64(i)*math.Pi/C))
	}

	renderer.SetTarget(nil)
	ticker := time.Tick(FPS)
	for {
		event()
		select {
		case <-ticker:
			update()
		default:
		}
		draw()
	}
}
Ejemplo n.º 3
0
func main() {
	runtime.LockOSThread()

	err := sdl.Init(sdl.INIT_EVERYTHING)
	if err != nil {
		log.Fatalln(err)
	}

	defer sdl.Quit()

	window, renderer, err := sdl.CreateWindowAndRenderer(W, H, sdl.WINDOW_RESIZABLE)
	if err != nil {
		log.Fatalln(err)
	}
	texture, err := renderer.CreateTexture(sdl.PIXELFORMAT_ARGB8888, sdl.TEXTUREACCESS_STREAMING, W, H)
	if err != nil {
		log.Fatalln(err)
	}
	pixels := make([]uint32, W*H)
	window.SetTitle("Gasket")
	renderer.SetLogicalSize(W, H)

	v := []Vec2{
		{0.5, 0},
		{0, 1},
		{1, 1},
	}
	p := Vec2{0.5, 0.5}

loop:
	for {
		for {
			ev := sdl.PollEvent()
			if ev == nil {
				break
			}
			switch ev := ev.(type) {
			case sdl.QuitEvent:
				break loop
			case sdl.KeyDownEvent:
				switch ev.Sym {
				case sdl.K_ESCAPE:
					break loop
				}
			}
		}
		r, g, b := rand.Intn(256), rand.Intn(256), rand.Intn(256)

		n := rand.Intn(3)
		q := v[n].Add(p).Scale(.5)

		x := int(q[0] * W)
		y := int(q[1] * H)
		if y*W+x < len(pixels) {
			pixels[y*W+x] = 255<<24 | uint32(r)<<16 | uint32(g)<<8 | uint32(b)
		}
		p = q

		renderer.SetDrawColor(sdlcolor.Black)
		renderer.Clear()
		texture.Update(nil, pixels, W*4)
		renderer.Copy(texture, nil, nil)
		renderer.Present()
	}
}