예제 #1
0
static uint8_t tick(void) {

	
	uint8_t x, y;

	uint16_t sin1 = sini(a);
	float x0 = (float)sini(a*4)/256-64;
	float y0 = (float)sini((a*4)+0x1000)/256-64;
	float x1 = (float)sini(a*5)/128-128;
	float y1 = (float)sini((a*5)+0x1000)/128-128;
		
		
	uint8_t joy_x = 128;
	uint8_t joy_y = 128;

	get_stick(&joy_x,&joy_y);
		
	for(y = 0; y < LED_HEIGHT; y++) 
	{
		uint16_t y_part =  sini(sin1+y*20);


		for(x = 0; x < LED_WIDTH; x++) 
		{
			
			float dist = pythagorasf(x0-x,y0-y);
			float dist2 = pythagorasf(y1-x,x1-y);


			uint16_t h = sini(sin1+x*20)+ y_part + sini(dist*500) + sini(dist2*joy_y*2);
			uint16_t h2 = sini(sin1+x*30)+ y_part + sini(dist*joy_x*2) + sini(dist2*350);
			setLedXY(
				x,y,
				sini((h>>2)+a*500)>>8,
				sini((h2>>2)+a*320+0x1555)>>8,
				sini((h>>2)+a*630+0x2aaa)>>8
			);
		}
	}
	char* nick = "";
	uint16_t text_width = get_text_width_16pt(nick);
	draw_text_inv_16pt((LED_WIDTH/2)-(text_width/2),LED_HEIGHT/2-11, nick);
	a+=1;
	if(a==0x4000)
	{
		a=0;
	}
	return 0;
}
예제 #2
0
파일: ex8.c 프로젝트: 128keaton/ltdc
// do the whole preview table and stuff :)
void do_preview(u_char* buf) {
	int asc, x, y, addr;
	u_char st;

	set_color(15, 4, 4);
	set_sprite_8(0, square);

	fill(MODE2_ATTR, 0xF0, MODE2_MAX);

	// start blitting buffer at pixel (16,16)
	addr = map_block(16, 16);

	// 16 chars of width (*8), 16 "lines", jump 256 in VRAM for each line
	blit_ram_vram(buf, addr, 16 * 8, 16, 16 * 8, 256);

	// fill yellow background
	blit_fill_vram(MODE2_ATTR + map_block(8, 8), 0x1A, 8 * 18, 18, 256);

	x = 0; y = 0;

	// preview loop
	while (!get_trigger(0)) {
		// move the cursor and set the zooming
		st = st_dir[get_stick(0)];

		x += (st & st_right) ? 1 : ((st & st_left) ? -1 : 0);
		y += (st & st_down) ? 1 : ((st & st_up) ? -1 : 0);

		x &= 15;
		y &= 15;
		asc = (y << 4) + x;
		put_sprite_8(0, (x + 2) << 3, (y + 2) << 3, 0, 9);

		preview_char(buf + (asc << 3));
	}	
}
예제 #3
0
파일: ex11.c 프로젝트: bitfixer/bitfixer
main() {
	bool flat = false;
	//int *low, *high;
	vector_t light;

	surface_t screen;

	// this is a vector buffer, for the transformations
	// our only object have 5 vertexes, but we'll make space for 32 anyway
	vector_t *pbuffer;

	// off-screen surface buffer
	//u_char* sbuffer = (u_char*)malloc(MODE2_MAX);

	// our solid :)
	object_t triangle;


	heapinit (HPSIZE);
	
	pbuffer = newa(vector_t, 32);

	triangle.mesh = build_mesh();
	triangle.rot_x = triangle.rot_y = triangle.rot_z = 0;
	triangle.trans_x = triangle.trans_y = 0;
	triangle.trans_z = i2f(30);	// remember: we are using fixed-point numbers

	screen.data.ram = sbuffer;

	// polygon rendering buffers
	//low = newa(int, MODE2_HEIGHT);
	//high = newa(int, MODE2_HEIGHT);

	// light source
	light.x = light.y = light.z = i2f(1);
	vector_normalize(&light, &light);

	printf("spinning solid demo\n\n");

	printf("instructions:\n   press [UP] to toggle flat shading\n\n");

	printf("creating look-up tables, please wait\n");
	create_lookup_tables();

	// set screen to graphic mode
	set_color(15, 1, 1);
	set_mode(mode_2);
	fill(MODE2_ATTR, 0xF1, MODE2_MAX);

	//surface_line(&screen, 0, 0, 0, 0); // FIXME: won't compile without this crap

	while (!get_trigger(0)) {
		if (get_stick(0) == 1)
			flat = !flat;

		// rotate a bit
		triangle.rot_y += 2;
		triangle.rot_x += 3;
		triangle.rot_z += 1;

		// clear the off-screen buffer
		memset(sbuffer, 0, MODE2_MAX);	// [*] 

	//surface_line(screen, 0, 0, 10, 10);

		// render the object
		if (flat)
			//object_render_flatshading(&screen, &triangle, pbuffer, low, high, &light);
			object_render_flatshading(&screen, &triangle, pbuffer, stencil, &light);
		else
			object_render_wireframe(&screen, &triangle, pbuffer);

		// show the off-screen buffer
		//vwrite(screen.data.ram, 0, MODE2_MAX); // [*]
		msx_vwrite_direct(screen.data.ram, 0, MODE2_MAX);

		// [*] FIXME: there will be better ways of doing this (soon)
	}

	// go back to text mode
	set_mode(mode_0);

	// deallocate stuff

	mesh_delete(triangle.mesh);
	//free(sbuffer);
	//free(low);
	//free(high);
	//destroy_lookup_tables();
}