Exemplo n.º 1
0
void clear_screens() {
    clear_screen(0);
    clear_screen(1);
}
Exemplo n.º 2
0
//=================================================
// setting up all the necessary things for the 
// start of a new level
//=================================================
void TheMathGame::startLevel(int level){
	clear_screen();
	currentLevel = level;
	clockTicksCurrentLevel = 0;

	// setting up player1 for a new level
	player1.setLives(3);
	player1.setPosition(Point(10, 9));
	player1.changeDirection(Direction::RIGHT);

	if (currentLevel >= 1 && currentLevel < 20){
		player1.resetExercise();
		player1.createExercise(currentLevel);
	}
	else if (currentLevel == 20){
		player1.resetExercise();
		player1.createAdvExercise(currentLevel);
	}
	else{
		player1.resetAdvExercise();
		player1.createAdvExercise(currentLevel);
	}

	player1.resetPlayerAlive();
	player1.resetPlayerDone();
	player1.setShotsCounter(5);

	// setting up player2 for a new level
	player2.setLives(3);
	player2.setPosition(Point(70, 9));
	player2.changeDirection(Direction::LEFT);

	if (currentLevel >= 1 && currentLevel < 20){
		player2.resetExercise();
		player2.createExercise(currentLevel);
	}
	else if (currentLevel == 20){
		player2.resetExercise();
		player2.createAdvExercise(currentLevel);
	}
	else{
		player2.resetAdvExercise();
		player2.createAdvExercise(currentLevel);
	}
	player2.resetPlayerAlive();
	player2.resetPlayerDone();
	player2.setShotsCounter(5);

	//settinp up status bar for a new level
	stBar.setTimeLeft(300);
	stBar.setCurrentLevel(currentLevel);
	stBar.drawStatusBar();

	// erasing the screen matrix
	myScreen.eraseMatrix();

	// erase all bullets from screen and cleans the array
	playShooting.initArr();

	// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	// "NEW CODE EX3, author=Dror Moyal, date=2015-06-02,  author=Maya Bugana, date=2015-31-05    
	// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//inits all creatures
	RowsFlyerR.initObject(Direction::RIGHT, Point(30, 23));
	RowsFlyerL.initObject(Direction::LEFT, Point(50, 15));
	ColFlyerUP.initObject(Direction::UP, Point(45, 23));
	ColFlyerD.initObject(Direction::DOWN, Point(55, 15));
	eater1.initObject(Direction::DOWN, Point(10, 19));
	eater2.initObject(Direction::UP, Point(70, 19));
	//+++++++++++++++++++++
	// END of NEW CODE EX3
	//+++++++++++++++++++++
}
Exemplo n.º 3
0
LRESULT CALLBACK MainDlg(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
	PAINTSTRUCT ps;
	BITMAPINFO bmi;
	char str[255];
	static int timer=FALSE;
	static int xpos=0,ypos=0,LMB=FALSE,dx=0,dy=0;
	static HWND hview=0;
	static HGLRC hglrc=0;
	static HDC hdc=0;
	int i;

#ifdef _DEBUG
//	if(message!=0x200&&message!=0x84&&message!=0x20&&message!=WM_ENTERIDLE)
//		debug_printf("message=%08X wparam=%08X lparam=%08X\n",message,wparam,lparam);
#endif	
	switch(message)
	{
	case WM_INITDIALOG:
		bufA=malloc(bwidth*bheight*bdepth);
		bufB=malloc(bwidth*bheight*bdepth);
		if(bufA==0 || bufB==0)
			MessageBox(hwnd,"malloc failed","error",MB_OK);
		else{
			memset(bufB,0,bwidth*bheight*bdepth);
			rand_fill(bufA,bwidth,bheight,bdepth);
		}
		create_grippy(hwnd);
		BringWindowToTop(hwnd);
		BringWindowToTop(hwnd);
		update_title(hwnd);
		SendMessage(hwnd,WM_KEYDOWN,VK_TAB,0);
		SendMessage(hwnd,WM_LBUTTONDOWN,0,0);
		create_view_windows(hwnd,&hview);
		init_ogl(hview,&hglrc,&hdc);
		resize_view(hwnd,hview);
		break;
	case WM_SIZE:
		{
			int w,h;
			w=LOWORD(lparam);
			h=HIWORD(lparam);
			grippy_move(hwnd);
			resize_view(hwnd,hview);
			reshape(w,h);
		}
		break;
	case WM_TIMER:
		if(LMB)
			handle_click(xpos,ypos);
		display_view1(hview,hglrc);
		break;
	case WM_COMMAND:

		switch(LOWORD(wparam))
		{
		case IDC_ONTOP:
			SetWindowPos(hwnd,IsDlgButtonChecked(hwnd,LOWORD(wparam))? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
			break;
		case WM_DESTROY:
		#ifndef _DEBUG
			if(MessageBox(hwnd,"Sure you want to quit?","QUIT",MB_OKCANCEL)!=IDOK)
				break;
		#endif
			PostQuitMessage(0);
			break;
		}
		break;
	case WM_PAINT:
	/*
		hdc=BeginPaint(hwnd,&ps);
		memset(&bmi,0,sizeof(BITMAPINFO));
		bmi.bmiHeader.biBitCount=24;
		bmi.bmiHeader.biWidth=BUF_WIDTH;
		bmi.bmiHeader.biHeight=BUF_HEIGHT;
		bmi.bmiHeader.biPlanes=1;
		bmi.bmiHeader.biSize=40;
		if(stretch)
			StretchDIBits(hdc,0,0,client_rect.right,client_rect.bottom,0,0,BUF_WIDTH,BUF_HEIGHT,buffer,&bmi,DIB_RGB_COLORS,SRCCOPY);
		else
			SetDIBitsToDevice(hdc,0,0,BUF_WIDTH,BUF_HEIGHT,0,0,0,BUF_WIDTH,buffer,&bmi,DIB_RGB_COLORS);
		screen_updated=TRUE;
		EndPaint(hwnd,&ps);
		*/
		break;
	case WM_CLOSE:
	case WM_QUIT:
		PostQuitMessage(0);
		break;
	case WM_DROPFILES:
		break;
	case WM_RBUTTONDOWN:
	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
		xpos=LOWORD(lparam);
		ypos=HIWORD(lparam);
		break;
	case WM_MOUSEMOVE:
		{
			int x,y;
			int key=wparam;
			x=LOWORD(lparam);
			y=HIWORD(lparam);
			if(key&MK_LBUTTON){
				x=xpos-x;
				ry=x;
				y=ypos-y;
				rx=y;
				printf("rz=%.1f ry=%.1f\n",rx,ry);
			}
			if(key&MK_RBUTTON){
				x=xpos-x;
				rz=-x;
				printf("z=%.1f\n",rz);
			}
			update_title(hwnd);
		}
		break;
	case WM_MOUSEWHEEL:
		if(wparam&0x80000000)
			SendMessage(hwnd,WM_KEYDOWN,VK_NEXT,0);
		else
			SendMessage(hwnd,WM_KEYDOWN,VK_PRIOR,0);
		break;
	case WM_KEYUP:
		break;
	case WM_KEYDOWN:
		{
			int ctrl=GetKeyState(VK_CONTROL)&0x8000;
			int shift=GetKeyState(VK_SHIFT)&0x8000;

#ifdef _DEBUG
//		debug_printf("message=%08X wparam=%08X lparam=%08X\n",message,wparam,lparam);
#endif
		switch(wparam)
		{
		case VK_INSERT:
			clear_screen();
			break;
		case 0xBD:
		case 0xBB:
			break;
		case 'Q':
			rx=ry=rz=0;
			printf("angles reset\n");
			break;
		case 'W':
			break;
		case 0xC0:
			rand_fill(swap?bufB:bufA,bwidth,bheight,bdepth);
			break;
		case 'K':
			set_offsety(1);
			break;
		case 'L':
			set_offsety(-1);
			break;
		case 'X':
			if(shift)
				scale+=10;
			else
				scale++;
			printf("scale=%i\n",scale);
			break;
		case 'Z':
			if(shift)
				scale-=10;
			else
				scale--;
			printf("scale=%i\n",scale);
			break;
		//case 0xC0:
			change_direction(0);
			rx=ry=rz=0;
			break;
		case '0':
		case '1':
			//tube();
			frame_step=1;
			break;
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			change_direction(wparam-'0');
			break;

		case VK_SPACE:
			break;
		case VK_TAB:
			if(timer)
				KillTimer(hwnd,1);
			else
				SetTimer(hwnd,1,60,NULL);
			timer=!timer;
			break;
		case VK_F1:
			display_help(hwnd);
			break;
/*		case VK_F2:
			i=CreateDialog(ghInstance,MAKEINTRESOURCE(IDD_DIALOG2),hwnd,request_value);
			ShowWindow(i,SW_SHOWNORMAL);
			debug_printf("return =%i\r\n",i);
			break;*/
		case VK_F5:
			break;
		case VK_F9:
			stretch=!stretch;
			break;
		case 0xDEADBEEF:
			break;
		case VK_DOWN:
			if(GetKeyState(VK_CONTROL)&0x8000)
				move_center(3);
			else if(GetKeyState(VK_SHIFT)&0x8000)
				change_direction(12);
			else
				change_direction(2);
			break;
		case VK_UP:
			if(GetKeyState(VK_CONTROL)&0x8000)
				move_center(4);
			else if(GetKeyState(VK_SHIFT)&0x8000)
				change_direction(11);
			else
				change_direction(1);
			break;
		case VK_LEFT:
			if(GetKeyState(VK_CONTROL)&0x8000)
				move_center(1);
			else if(GetKeyState(VK_SHIFT)&0x8000)
				change_direction(14);
			else
				change_direction(4);
			break;
		case VK_RIGHT:
			if(GetKeyState(VK_CONTROL)&0x8000)
				move_center(2);
			else if(GetKeyState(VK_SHIFT)&0x8000)
				change_direction(13);
			else
				change_direction(3);
			break;
		case VK_ADD:
			break;
		case VK_SUBTRACT:
			break;
		case VK_NEXT: //page key
			if(GetKeyState(VK_CONTROL)&0x8000)
				;
			else if(GetKeyState(VK_SHIFT)&0x8000)
				;
			change_direction(100);
			break;
		case VK_PRIOR: //page key
			if(GetKeyState(VK_CONTROL)&0x8000)
				;
			else if(GetKeyState(VK_SHIFT)&0x8000)
				;
			change_direction(100);
			break;
		case VK_HOME:
			change_direction(5);
			break;
		case VK_END:
			;
			break;
		case ZOOM_IN_KEY: //[
			if(GetKeyState(VK_SHIFT)&0x8000){
				if(GetKeyState(VK_CONTROL)&0x8000)
					;
				else
					;
			}
			else
				;
			break;
		case ZOOM_OUT_KEY: //]
			if(GetKeyState(VK_SHIFT)&0x8000){
				if(GetKeyState(VK_CONTROL)&0x8000)
					;
				else
					;
			}
			else
				;
			break;
		case 0xBE:  //>
			if(GetKeyState(VK_SHIFT)&0x8000){
				if(GetKeyState(VK_CONTROL)&0x8000)
					;
				else
					;
			}
			else
				;
			break;
		case 0xBC:  //<
			if(GetKeyState(VK_SHIFT)&0x8000){
				if(GetKeyState(VK_CONTROL)&0x8000)
					;
				else
					;
			}
			else
				;
			break;
		case 'V':
			if(GetKeyState(VK_CONTROL)&0x8000){
				if(OpenClipboard(NULL)){
					char *p=GetClipboardData(CF_TEXT);
					if(p!=0){
						strncpy(str,p,sizeof(str));
						SetDlgItemText(hwnd,IDC_EDIT1,str);
					}
					CloseClipboard();
				}
			}
			break;
		case VK_ESCAPE:
			if(MessageBox(hwnd,"Sure you want to quit?","QUIT",MB_OKCANCEL)==IDOK)
				PostQuitMessage(0);
			break;
		}
		update_title(hwnd);
		}
		break;
	}
	return 0;
}
Exemplo n.º 4
0
void
initialize(void)
{
 register int i;

 /* Loop over all threads in the thread table and reset the owner. */
 for(i=0; i<MAX_NUMBER_OF_THREADS; i++)
 {
  thread_table[i].data.owner=-1; /* -1 is an illegal process_table index.
                                     We use that to show that the thread
                                     is dormant. */
 }

 /* Loop over all processes in the thread table and mark them as not
    executing. */
 for(i=0; i<MAX_NUMBER_OF_PROCESSES; i++)
 {
  process_table[i].threads=0;    /* No executing process has less than 1
                                    thread. */
 }

 /* Initialize the ready queue. */
 thread_queue_init(&ready_queue);

 /* Initialize the list of blocked threads waiting for the keyboard. */
 thread_queue_init(&keyboard_blocked_threads);

 /* Calculate the number of pages. */
 memory_pages = memory_size/(4*1024);

 {
  /* Calculate the number of frames occupied by the kernel and executable
     images. */
  const register int k=first_available_memory_byte/(4*1024);

  /* Mark the pages that are used by the kernel or executable images as taken
    by the kernel (-2 in the owner field). */
  for(i=0; i<k; i++)
  {
   page_frame_table[i].owner=-2;
   page_frame_table[i].free_is_allowed=0;
  }

  /* Loop over all the rest page frames and mark them as free (-1 in owner
     field). */
  for(i=k; i<memory_pages; i++)
  {
   page_frame_table[i].owner=-1;
   page_frame_table[i].free_is_allowed=1;
  }

  /* Mark any unusable pages as taken by the kernel. */
  for(i=memory_pages; i<MAX_NUMBER_OF_FRAMES; i++)
  {
   page_frame_table[i].owner=-2;
   page_frame_table[i].free_is_allowed=0;
  }
 }

 /* Go through the linked list of executable images and verify that they
    are correct. At the same time build the executable_table. */
 {
  const struct executable_image* image;

  for (image=ELF_images_start; 0!=image; image=image->next)
  {
   unsigned long      image_size;

   /* First calculate the size of the image. */
   if (0 != image->next)
   {
    image_size = ((char *) (image->next)) - ((char *) image) -1;
   }
   else
   {
    image_size = ((char *) ELF_images_end) - ((char *) image) - 1;
   }

   /* Check that the image is an ELF image and that it is of the
      right type. */
   if (
       /* EI_MAG0 - EI_MAG3 have to be 0x7f 'E' 'L' 'F'. */
       (image->elf_image.e_ident[EI_MAG0] != 0x7f) ||
       (image->elf_image.e_ident[EI_MAG1] != 'E') ||
       (image->elf_image.e_ident[EI_MAG2] != 'L') ||
       (image->elf_image.e_ident[EI_MAG3] != 'F') ||
       /* Check that the image is a 64-bit image. */
       (image->elf_image.e_ident[EI_CLASS] != 2) ||
       /* Check that the image is a little endian image. */
       (image->elf_image.e_ident[EI_DATA] != 1) ||
       /* And that the version of the image format is correct. */
       (image->elf_image.e_ident[EI_VERSION] != 1) ||
       /* NB: We do not check the ABI or ABI version. We really should
          but currently those fields are not set properly by the build
          tools. They are both set to zero which means: System V ABI,
          third edition. However, the ABI used is clearly not System V :-) */

       /* Check that the image is executable. */
       (image->elf_image.e_type != 2) ||
       /* Check that the image is executable on AMD64. */
       (image->elf_image.e_machine != 0x3e) ||
       /* Check that the object format is corrent. */
       (image->elf_image.e_version != 1) ||
       /* Check that the processor dependent flags are all reset. */
       (image->elf_image.e_flags != 0) ||
       /* Check that the length of t   he header is what we expect. */
       (image->elf_image.e_ehsize != sizeof(struct Elf64_Ehdr)) ||
       /* Check that the size of the program header table entry is what
          we expect. */
       (image->elf_image.e_phentsize != sizeof(struct Elf64_Phdr)) ||
       /* Check that the number of entries is reasonable. */
       (image->elf_image.e_phnum < 0) ||
       (image->elf_image.e_phnum > 8) ||
       /* Check that the entry point is within the image. */
       (image->elf_image.e_entry < 0) ||
       (image->elf_image.e_entry >= image_size) ||
       /* Finally, check that the program header table is within the image. */
       (image->elf_image.e_phoff > image_size) ||
       ((image->elf_image.e_phoff +
         image->elf_image.e_phnum * sizeof(struct Elf64_Phdr)) > image_size )
      )

   {
    /* There is something wrong with the image. */
    while (1)
    {
     kprints("Kernel panic! Corrupt executable image.\n");
    }
    continue;
   }

   /* Now check the program header table. */
   {
    int                program_header_index;
    struct Elf64_Phdr* program_header = ((struct Elf64_Phdr*)
                                         (((char*) &(image->elf_image)) +
                                          image->elf_image.e_phoff));
    unsigned long      memory_footprint_size = 0;

    for (program_header_index = 0;
         program_header_index < image->elf_image.e_phnum;
         program_header_index++)
    {
     /* First sanity check the entry. */
     if (
         /* Check that the segment is a type we can handle. */
         (program_header[program_header_index].p_type < 0) ||
         (!((program_header[program_header_index].p_type == PT_NULL) ||
            (program_header[program_header_index].p_type == PT_LOAD) ||
            (program_header[program_header_index].p_type == PT_PHDR))) ||
         /* Look more carefully into loadable segments. */
         ((program_header[program_header_index].p_type == PT_LOAD) &&
           /* Check if any flags that we can not handle is set. */
          (((program_header[program_header_index].p_flags & ~7) != 0) ||
           /* Check if sizes and offsets look sane. */
           (program_header[program_header_index].p_offset < 0) ||
           (program_header[program_header_index].p_vaddr < 0) ||
           (program_header[program_header_index].p_filesz < 0) ||
           (program_header[program_header_index].p_memsz < 0) ||
          /* Check if the segment has an odd size. We require the
             segment size to be an even multiple of 8. */
           (0 != (program_header[program_header_index].p_memsz&7)) ||
           (0 != (program_header[program_header_index].p_filesz&7)) ||
           /* Check if the segment goes beyond the image. */
           ((program_header[program_header_index].p_offset +
             program_header[program_header_index].p_filesz) > image_size)))
        )
     {
      while (1)
      {
       kprints("Kernel panic! Corrupt segment.\n");
      }
     }

     /* Check that all PT_LOAD segments are contiguous starting from
        address 0. Also, calculate the memory footprint of the image. */
     if (program_header[program_header_index].p_type == PT_LOAD)
     {
      if (program_header[program_header_index].p_vaddr !=
          memory_footprint_size)
      {
       while (1)
       {
        kprints("Kernel panic! Executable image has illegal memory layout.\n");
       }
      }

      memory_footprint_size += program_header[program_header_index].p_memsz;
     }
    }

    executable_table[executable_table_size].memory_footprint_size =
     memory_footprint_size;
   }

   executable_table[executable_table_size].elf_image = &(image->elf_image);
   executable_table_size += 1;

   kprints("Found an executable image.\n");

   if (executable_table_size >= MAX_NUMBER_OF_PROCESSES)
   {
    while (1)
    {
     kprints("Kernel panic! Too many executable images found.\n");
    }
   }
  }
 }

 /* Check that actually some executable files are found. Also check that the
    thread structure is of the right size. The assembly code will break if it
    is not. Finally, initialize memory protection. You will implement memory
    protection in task A4. */

 if ((0 >= executable_table_size) ||
     (1024 != sizeof(union thread)))
 {
  while (1)
  {
   kprints("Kernel panic! Can not boot.\n");
  }
 }

 initialize_memory_protection();
 initialize_ports();
 initialize_thread_synchronization();

 /* All sub-systems are now initialized. Kernel areas can now get the right
    memory protection. */

 {
  /* Use the kernel's ELF header. */
  struct Elf32_Phdr* program_header = ((struct Elf32_Phdr*)
                                       (((char*) (0x00100000)) +
                                        ((struct Elf32_Ehdr*)0x00100000)->
                                          e_phoff));

  /* Traverse the program header. */
  short              number_of_program_header_entries =
                      ((struct Elf32_Ehdr*)0x00100000)->e_phnum;
  int                i;
  for(i=0; i<number_of_program_header_entries; i++)
  {
   if (PT_LOAD == program_header[i].p_type)
   {
    /* Set protection on each segment. */

    update_memory_protection(kernel_page_table_root,
                             program_header[i].p_vaddr,
                             program_header[i].p_memsz,
                             (program_header[i].p_flags&7) | PF_KERNEL);
   }
  }
 }

 /* Start running the first program in the executable table. */

 /* Use the ELF program header table and copy the right portions of the
    image to memory. This is done by prepare_process. */

 {
  struct prepare_process_return_value prepare_process_ret_val =
   prepare_process(executable_table[0].elf_image,
                   0,
                   executable_table[0].memory_footprint_size);

  if (0 == prepare_process_ret_val.first_instruction_address)
  {
   while (1)
   {
    kprints("Kernel panic! Can not start process 0!\n");
   }
  }

  /* Start executable program 0 as process 0. At this point, there are no
     processes so we can just grab entry 0 and use it. */
  process_table[0].parent=-1;    /* We put -1 to indicate that there is no
                                    parent process. */
  process_table[0].threads=1;

  /*  all processes should start with an allocated port with id zero */
  if (-1 == allocate_port(0,0))
  {
   while(1)
   {
    kprints("Kernel panic! Can not initialize the IPC system!\n");
   }
  }

  /* Set the page table address. */
  process_table[0].page_table_root =
   prepare_process_ret_val.page_table_address;
  cpu_private_data.page_table_root =
   prepare_process_ret_val.page_table_address;

  /* We need a thread. We just take the first one as no threads are running or
     have been allocated at this point. */
  thread_table[0].data.owner=0;  /* 0 is the index of the first process. */

  /* We reset all flags and enable interrupts */
  thread_table[0].data.registers.integer_registers.rflags=0x200;

  /* And set the start address. */
  thread_table[0].data.registers.integer_registers.rip =
   prepare_process_ret_val.first_instruction_address;

  /* Finally we set the current thread. */
  cpu_private_data.thread_index = 0;
 }

 /* Set up the timer hardware to generate interrupts 200 times a second. */
 outb(0x43, 0x36);
 outb(0x40, 78);
 outb(0x40, 23);

 /* Set up the keyboard controller. */
 
 /* Empty the keyboard buffer. */
 {
  register unsigned char status_byte;
  do
  {
   status_byte=inb(0x64);
   if ((status_byte&3)==1)
   {
    inb(0x60);
   }
  } while((status_byte&0x3)!=0x0);
 }

 /* Change the command byte to enable interrupts. */
 outb(0x64, 0x20);
 {
  register unsigned char keyboard_controller_command_byte;

  {
   register unsigned char status_byte;
   do
   {
    status_byte=inb(0x64);
   } while((status_byte&3)!=1);
  }

  keyboard_controller_command_byte=inb(0x60);

  /* Enable keyboard interrupts. */
  keyboard_controller_command_byte|=1;

  kprints("Keyboard controller command byte:");
  kprinthex(keyboard_controller_command_byte);
  kprints("\n");

  outb(0x64, 0x60);
  outb(0x60, keyboard_controller_command_byte);

  /* Wait until command is done. */
  {
   register unsigned char status_byte;
   do
   {
    status_byte=inb(0x64);
   } while((status_byte&0x2)!=0x0);
  }
 } 

 /* Now we set up the interrupt controller to allow timer and keyboard 
    interrupts. */
 outb(0x20, 0x11);
 outb(0xA0, 0x11);

 outb(0x21, 0x20);
 outb(0xA1, 0x28);

 outb(0x21, 1<<2);
 outb(0xA1, 2);

 outb(0x21, 1);
 outb(0xA1, 1);

 outb(0x21, 0xfc);
 outb(0xA1, 0xff);

 clear_screen();

 kprints("\n\n\nThe kernel has booted!\n\n\n");

 /* Now go back to the assembly language code and let the process run. */
}
Exemplo n.º 5
0
/*
 * Display main menu.
 */
void oedit_disp_menu(struct descriptor_data *d)
{
  char tbitbuf[MAX_INPUT_LENGTH], ebitbuf[MAX_INPUT_LENGTH];
  struct obj_data *obj;

  obj = OLC_OBJ(d);
  get_char_colors(d->character);
  clear_screen(d);

  /*
   * Build buffers for first part of menu.
   */
  sprinttype(GET_OBJ_TYPE(obj), item_types, tbitbuf, sizeof(tbitbuf));
  sprintbitarray(GET_OBJ_EXTRA(obj), extra_bits, EF_ARRAY_MAX, ebitbuf);

  /*
   * Build first half of menu.
   */
  write_to_output(d,
	  "-- Item number : [%s%d%s]\r\n"
	  "%s1%s) Namelist : %s%s\r\n"
	  "%s2%s) S-Desc   : %s%s\r\n"
	  "%s3%s) L-Desc   :-\r\n%s%s\r\n"
	  "%s4%s) A-Desc   :-\r\n%s%s"
	  "%s5%s) Type        : %s%s\r\n"
	  "%s6%s) Extra flags : %s%s\r\n",

	  cyn, OLC_NUM(d), nrm,
	  grn, nrm, yel, (obj->name && *obj->name) ? obj->name : "undefined",
	  grn, nrm, yel, (obj->short_description && *obj->short_description) ? obj->short_description : "undefined",
	  grn, nrm, yel, (obj->description && *obj->description) ? obj->description : "undefined",
	  grn, nrm, yel, (obj->action_description && *obj->action_description) ? obj->action_description : "<not set>\r\n",
	  grn, nrm, cyn, tbitbuf,
	  grn, nrm, cyn, ebitbuf
	  );
  /*
   * Send first half.
   */

  /*
   * Build second half of menu.
   */
  sprintbitarray(GET_OBJ_WEAR(OLC_OBJ(d)), wear_bits, EF_ARRAY_MAX, tbitbuf);
  sprintbitarray(GET_OBJ_PERM(OLC_OBJ(d)), affected_bits, EF_ARRAY_MAX, ebitbuf);

  write_to_output(d,
	  "%s7%s) Wear flags  : %s%s\r\n"
	  "%s8%s) Weight      : %s%d\r\n"
	  "%s9%s) Cost        : %s%d\r\n"
	  "%sA%s) Cost/Day    : %s%d\r\n"
	  "%sB%s) Timer       : %s%d\r\n"
	  "%sC%s) Values      : %s%d %d %d %d\r\n"
	  "%sD%s) Applies menu\r\n"
	  "%sE%s) Extra descriptions menu\r\n"
          "%sM%s) Min Level   : %s%d\r\n"
          "%sP%s) Perm Affects: %s%s\r\n"
          "%sS%s) Script      : %s%s\r\n"
          "%sQ%s) Quit\r\n"
	  "Enter choice : ",

	  grn, nrm, cyn, tbitbuf,
	  grn, nrm, cyn, GET_OBJ_WEIGHT(obj),
	  grn, nrm, cyn, GET_OBJ_COST(obj),
	  grn, nrm, cyn, GET_OBJ_RENT(obj),
	  grn, nrm, cyn, GET_OBJ_TIMER(obj),
	  grn, nrm, cyn, GET_OBJ_VAL(obj, 0),
	  GET_OBJ_VAL(obj, 1),
	  GET_OBJ_VAL(obj, 2),
	  GET_OBJ_VAL(obj, 3),
	  grn, nrm, grn, nrm,
          grn, nrm, cyn, GET_OBJ_LEVEL(obj),
          grn, nrm, cyn, ebitbuf,
          grn, nrm, cyn, OLC_SCRIPT(d) ? "Set." : "Not Set.",
          grn, nrm
  );
  OLC_MODE(d) = OEDIT_MAIN_MENU;
}
Exemplo n.º 6
0
/*======== void parse_file () ==========
Inputs:   char * filename 
          struct matrix * transform, 
          struct matrix * pm,
          screen s
Returns: 

Goes through the file named filename and performs all of the actions listed in that file.
The file follows the following format:
     Every command is a single character that takes up a line
     Any command that requires arguments must have those arguments in the second line.
     The commands are as follows:
         l: add a line to the edge matrix - 
	    takes 6 arguemnts (x0, y0, z0, x1, y1, z1)
	 c: add a circle to the edge matrix - 
	    takes 3 arguments (cx, cy, r)
	 h: add a hermite curve to the edge matrix -
	    takes 8 arguments (x0, y0, x1, y1, x2, y2, x3, y3)
	 b: add a bezier curve to the edge matrix -
	    takes 8 arguments (x0, y0, x1, y1, x2, y2, x3, y3)
	 i: set the transform matrix to the identity matrix - 
	 s: create a scale matrix, 
	    then multiply the transform matrix by the scale matrix - 
	    takes 3 arguments (sx, sy, sz)
	 t: create a translation matrix, 
	    then multiply the transform matrix by the translation matrix - 
	    takes 3 arguments (tx, ty, tz)
	 x: create an x-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 y: create an y-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 z: create an z-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 a: apply the current transformation matrix to the 
	    edge matrix
	 v: draw the lines of the edge matrix to the screen
	    display the screen
	 g: draw the lines of the edge matrix to the screen
	    save the screen to a file -
	    takes 1 argument (file name)
	 q: end parsing

See the file script for an example of the file format


IMPORTANT MATH NOTE:
the trig functions int math.h use radian mesure, but us normal
humans use degrees, so the file will contain degrees for rotations,
be sure to conver those degrees to radians (M_PI is the constant
for PI)

jdyrlandweaver
====================*/
void parse_file ( char * filename, 
                  struct matrix * transform, 
                  struct matrix * pm,
                  screen s, color c) {

  FILE * fp = fopen(filename, "r");

  char * lines = (char *)malloc(1);
  float x0, y0, z0, x1, y1, z1, x2, y2, x3, y3;
  float step;
  float cx, cy, r;
  float x, y, z;
  float theta;
	
  while(fscanf(fp, "%c", lines)) {
    printf("lines gets: %c \n", *lines); 
    switch (*lines){
    case 'c':
      {
	fscanf(fp, "%f %f %f %f", &cx, &cy, &r, &step);
	add_circle(pm, cx, cy, r, step);
	break;
      }
    case 'b':
      {
	fscanf(fp, "%f %f %f %f %f %f %f %f %f", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3, &step);
	add_curve(pm, x0, y0, x1, y1, x2, y2, x3, y3, step, 0);
	break;
      }
    case 'h':
      {
	fscanf(fp, "%f %f %f %f %f %f %f %f %f", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3, &step);
	add_curve(pm, x0, y0, x1, y1, x2, y2, x3, y3, step, 1);
	break;
      }
    case 'l':
      {
	fscanf(fp, "%f %f %f %f %f %f", &x0, &y0, &z0, &x1, &y1, &z1);
	add_edge(pm, x0, y0, z0, x1, y1, z1);
	break;
      }
    case 'i':
      {
	ident(transform);
	break;
      }
    case 's':
      {
	fscanf(fp, "%f %f %f", &x, &y, &z);
	struct matrix * scale = make_scale(x, y, z);
	matrix_mult(scale, transform);
	free(scale);
	break;
      }
    case 't':
      {
	fscanf(fp, "%f %f %f", &x, &y, &z);
	struct matrix * trans = make_translate(x, y, z);
	matrix_mult(trans, transform);
	free(trans);
	break;
      }
    case 'x':
      {
	fscanf(fp, "%f", &theta);
	struct matrix * transx = make_rotX(theta);
	matrix_mult(transx, transform);
	free(transx);
	break;
      }
    case 'y':
      {
	fscanf(fp, "%f", &theta);
	struct matrix * transy = make_rotY(theta);
	matrix_mult(transy, transform);
	free(transy);
	break;
      }
    case 'z':
      {
	fscanf(fp, "%f", &theta);
	struct matrix * transz = make_rotZ(theta);
	matrix_mult(transz, transform);
	free(transz);
	break;
      }
    case 'a':
      {
	matrix_mult(transform, pm);
	break;
      }
    case 'v':
      {
	clear_screen(s);
	draw_lines(pm, s, c);
	display(s);
	break;
      }
    case 'g':
      {
	char * file = (char *)malloc(256);
	fscanf(fp, "%s", file);
	clear_screen(s);
	draw_lines(pm, s, c);
	save_extension(s, file);
	free(file);
	break;
      }
    case 'q':
      {
	exit(0);
      }
    default:
      {
	exit(1);
      }
    }
    fscanf(fp, "%c", lines);
  }
  
  fclose(fp);
  free(lines);
  
}
Exemplo n.º 7
0
Arquivo: q6.c Projeto: eokeeffe/C-code
void end_all()//end the program cycle
{
	clear_screen();
	printf("Thank you for using my database V1.0\r\n");
	exit(0);
}
Exemplo n.º 8
0
/**
 * @brief  
 * @param  None
 * @retval None
 */
void clr_scr_rst_cur(void)
{
  clear_screen();
  reset_cursor();
}
Exemplo n.º 9
0
void display_loop(){
//	mcuf_serial_mode();

	mode = setjmp(newmode_jmpbuf);

#ifdef JOYSTICK_SUPPORT
	// in case we get here via mode jump, we (re)enable joystick queries
	waitForFire = 1;
#endif

	oldOldmode = oldMode;

#ifdef JOYSTICK_SUPPORT
	waitForFire = 1;
#endif

	for(;;){
#ifndef MENU_SUPPORT
		clear_screen(0);
#endif
		oldMode = mode;

		switch(mode++) {

#ifdef ANIMATION_SCROLLTEXT
		case 1:
			scrolltext(scrolltext_text);

	#ifdef RANDOM_SUPPORT
			{
				char a[28];
				sprintf(a,"</# counter == %lu  ",
					(unsigned long)percnt_get(&g_reset_counter, &g_reset_counter_idx));
				scrolltext(a);
			}
	#endif
#endif
#ifdef ANIMATION_TIME
#ifndef ANIMATION_SCROLLTEXT
		case 1:
#endif
			time_anim();
			break;
#else
#ifdef ANIMATION_SCROLLTEXT
			break;
#endif
#endif

#ifdef ANIMATION_SPIRAL
#		ifndef SPIRAL_DELAY
#			define SPIRAL_DELAY 5
#		endif

		case 2:
			spiral(SPIRAL_DELAY);
			break;
#endif

#ifdef ANIMATION_JOERN1
		case 3:
			joern1();
			break;
#endif

#ifdef ANIMATION_SNAKE
		case 4:
			snake_animation();
			break;
#endif

#ifdef ANIMATION_CHECKERBOARD
		case 5:
			checkerboard(20);
			break;
#endif

#ifdef ANIMATION_FIRE
		case 6:
			fire();
			break;
#endif

#ifdef ANIMATION_TIME
		case 7:
			time_anim();
			break;
#endif

#ifdef ANIMATION_MATRIX
		case 8:
			matrix();
			break;
#endif

#ifdef ANIMATION_RANDOM_BRIGHT
		case 9:
			random_bright(30);
			break;
#endif

#ifdef ANIMATION_STONEFLY
		case 10:
			stonefly();
			break;
#endif

#ifdef ANIMATION_GAMEOFLIFE
		case 11:
			gameoflife();
			break;
#endif

#ifdef ANIMATION_FLYINGDOTS
		case 12:
			flyingdots();
			break;
#endif

#ifdef ANIMATION_BREAKOUT
		case 13:
			breakout_demo();
			break;
#endif

#ifdef ANIMATION_MHERWEG
		case 14:
			mherweg();
			break;
#endif

#ifdef ANIMATION_MOIRE
		case 15:
			moire();
			break;
#endif

#ifdef ANIMATION_TIME
		case 16:
			time_anim();
			break;
#endif

#ifdef ANIMATION_LTN_ANT
		case 17:
			ltn_ant();
			break;
#endif

#ifdef ANIMATION_LABORLOGO
		case 18:
			laborlogo();
			break;
#endif

#ifdef ANIMATION_AMPHIBIAN
		case 19:
			amphibian();
			break;
#endif

#ifdef ANIMATION_LOGO_OOS
		case 20:
			logo_OutOfSpec();
			break;
#endif

#ifdef ANIMATION_FAIRYDUST
		case 21:
			fairydust();
			break;
#endif

#ifdef ANIMATION_PLASMA
		case 22:
			plasma();
			break;
#endif

#ifdef ANIMATION_PSYCHEDELIC
		case 23:
			psychedelic();
			break;
#endif

#ifdef ANIMATION_BLACKHOLE
		case 24:
			blackhole();
			break;
#endif

#ifdef ANIMATION_SQUARES
		case 25:
			squares();
			break;
#endif

#ifdef ANIMATION_DNA
		case 26:
			dna();
			break;
#endif

#ifdef ANIMATION_TESTS
		case 31:
			test_level(1, false);
			break;

		case 32:
			test_level(2, false);
			break;

		case 33:
			test_level(3, false);
			break;

		case 35:
			test_palette(false);
			test_palette2(false);
			break;
#endif

#ifdef SMALLANIMATION_ROWWALK
		case 36:
		  rowwalk(SMALLANIMATION_ROWWALK_COUNT,SMALLANIMATION_ROWWALK_SPEED);
		  break;
#endif

#ifdef SMALLANIMATION_COLWALK
		case 37:
		  colwalk(SMALLANIMATION_COLWALK_COUNT,SMALLANIMATION_COLWALK_SPEED);
		  break;
#endif
#ifdef SMALLANIMATION_COLBOUNCE
		case 38:
		  colbounce(SMALLANIMATION_COLBOUNCE_COUNT,SMALLANIMATION_COLBOUNCE_SPEED);
		  break;
#endif
#ifdef SMALLANIMATION_ROWBOUNCE
		case 39:
		  rowbounce(SMALLANIMATION_ROWBOUNCE_COUNT,SMALLANIMATION_ROWBOUNCE_SPEED);
		  break;
#endif

#ifdef MENU_SUPPORT
		case 0xFDu:
			mode = 1;
			break;

		case 0xFEu:
			menu();
			mode = oldOldmode;
			break;
#else

		case 0xFDu:
#ifdef JOYSTICK_SUPPORT
			if (JOYISFIRE)
				mode = 0xFEu;
			else
#endif
				mode = 1;
			break;

		case 0xFEu:
#ifdef JOYSTICK_SUPPORT
			waitForFire = 0;   // avoid circular jumps
			while (JOYISFIRE); // wait until user released the fire button
#endif
			wait(25);          // wait for button to settle

#  ifdef GAME_TETRIS
			tetris();
#  endif

#  ifdef GAME_BASTET
			tetris_bastet();
#  endif

#  ifdef GAME_TETRIS_FP
			tetris_fp();
#  endif

#  ifdef GAME_SPACE_INVADERS
			borg_invaders();
#  endif

#  ifdef GAME_SNAKE
			snake_game();
#  endif

#  ifdef GAME_BREAKOUT
			borg_breakout(0);
#  endif

#ifdef JOYSTICK_SUPPORT
			while (JOYISFIRE); // avoid an unwanted restart of the game loop
#endif
			wait(25);          // wait for button to settle
			mode = oldOldmode; // restore old animation mode
#ifdef JOYSTICK_SUPPORT
			waitForFire = 1;   // reenable joystick query of the wait() function
#endif
			break;
#endif

#ifdef ANIMATION_OFF
		case 0xFFu:
			off();
			break;
#endif
		default:
			if (reverseMode) {
				if (reverseMode-- == (mode - 1)) {
					mode -= 2;
				} else {
					reverseMode = 0;
				}
			}
			break;
		}
	}
}
Exemplo n.º 10
0
static void on_clear (GtkMenuItem *menuitem,
		      gpointer     user_data)
{
  GromitData *data = (GromitData *) user_data;
  clear_screen(data);
}
Exemplo n.º 11
0
/*======== void parse_file () ==========
Inputs:   char * filename 
          struct matrix * transform, 
          struct matrix * pm,
          screen s
Returns: 

Goes through the file named filename and performs all of the actions listed in that file.
The file follows the following format:
     Every command is a single character that takes up a line
     Any command that requires arguments must have those arguments in the second line.
     The commands are as follows:
         l: add a line to the edge matrix - 
	    takes 6 arguemnts (x0, y0, z0, x1, y1, z1)
         b: add a hermite cutve to the edge matrix - 
	    takes 8 arguemnts (x0, y0, x1, y1, x2, y2, x3, y3)
         h: add a bezier to the edge matrix - 
	    takes 8 arguemnts (x0, y0, x1, y1, x2, y2, x3, y3)
         c: add a circle to the edge matrix - 
	    takes 3 arguemnts (cx, cy, r)
         m: add a sphere to the edge matrix - 
	    takes 3 arguemnts (cx, cy, r)
         d: add a torus to the edge matrix - 
	    takes 4 arguemnts (cx, cy, r1, r2)
         p: add a rectangular prism to the edge matrix - 
	    takes 6 arguemnts (x, y, z, width, height, depth)
	 w: clear the currnt edge matrix -
	    takes 0 arguments
	 i: set the transform matrix to the identity matrix - 
	 s: create a scale matrix, 
	    then multiply the transform matrix by the scale matrix - 
	    takes 3 arguments (sx, sy, sz)
	 t: create a translation matrix, 
	    then multiply the transform matrix by the translation matrix - 
	    takes 3 arguments (tx, ty, tz)
	 x: create an x-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 y: create an y-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 z: create an z-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 a: apply the current transformation matrix to the 
	    edge matrix
	 v: draw the lines of the edge matrix to the screen
	    display the screen
	 g: draw the lines of the edge matrix to the screen
	    save the screen to a file -
	    takes 1 argument (file name)
	 q: end parsing

See the file script for an example of the file format


IMPORTANT MATH NOTE:
the trig functions int math.h use radian mesure, but us normal
humans use degrees, so the file will contain degrees for rotations,
be sure to conver those degrees to radians (M_PI is the constant
for PI)

03/08/12 16:22:10
jdyrlandweaver
====================*/
void parse_file ( char * filename, 
                  struct matrix * transform, 
                  struct matrix * pm,
                  screen s) {

  FILE *f;
  char line[256];
  struct matrix * tmp;
  double angle;
  color g;

  g.red = 0;
  g.green = 255;
  g.blue = 255;
  
  clear_screen(s);

  if ( strcmp(filename, "stdin") == 0 ) 
    f = stdin;
  else
    f = fopen(filename, "r");
  
  while ( fgets(line, 255, f) != NULL ) {
    line[strlen(line)-1]='\0';
    //printf(":%s:\n",line);
    char c;
    double x, y, z, x1, y1, z1, x2, y2, x3, y3, x4, y4;
   
    c = line[0];

    switch (c) {
    case 'l':
      //      printf("LINE!\n");
      fgets(line, 255, f);
      //      printf("\t%s", line);
      //line[strlen(line)-1]='\0';
      sscanf(line, "%lf %lf %lf %lf %lf %lf", &x, &y, &z, &x1, &y1, &z1);
      add_edge(pm, x, y, z, x1, y1, z1);
      // printf( "%lf %lf %lf %lf %lf %lf\n", x, y, z, x1, y1, z1);
      break;
    case 'p':
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf %lf %lf %lf", &x, &y, &z, &x1, &y1, &z1);
      add_box(pm, x, y, z, x1, y1, z1);
      // printf( "%lf %lf %lf %lf %lf %lf\n", x, y, z, x1, y1, z1);
      break;
    case 'm':
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf", &x, &y, &z);
      add_sphere(pm, x, y, z, 0.06);
      //printf( "%lf %lf %lf\n", x, y, z);
      break;
    case 'd':
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf %lf", &x, &y, &z, &z1);
      add_torus(pm, x, y, z, z1, 0.06);
      //printf( "%lf %lf %lf\n", x, y, z);
      break;
    case 'c':
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf", &x, &y, &z);
      add_circle(pm, x, y, z, 0.05);
      //printf( "%lf %lf %lf\n", x, y, z);
      break;
    case 'b':
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf %lf %lf %lf %lf %lf",
	     &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
      add_curve(pm, x1, y1, x2, y2, x3, y3, x4, y4, 0.01, BEZIER_MODE );
      //printf( "%lf %lf %lf\n", x, y, z);
      break;
    case 'h':
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf %lf %lf %lf %lf %lf",
	     &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
      add_curve(pm, x1, y1, x2, y2, x3, y3, x4, y4, 0.01, HERMITE_MODE );
      //printf( "%lf %lf %lf\n", x, y, z);
      break;
    case 's':
      //printf("SCALE\n");
      fgets(line, 255, f);
      //line[strlen(line)-1]='\0';      
      sscanf(line, "%lf %lf %lf", &x, &y, &z);
      tmp = make_scale(x, y, z);
      matrix_mult(tmp, transform);
      //print_matrix(transform);
      break;
    case 't':
      //printf("TRANSLATE\n");
      fgets(line, 255, f);
      //      line[strlen(line)-1]='\0';      
      sscanf(line, "%lf %lf %lf", &x, &y, &z);
      tmp = make_translate(x, y, z);
      matrix_mult(tmp, transform);
      //print_matrix(transform);
      break;
    case 'x':
      //printf("ROTATE!\n");
      fgets(line, 255, f);
      sscanf(line, "%lf", &angle);
      angle = angle * (M_PI / 180);
      tmp = make_rotX( angle);
      matrix_mult(tmp, transform);
      break;
    case 'y':
      //printf("ROTATE!\n");
      fgets(line, 255, f);
      sscanf(line, "%lf", &angle);
      angle = angle * (M_PI / 180);
      tmp = make_rotY( angle);
      matrix_mult(tmp, transform);
      break;
    case 'z':
      //printf("ROTATE!\n");
      fgets(line, 255, f);
      sscanf(line, "%lf", &angle);
      angle = angle * (M_PI / 180);
      tmp = make_rotZ( angle);
      matrix_mult(tmp, transform);
      break;
    case 'i':
      ident(transform);
      break;
    case 'a':
      //printf("APPLY!\n");
      //print_matrix( transform );
      //      print_matrix(pm);
      matrix_mult(transform, pm);
      break;
    case 'v':
      clear_screen(s);
      draw_polygons(pm, s, g);
      display(s);
      break;
    case 'w':
      pm->lastcol = 0;
      break;
    case 'g':
      fgets(line, 255, f);
      // line[strlen(line)-1] = '\0';
      clear_screen(s);
      draw_polygons(pm, s, g);
      save_extension(s, line);
      break;
    case 'q':
      return;
    case '#':
      break;
    default:
      printf("Invalid command\n");
      break;
    }
  }

  free_matrix(tmp);
  fclose(f);
  //printf("END PARSE\n");
}
Exemplo n.º 12
0
/* Efface la fenetre graphique */
void Effacer() {
	clear_screen(fenetreCourante);
}
Exemplo n.º 13
0
void ConsoleUI::add_scientist()
{
    Scientist s = Scientist();
    string firstname_, lastname_, gender_, birth_, death_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Name of Scientist: [FirstName LastName]" << endl;
    cout << endl << " -> ";
    cin >> firstname_ >> lastname_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Gender of scientist: \n(1) male \n(2) female" << endl;
    cout << endl << " -> ";
    cin >> gender_;
    while ((gender_ != "1") && (gender_ != "2"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Gender of scientist: \n(1) male \n(2) female" << endl;
        cout << endl << " -> ";
        cin >> gender_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Birth year of scientist:" << endl;
    cout << endl << " -> ";
    cin >> birth_;
    while (!is_digits(birth_))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Birth year of scientist:" << endl;
        cout << endl << " -> ";
        cin >> birth_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Scientist's Year of death: " << endl;
    cout << endl << " -> ";
    cin >> death_;
    while (!is_digits(death_) || (atoi(death_.c_str()) < atoi(birth_.c_str())))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        if (!is_digits(death_))
        {
            cout << "Invalid input! Please try again:" << endl;
        }
        else if (atoi(death_.c_str()) < atoi(birth_.c_str()))
        {
            cout << "Year of death should be AFTER year of birth! Please ry again:" << endl;
        }
        cout << "Scientist's Year of death:" << endl;
        cout << endl << " -> ";
        cin >> death_;
    }
    if (gender_ == "1")
    {
        s.set_gender("Male");
    }
    else if (gender_ == "2")
    {
        s.set_gender("Female");
    }
    fix_string(firstname_);
    fix_string(lastname_);
    s.set_firstname(firstname_);
    s.set_lastname(lastname_);
    s.set_birth(birth_);
    s.set_death(death_);
    dbService.addS(s);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "Scientist has been added to the list!\n\n\n\n\n\n\n" << endl;
}
Exemplo n.º 14
0
void cTtyStatus::Recording(const cDevice *Device, const char *Name)
{
    const char *FileName = NULL;
    bool On = (Name != NULL);
#else
void cTtyStatus::Recording(const cDevice *Device,
                           const char *Name, const char *FileName, bool On, int ChannelNumber)
{
#endif
    const char *startStop = On ? "start" : "stop";
    const char *s = Name;

    if (!s)
        s = FileName;
    if (!s)
        s = "...";

    set_pos(24, 0);
    set_color(BLACK_GREEN);
    print("  Card %d: %s recording '%s'%-60s",
          Device->CardIndex()+1, startStop, s, "");
    refresh();
    set_pos(2, 0);
}


#if VDRVERSNUM <= 10337
void cTtyStatus::Replaying(const cControl *Control, const char *Name)
{
    const char *FileName = NULL;
    bool On = (Name != NULL);
#else
void cTtyStatus::Replaying(const cControl *Control,
                           const char *Name, const char *FileName, bool On)
{
#endif
    const char *startStop = On ? "Start" : "Stop";
    const char *s = Name;

    if (!s)
        s = FileName;
    if (!s)
        s = "...";

    set_pos(24, 0);
    set_color(BLACK_GREEN);
    print("  %s replay '%s'%-70s", startStop, s, "");
    refresh();
    set_pos(2, 0);
}


void cTtyStatus::SetVolume(int Volume, bool Absolute)
{
    static int lastVolume;

    // dsyslog("%s: vol %d abs %d", __FUNCTION__, Volume, Absolute);

    set_pos(24, 0);
    set_color(BLACK_GREEN);
#if APIVERSNUM < 10402
    Absolute = true;
#endif
    if (Absolute)
        lastVolume = Volume;
    else
        lastVolume += Volume;
    print("     Set volume %d %-70s", lastVolume, "");
    refresh();
    set_pos(2, 0);
}


void cTtyStatus::OsdClear(void)
{
    clear_screen();
    refresh();
}


void cTtyStatus::OsdTitle(const char *Title)
{
    // dsyslog("%s: '%s'", __FUNCTION__, Title);

    clear_screen();
    set_color(BLACK_CYAN);
    set_pos(0, 0);
    print("     %-80s", Title);
    set_color(WHITE_BLACK);
    refresh();
    set_pos(2, 0);
}
Exemplo n.º 15
0
static int clear ()
{
	return clear_screen ();
}
Exemplo n.º 16
0
/**
 * \brief Example application entry routine
 */
int main(void)
{
	/* The sensor_platform_init() function will initialize the system
	 * clock and sensor bus support in addition to configuring the
	 * XMEGA-A3BU and Sensor Xplained boards.
	 *
	 * Use gfx_mono_init() to initialize the monochrome graphical system
	 * API then write a splash screen after enabling the LCD display
	 * backlight and setting the contrast.
	 *
	 * The MCU is going to be put in a sleep mode, so initialize the
	 * sleep manager API with a call to the sleepmgr_init() routine.
	 */
	sensor_platform_init();
	gfx_mono_init();
	sleepmgr_init();

	gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
	st7565r_set_contrast(ST7565R_DISPLAY_CONTRAST_MIN);

	/* Attach an accelerometer on a Sensors Xplained board. */
	sensor_t accelerometer;
	sensor_attach(&accelerometer, SENSOR_TYPE_ACCELEROMETER, 0, 0);

	/* Enable the accelerometer low-g (free fall) event. */
	sensor_enable_event(&accelerometer, SENSOR_EVENT_LOW_G);

	/* Set the free fall threshold (low-g event), bandwidth and range. */
	sensor_set_threshold(&accelerometer, SENSOR_THRESHOLD_LOW_G,
			LOW_G_THRESHOLD);
	sensor_set_bandwidth(&accelerometer, BANDWIDTH);
	sensor_set_range(&accelerometer, RANGE);

	while (true) {
		/* Put the accelerometer into a low-power mode (if available). */
		sensor_set_state(&accelerometer, SENSOR_STATE_LOW_POWER);

		LED_Off(ACCEL_LED);

		clear_screen();

		/* Display the "armed" message and put the MCU in sleep mode. */
		gfx_mono_draw_string("ATMEL Drop Demo\r\nXMEGA Powered Down\r\n"
				"g Sensor Armed", 1, 5, &sysfont);

		sleepmgr_lock_mode(SLEEP_MODE);
		sleepmgr_enter_sleep();

		/* The following runs after the MCU has been woken by an
		 * external low-g interrupt from the accelerometer.
		 *
		 * Turn on the red LED while falling and put the accelerometer
		 * into a high-power mode (if available) to sample date points.
		 */
		LED_On(ACCEL_LED);

		sensor_set_state(&accelerometer, SENSOR_STATE_HIGHEST_POWER);

		static scalar_t acceleration_waveform[DATA_SAMPLE_COUNT];
		scalar_t acceleration_max = 0;

		for (int data_count = 0; data_count < DATA_SAMPLE_COUNT;
				++data_count) {
			acceleration_waveform[data_count] = 0;

			for (int i = 0; i < SAMPLE_AVG_COUNT; ++i) {
				/* Calculate the gravity vector magnitude. */
				vector3_t gvec;
				sensor_get_vector(&accelerometer, &gvec);

				scalar_t const acceleration_magnitude
					= vector3_magnitude(&gvec);

				/* Store the maximum g magnitude for this
				 * sub-group. */
				if (acceleration_magnitude >
						acceleration_waveform[data_count]) {
					acceleration_waveform[data_count]
						= acceleration_magnitude;
				}

				/* Store the maximum g magnitude for the whole
				 * data set. */
				if (acceleration_magnitude > acceleration_max) {
					acceleration_max = acceleration_magnitude;
				}
			}
		}

		clear_screen();

		/* Turn the max acceleration into a string and convert to g. */
		static char max_g_string[20];

		if (acceleration_max > LOW_G_SATURATION) {
			sprintf(max_g_string, "g Sensor Saturated");
		} else {
			sprintf(max_g_string, "Peak = %02.2f g",
					acceleration_max / 1000);
		}

		/* Print the max g on the monochrome display. */
		gfx_mono_draw_string("Drop Detected", 1, 5, &sysfont);
		gfx_mono_draw_string(max_g_string, 1, 13, &sysfont);
		gfx_mono_draw_string("Press SW1 for chart", 1, 21, &sysfont);

		do {
			LED_Toggle(ACCEL_LED);
			delay_ms(100);
		} while (!switch_pressed(SW1));

		/* Plot the collected data points to create the waveform chart. */
		clear_screen();
		screen_border();

		for (int data_count = 0; data_count < DATA_SAMPLE_COUNT; ++data_count) {
			gfx_mono_draw_filled_circle(data_count,
					32 -
					(acceleration_waveform[data_count] / 500), 1,
					GFX_PIXEL_SET, GFX_WHOLE);
		}

		do {
			LED_Toggle(PROMPT_LED);
			delay_ms(100);
		} while (!switch_pressed(SW1));

		LED_Off(PROMPT_LED);
	}
}
Exemplo n.º 17
0
int main(int argc, char** argv)
{
	color_t pikachu[24][28] = {	
		{BLA, BLA, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, BLA, BLA},
		{BLA, BLA, BLA, BLA, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, BLA, BLA, BLA, BLA},
		{BLA, BLA, BLA, YEL, BLA, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, BLA, YEL, BLA, BLA, BLA},
		{BLA, BLA, BLA, YEL, YEL, BLA, BLA, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, BLA, BLA, YEL, YEL, BLA, BLA, BLA},
		{WHI, BLA, BLA, YEL, YEL, YEL, YEL, BLA, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, BLA, YEL, YEL, YEL, YEL, BLA, BLA, WHI},
		{WHI, BLA, BLA, YEL, YEL, YEL, YEL, YEL, BLA, BLA, WHI, WHI, BLA, BLA, BLA, BLA, WHI, WHI, BLA, BLA, YEL, YEL, YEL, YEL, YEL, BLA, BLA, WHI},
		{WHI, WHI, BLA, YEL, YEL, YEL, YEL, YEL, YEL, YEL, BLA, BLA, YEL, YEL, YEL, YEL, BLA, BLA, YEL, YEL, YEL, YEL, YEL, YEL, YEL, BLA, WHI, WHI},
		{WHI, WHI, BLA, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, BLA, WHI, WHI},
		{WHI, WHI, WHI, BLA, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, BLA, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, BLA, YEL, BLA, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, BLA, YEL, BLA, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, WHI, BLA, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, BLA, WHI, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, WHI, BLA, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, BLA, WHI, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, BLA, YEL, YEL, YEL, BLA, BLA, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, BLA, BLA, YEL, YEL, YEL, BLA, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, BLA, YEL, YEL, BLA, WHI, BLA, BLA, YEL, YEL, YEL, YEL, YEL, YEL, BLA, BLA, WHI, BLA, YEL, YEL, BLA, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, BLA, YEL, YEL, BLA, BLA, BLA, BLA, YEL, YEL, YEL, YEL, YEL, YEL, BLA, BLA, BLA, BLA, YEL, YEL, BLA, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, BLA, YEL, YEL, YEL, BLA, BLA, YEL, YEL, YEL, BLA, BLA, YEL, YEL, YEL, BLA, BLA, YEL, YEL, YEL, BLA, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, BLA, YEL, YEL, RED, RED, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, YEL, RED, RED, YEL, YEL, BLA, WHI, WHI, WHI},
		{WHI, WHI, WHI, BLA, YEL, RED, RED, RED, RED, YEL, YEL, BLA, YEL, BLA, BLA, YEL, BLA, YEL, YEL, RED, RED, RED, RED, YEL, BLA, WHI, WHI, WHI},
		{WHI, WHI, WHI, BLA, YEL, RED, RED, RED, RED, YEL, YEL, YEL, BLA, BLA, BLA, BLA, YEL, YEL, YEL, RED, RED, RED, RED, YEL, BLA, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, BLA, YEL, RED, RED, YEL, YEL, YEL, YEL, BLA, RED, RED, BLA, YEL, YEL, YEL, YEL, RED, RED, YEL, BLA, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, WHI, BLA, YEL, YEL, YEL, YEL, YEL, YEL, BLA, RED, RED, BLA, YEL, YEL, YEL, YEL, YEL, YEL, BLA, WHI, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, WHI, WHI, BLA, BLA, YEL, YEL, YEL, YEL, YEL, BLA, BLA, YEL, YEL, YEL, YEL, YEL, BLA, BLA, WHI, WHI, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, BLA, BLA, BLA, YEL, YEL, YEL, YEL, YEL, YEL, BLA, BLA, BLA, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI},
		{WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, BLA, BLA, BLA, BLA, BLA, BLA, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI, WHI}
	};
	char key;
	char *dance = "Let's dance!!";
	char *exit = "n => EXIT";
	int swip = 0;
	int pika = 0;

	init_graphics();


	sleep_ms(20);

	char* s = "Hello PIKACHU!!!";
	draw_text(50, 30, s, YEL);
	clear_screen();	
	int i, j;
/*
	for (i = 0; i < 24; i++)
	{
		for (j = 0; j < 28; j++)
		{
			draw_rect((50+j*8), (50+i*8), 8, 8, pikachu[i][j]);
			fill_circle((350+j*8), (50+i*8), 4, pikachu[i][j]);
		}
	}
*/
	sleep_ms(200000000);
	char* start = "Want to see pikachu dance? (y => YES; n => EXIT)";
	draw_text(50, 30, s, BLA);
	draw_text(50, 30, start, YEL);
	
	for (i = 0; i < 24; i++)
			{
				for (j = 0; j < 28; j++)
				{
					draw_rect((50+j*8), (50+i*8), 8, 8, pikachu[i][j]);
					fill_circle((350+j*8), (50+i*8), 4, pikachu[i][j]);
				}
			}
	
	do
	{

		key = getkey();
		if(key == 'y')
			pika = 1;
		if(key == 'n')
			pika = 0;

		if (pika == 1)
		{
			clear_screen();
			fill_rect(50, 30, 400, 16, BLA);
			fill_rect(40, 30, 600, 400, BLA);

			if (swip == 0)
			{
				for (i = 0; i < 24; i++)
				{
					for (j = 0; j < 28; j++)
					{
						fill_circle((350+j*8), (50+i*8), 8, pikachu[i][j]);
					}
				}
				swip = 1;
			}
			else
			{
				for (i = 23; i >= 0; i--)
				{
					for (j = 27; j >= 0; j--)
					{
						fill_circle((50+j*8), (50+i*8), 8, pikachu[i][j]);
					}
				}
				swip = 0;
			}
			sleep_ms(900000000000000);

			draw_text(50, 350, exit, YEL);
		}


	} while(key != 'n');

/*
	int i, j;
	for (i = 0; i < 24; i++)
	{
		for (j = 0; j < 28; j++)
		{
			draw_rect((50+j*8), (50+i*8), 8, 8, pikachu[i][j]);
			fill_circle((350+j*8), (50+i*8), 4, pikachu[i][j]);
		}
	}
*/

	char *gb = "Goodbye!! PIKAPIKACHU!!";
//	draw_text(50, 30, start, BLA);
//	draw_text(50, 30, dance, BLA);
	draw_text(50, 350, exit, BLA);
//	fill_rect(50, 30, 400, 16, BLA);
	fill_rect(50, 30, 400, 16, BLA);
	fill_rect(30, 20, 600, 400, BLA);
	draw_text(50, 30, gb, YEL);
	exit_graphics();	

	return 0;
}
Exemplo n.º 18
0
Arquivo: inky.c Projeto: jucimarjr/pca
int main (int argc, char *argv[])
{
  int ghost[3],pacman[3], red[3], target[2], number_ghost;
  char maze[L][C];
  char ch;
  int i=0,j=0;
  FILE *fp;
  fp = fopen("maze.txt","r" );
  if(fp == NULL)
	printf("Erro, nao foi possivel abrir o arquivo\n");
  else
	while( (ch=fgetc(fp))!= EOF )
	{
		if (ch != '\n')
		{
			maze[i][j] = ch;
			j++;
		}else
		{
			j = 0;
			i++;
		}
	}		
  fclose(fp);
	
  clear_screen();
  print_maze(maze);
 
  printf ( "\t>>> GHOSTS <<<\n" );
  printf ( "1.BLINK  2.PINK  3.INKY  4.CLYDE\n" );
  do
  {  	  
  	  printf ( "Qual o numero do Ghost? = " );
          scanf ("%d", &number_ghost);
  }while(number_ghost > 4 || number_ghost < 1 );  
  //number_ghost = 2;
  do
  {
  	print_maze(maze);
	printf ( "Qual a posição do GHOST? (x,y)\n" );
  	printf ( "x: " );
  	scanf ( "%d", &ghost[1] ); // referente a coluna - ghost
  	printf ( "y: " );
  	scanf ( "%d", &ghost[0] ); // referente a linha - ghost
	printf ( "Direção do ghost = 1-Down , 2-Right, 3-Up, 4-Left = " );
        scanf ("%d", &ghost[2]);
	clear_screen();
  }while (!validate_position(maze,ghost[0],ghost[1]) || ghost[2] > 4 ||ghost[2] < 1);                                           //mudar os parametros
	position (maze,ghost,'3');
    
    
   do
  {
  	print_maze(maze);
	printf ( "Qual a posição do RED? (x,y)\n" );
  	printf ( "x: " );
  	scanf ( "%d", &red[1] ); // referente a coluna - ghost
  	printf ( "y: " );
  	scanf ( "%d", &red[0] ); // referente a linha - ghost
	printf ( "Direção do red = 1-Down , 2-Right, 3-Up, 4-Left = " );
        scanf ("%d", &red[2]);
	clear_screen();
  }while (!validate_position(maze,red[0],red[1]) || red[2] > 4 ||red[2] < 1);                                           //mudar os parametros
	position (maze,red,'4');
    
    
  do 
  {
	clear_screen();
  	print_maze (maze);
  	printf ( "Qual a posição do Pacman? (x,y)\n" );
  	printf ( "x: " );
  	scanf ( "%d", &pacman[1]); // referente a coluna - ghost
  	printf ( "y: " );
  	scanf ( "%d", &pacman[0]); // referente a linha - ghost
  }while (!validate_position(maze,pacman[0],pacman[1]));                          //mudar os parametros
  
  do
  {  	
        printf ( "Direção do Pac-mam: 1-Down , 2-Right, 3-Up, 4-Left =  " );
        scanf ("%d",&pacman[2]);
  }while( pacman[2]>4 ||pacman[2]<1);
  position (maze,pacman,'5' );//mudar os parametros
  
  dist(pacman);
  //marca_target aqui// calcular o target aqui e passa-lo para a walking
  //target[0]=(pacman[0]-red[0])+pacman[0];
  //target[1]=(pacman[1]-red[1])+pacman[1];
  //verifica_target(maze, target);
  calcula_target(maze, red, pacman, target);
  position(maze, target, '8');
  print_maze (maze);
  walking(maze,ghost,target);//mudar os parametros
  print_maze (maze);
  
  return 0;
}
Exemplo n.º 19
0
Arquivo: q6.c Projeto: eokeeffe/C-code
int main()
{
	clear_screen();
	options();
	return 0;
}
Exemplo n.º 20
0
void delay_test(void)
{
    unsigned char s1[4];
    unsigned char delay,c1,i;

    while(1)
    {
        clear_screen();
        printf("Test zur uC-spezifischen Delay-Festlegung\n");
        printf("=========================================\n\n");
        printf("VOR dem Test den DS18S20 abklemmen !\n\n");
        printf("Es gibt nun zwei Moeglichkeiten, die notwendigen Zeitverzoegerungen\n");
        printf("zu erzeugen:\n\n");
        printf("  1. Mit einer reinen for-Schleife direkt im Programm-Code.\n");
        printf("  2. Durch Aufruf einer Funktion, die eine for-Schleife enthaelt.\n\n");
        printf("Die Methode 1 wird zur Erzeugung sehr kleiner Zeitverzoegerungen (< 20 us),\n");
        printf("die Methode 2 fuer groessere Verzoegerungen verwendet.\n\n");
        printf("Auswahl, was getestet werden soll (1, 2 oder 'e' (Ende)):  ");

        c1 = getchar();

        if ((c1 != '1') && (c1 != '2')) break;           // Rücksprung

        if (c1 == '1')              // Test für Methode 1
        {
            while(1)
            {
                clear_screen();
                printf("Test Methode 1: Zeitverzoegerung d. reine for-Schleife direkt im Progamm-Code\n");
                printf("=============================================================================\n");
                printf("(Ruecksprung durch Reset ... )\n\n");

                printf("\n\nTest laeuft ... ");
    
                while(1)
                {
                    DQ = 0;
                    for(i=0; i<8; i++);         // for-Schleife zur Zeitverzögerung:
                                                // Wert muss direkt eingetragen werden,
                                                // keine Variable verwenden: würde dadurch
                                                // langsamer !!!!
                    DQ = 1;
                    _wait_ms(10);
                }
            }
        }

        else                        // Test für Methode 2
        {
            while(1)
            {
                clear_screen();
                printf("Test Methode 2: Zeitverzoegerung durch Funktionsaufruf\n");
                printf("======================================================\n");
                printf("(Ruecksprung durch Eingabe von 255)\n\n");
                printf("Bitte Delay-Wert (Funktions-Uebergabe-Wert) eingeben (0 ... 254): ");
    
                inputse(s1,4);
                delay = atoi(s1);
    
                if (delay == 255) break;            // Rücksprung
    
                printf("\n\nTest laeuft, weiter mit Taste ... ");
    
                while(1)
                {
                    DQ = 0;
                    ow_delay(delay);
                    DQ = 1;
                    if (seri_zeichen_da()) break;
                    _wait_ms(10);
                }
            }
        }
    }
}
Exemplo n.º 21
0
/*======== void parse_file () ==========
Inputs:   char * filename 
          struct matrix * transform, 
          struct matrix * pm,
          screen s
Returns: 

Goes through the file named filename and performs all of the actions listed in that file.
The file follows the following format:
     Every command is a single character that takes up a line
     Any command that requires arguments must have those arguments in the second line.
     The commands are as follows:
         line: add a line to the edge matrix - 
	    takes 6 arguemnts (x0, y0, z0, x1, y1, z1)
	 circle: add a circle to the edge matrix - 
	    takes 3 arguments (cx, cy, r)
	 hermite: add a hermite curve to the edge matrix -
	    takes 8 arguments (x0, y0, x1, y1, x2, y2, x3, y3)
	 bezier: add a bezier curve to the edge matrix -
	    takes 8 arguments (x0, y0, x1, y1, x2, y2, x3, y3)
         sphere: add a sphere to the edge matrix - 
	    takes 3 arguemnts (cx, cy, r)
         torus: add a torus to the edge matrix - 
	    takes 4 arguemnts (cx, cy, r1, r2)
         box: add a rectangular prism to the edge matrix - 
	    takes 6 arguemnts (x, y, z, width, height, depth)
	 clear: clear the currnt edge matrix -
	    takes 0 arguments
	 ident: set the transform matrix to the identity matrix - 
	 scale: create a scale matrix, 
	    then multiply the transform matrix by the scale matrix - 
	    takes 3 arguments (sx, sy, sz)
	 translate: create a translation matrix, 
	    then multiply the transform matrix by the translation matrix - 
	    takes 3 arguments (tx, ty, tz)
	 xrotate: create an x-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 yrotate: create an y-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 zrotate: create an z-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 apply: apply the current transformation matrix to the 
	    edge matrix
	 display: draw the lines of the edge matrix to the screen
	    display the screen
	 save: draw the lines of the edge matrix to the screen
	    save the screen to a file -
	    takes 1 argument (file name)
	 quit: end parsing

See the file script for an example of the file format


IMPORTANT MATH NOTE:
the trig functions int math.h use radian mesure, but us normal
humans use degrees, so the file will contain degrees for rotations,
be sure to conver those degrees to radians (M_PI is the constant
for PI)
====================*/
void parse_file ( char * filename, 
                  struct matrix * transform, 
                  struct matrix * pm,
                  screen s) {

  FILE *f;
  char line[256];
  struct matrix * tmp;
  double angle;
  color g;

  g.red = 0;
  g.green = 255;
  g.blue = 0;
  
  clear_screen(s);

  if ( strcmp(filename, "stdin") == 0 ) 
    f = stdin;
  else
    f = fopen(filename, "r");
  
  while ( fgets(line, 255, f) != NULL ) {
    line[strlen(line)-1]='\0';
    //printf(":%s:\n",line);
    double x, y, z, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4;
   
    
    if ( strncmp(line, "line", strlen(line)) == 0 ) {
      //      printf("LINE!\n");
      fgets(line, 255, f);
      //      printf("\t%s", line);
      //line[strlen(line)-1]='\0';
      sscanf(line, "%lf %lf %lf %lf %lf %lf", &x, &y, &z, &x1, &y1, &z1);
      add_edge(pm, x, y, z, x1, y1, z1);
      // printf( "%lf %lf %lf %lf %lf %lf\n", x, y, z, x1, y1, z1);
    }
    else if ( strncmp(line, "circle", strlen(line)) == 0 ) {
      //printf("CIRCLE\n");
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf", &x, &y, &z);
      add_circle(pm, x, y, z, 0.01);
      //printf( "%lf %lf %lf\n", x, y, z);
    }    
    else if ( strncmp(line, "bezier", strlen(line)) == 0 ) {
      //printf("BEZIER\n");
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf %lf %lf %lf %lf %lf",
	     &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
      add_curve(pm, x1, y1, x2, y2, x3, y3, x4, y4, 0.01, BEZIER_MODE );
      //printf( "%lf %lf %lf\n", x, y, z);
    }    
    else if ( strncmp(line, "hermite", strlen(line)) == 0 ) {
      //printf("HERMITE\n");
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf %lf %lf %lf %lf %lf",
	     &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
      add_curve(pm, x1, y1, x2, y2, x3, y3, x4, y4, 0.01, HERMITE_MODE );
      //printf( "%lf %lf %lf\n", x, y, z);
    }
    else if ( strncmp(line, "box", strlen(line)) == 0 ) {
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf %lf %lf %lf", &x, &y, &z, &x1, &y1, &z1);
      add_box(pm, x, y, z, x1, y1, z1);
      // printf( "%lf %lf %lf %lf %lf %lf\n", x, y, z, x1, y1, z1);
    }
    else if (strncmp(line, "sphere", strlen(line)) == 0 ) {
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf", &x, &y, &z);
      add_sphere(pm, x, y, z, 1);
      //printf( "%lf %lf %lf\n", x, y, z);
    }
    else if (strncmp(line, "torus", strlen(line)) == 0 ) {
      fgets(line, 255, f);
      sscanf(line, "%lf %lf %lf %lf", &x, &y, &z, &z1);
      add_torus(pm, x, y, z, z1, 1);
      //printf( "%lf %lf %lf\n", x, y, z);
    }
    else if ( strncmp(line, "scale", strlen(line)) == 0 ) {
      //printf("SCALE\n");
      fgets(line, 255, f);
      //line[strlen(line)-1]='\0';      
      sscanf(line, "%lf %lf %lf", &x, &y, &z);
      tmp = make_scale(x, y, z);
      matrix_mult(tmp, transform);
      //print_matrix(transform);
    }
    else if ( strncmp(line, "translate", strlen(line)) == 0 ) {
      //printf("TRANSLATE\n");
      fgets(line, 255, f);
      //      line[strlen(line)-1]='\0';      
      sscanf(line, "%lf %lf %lf", &x, &y, &z);
      tmp = make_translate(x, y, z);
      matrix_mult(tmp, transform);
      //print_matrix(transform);
    }
    else if ( strncmp(line, "xrotate", strlen(line)) == 0 ) {
      //printf("ROTATE!\n");
      fgets(line, 255, f);
      sscanf(line, "%lf", &angle);
      angle = angle * (M_PI / 180);
      tmp = make_rotX( angle);
      matrix_mult(tmp, transform);
    }
    else if ( strncmp(line, "yrotate", strlen(line)) == 0 ) {
      //printf("ROTATE!\n");
      fgets(line, 255, f);
      sscanf(line, "%lf", &angle);
      angle = angle * (M_PI / 180);
      tmp = make_rotY( angle);
      matrix_mult(tmp, transform);
    }
    else if ( strncmp(line, "zrotate", strlen(line)) == 0 ) {
      //printf("ROTATE!\n");
      fgets(line, 255, f);
      sscanf(line, "%lf", &angle);
      angle = angle * (M_PI / 180);
      tmp = make_rotZ( angle);
      matrix_mult(tmp, transform);
    }
    else if ( strncmp(line, "ident", strlen(line)) == 0 ) {
      ident(transform);
    }
    else if ( strncmp(line, "apply", strlen(line)) == 0 ) {
      //printf("APPLY!\n");
      //print_matrix( transform );
      //      print_matrix(pm);
      matrix_mult(transform, pm);
    }
    else if ( strncmp(line, "display", strlen(line)) == 0 ) {
      clear_screen(s);
      draw_polygons(pm, s, g);
      display(s);
    }
    else if ( strncmp(line, "save", strlen(line)) == 0 ) {
      fgets(line, 255, f);
      // line[strlen(line)-1] = '\0';
      clear_screen(s);
      draw_polygons(pm, s, g);
      save_extension(s, line);
    }
    else if ( strncmp(line, "clear", strlen(line)) == 0 ) {
      pm->lastcol = 0;
    }
    else if ( strncmp(line, "quit", strlen(line)) == 0 ) {
      return;
    }
    else if ( line[0] != '#' ) {
      printf("Invalid command\n");
    }
  }
  
  free_matrix(tmp);
  fclose(f);
  //printf("END PARSE\n");
}
Exemplo n.º 22
0
void bus_demo(void)
{
    unsigned char i,merker;
    float ftemp;

    clear_screen();
    printf("1-Wire-Bus-Demo fuer max. 5 DS18S20er-Slaves\n");
    printf("============================================\n\n");
    printf("Demo laeuft ...   (Abbruch durch Tastendruck)\n\n\n");

    printf("   Slave-Nr.     Temperatur         Scratch-Pad (Byte 8 .... Byte 0)");

    // Endlosschleife
    while(1)
    {
        merker = 0;

        // Slaves abfragen
        for (i=0; i<5; i++)
        {
            // Scratch Pad des DS1820 auslesen
            ds1820_rd_temp(i);              // i = Stellung des Slaves in Matrix ds1820_mat

            // Scratch Pad-Inhalt ausgeben
            set_cursor(2*i+8,36);
            printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x",ds1820[8],ds1820[7],ds1820[6],ds1820[5],ds1820[4],ds1820[3],ds1820[2],ds1820[1],ds1820[0]);

            // Prüfen, ob Stat.-Nr. ok
            if (ds1820[3] != i)       // Falsche Stat.-Nr. oder Slave def.
            {
                set_cursor(2*i+8,6); printf("%u          Keine kor. Antw.",i);
                merker = 2;
            }
            else merker = 0;
            
            // Ausgabe nur, wenn Slave-Ant. korrekt war
            if (merker == 0)
            {

                // Temperatur berechnen, als float-Wert
                if(ds1820[1] == 0)                // Positve Temp.-Werte
                {
                    ftemp = ds1820[0];
                    ftemp = ftemp/2;
                }
                else                            // Neg. Temp.-Werte
                {
                    ftemp = (~ds1820[0])+1;       // 2er-Komplement
                    ftemp = (ftemp*(-1))/2;
                }
    
                // Ausgabe: Slave-Nr. und Temp.
                set_cursor(2*i+8,6); printf("%u            %5.1f         ",i,ftemp);
            }

            // Abfrage auf Abbruch
            if (seri_zeichen_da()) 
            {
                merker = 1;
                break;
            }

            // Warten bis zur nächsten Messung
            _wait_ms(50);           

        }
        if (merker == 1) break;          // Aussprung
    }
}
Exemplo n.º 23
0
/*======== void my_main() ==========
  Inputs:   int polygons  
  Returns: 

  This is the main engine of the interpreter, it should
  handle most of the commadns in mdl.

  If frames is not present in the source (and therefore 
  num_frames is 1, then process_knobs should be called.

  If frames is present, the enitre op array must be
  applied frames time. At the end of each frame iteration
  save the current screen to a file named the
  provided basename plus a numeric string such that the
  files will be listed in order, then clear the screen and
  reset any other data structures that need it.

  Important note: you cannot just name your files in 
  regular sequence, like pic0, pic1, pic2, pic3... if that
  is done, then pic1, pic10, pic11... will come before pic2
  and so on. In order to keep things clear, add leading 0s
  to the numeric portion of the name. If you use sprintf, 
  you can use "%0xd" for this purpose. It will add at most
  x 0s in <F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3><F3>front of a number, if needed, so if used correctly,
  and x = 4, you would get numbers like 0001, 0002, 0011,
  0487

  05/17/12 09:41:35
  jdyrlandweaver
  ====================*/
void my_main( int polygons ) {

  struct vary_node ** knob_vals;
  int i, f, j, k;
  double step;
  double xval, yval, zval, knob_value;
  struct matrix *transform;
  struct matrix *tmp;
  struct stack *s;
  screen t;
  color g;
  char q;
	struct vary_node * temp_node;

  step = 0.05;
 
  g.red = 0;
  g.green = 255;
  g.blue = 255;

  s = new_stack();
  tmp = new_matrix(4, 1000);
  clear_screen( t );

	first_pass();
	if(num_frames == -1)
		exit(1);
	knob_vals= second_pass();
	
//	print_knobs();

	for(k = 0; k < num_frames; k++){

		//print_knobs();
	  //printf("%lu %lu\n", knob_vals, knob_vals[0]);
	  //printf("first node: %s %f\n", knob_vals[0]->name, knob_vals[1]->value);
	  
		for(temp_node = knob_vals[k]; temp_node; temp_node = temp_node->next){	 
			//print_knobs();	
			set_value(lookup_symbol(temp_node->name), temp_node -> value); 
		}

		for (i=0;i<lastop;i++) {
  
    	switch (op[i].opcode) {
	
    		case SPHERE:
      		add_sphere( tmp,op[i].op.sphere.d[0], //cx
		  		op[i].op.sphere.d[1],  //cy
					op[i].op.sphere.d[2],  //cz
					op[i].op.sphere.r,
					step);
					//apply the current top origin
					matrix_mult( s->data[ s->top ], tmp );
					draw_polygons( tmp, t, g );
					tmp->lastcol = 0;
					break;

				case TORUS:
					add_torus( tmp, op[i].op.torus.d[0], //cx
													op[i].op.torus.d[1],     //cy
													op[i].op.torus.d[2],    //cz
													op[i].op.torus.r0,
		 op[i].op.torus.r1,
		 step);
					matrix_mult( s->data[ s->top ], tmp );
					draw_polygons( tmp, t, g );
					tmp->lastcol = 0;
					break;

				case BOX:
					add_box( tmp, op[i].op.box.d0[0],
													op[i].op.box.d0[1],
													op[i].op.box.d0[2],
													op[i].op.box.d1[0],
													op[i].op.box.d1[1],
													op[i].op.box.d1[2]);
					matrix_mult( s->data[ s->top ], tmp );
					draw_polygons( tmp, t, g );
					tmp->lastcol = 0;
					break;

				case LINE:
					add_edge( tmp, op[i].op.line.p0[0],
													op[i].op.line.p0[1],
													op[i].op.line.p0[1],
													op[i].op.line.p1[0],
													op[i].op.line.p1[1],
													op[i].op.line.p1[1]);
					draw_lines( tmp, t, g );
					tmp->lastcol = 0;
					break;

				case MOVE:
					//get the factors

					knob_value = 1;

					if(op[i].op.move.p)
						knob_value = (double)op[i].op.move.p->s.value;					

					xval = op[i].op.move.d[0] * knob_value;
					yval = op[i].op.move.d[1] * knob_value;
					zval = op[i].op.move.d[2] * knob_value;

					transform = make_translate( xval , yval, zval );
					//multiply by the existing origin
					matrix_mult( s->data[ s->top ], transform );
					//put the new matrix on the top
					copy_matrix( transform, s->data[ s->top ] );
					free_matrix( transform );
					break;

				case SCALE:

					knob_value = 1;
					if(op[i].op.scale.p)
						knob_value = op[i].op.scale.p->s.value;

					xval = (op[i].op.scale.d[0]) * knob_value;
					yval = (op[i].op.scale.d[1]) * knob_value;
					zval = (op[i].op.scale.d[2]) * knob_value;

					transform = make_scale( xval, yval, zval );
					matrix_mult( s->data[ s->top ], transform );
					//put the new matrix on the top
					copy_matrix( transform, s->data[ s->top ] );
					free_matrix( transform );
					break;

				case ROTATE:

					knob_value = 1;
					if(op[i].op.rotate.p)
						knob_value = op[i].op.rotate.p->s.value;

					xval = (op[i].op.rotate.degrees * ( M_PI / 180 )) * knob_value;

					//get the axis
					if ( op[i].op.rotate.axis == 0 ) 
									transform = make_rotX( xval );
					else if ( op[i].op.rotate.axis == 1 ) 
									transform = make_rotY( xval );
					else if ( op[i].op.rotate.axis == 2 ) 
									transform = make_rotZ( xval );

					matrix_mult( s->data[ s->top ], transform );
					//put the new matrix on the top
					copy_matrix( transform, s->data[ s->top ] );
					free_matrix( transform );
					break;

				case PUSH:
					push( s );
					break;
				case POP:
					pop( s );
					break;
				case SAVE:
					save_extension( t, op[i].op.save.p->name );
					break;
				case DISPLAY:
					display( t );
					break;
			}
		}

		//strcpy(name, op[].op.basename.p->name);
    char value[256];
    char adder[256];
    //    strcpy(value, "pic");
    //    strcat(value, name);
    strcpy(value, name);
    sprintf(adder, "%04d", k);
    //k++;
    strcat(value, adder);
    strcat(value, ".png");
    save_extension(t, value);
      //}

    clear_screen(t);
    s = new_stack();

	}
	free_stack( s );
	free_matrix( tmp );
	//free_matrix( transform );    
}
Exemplo n.º 24
0
void w_env_select::select_item(dialog *parent)
{
  // Find available files
  vector<FileSpecifier> files;
  if (type == _typecode_theme) {
    // Theme, find by theme script
    FindThemes finder(files);
    vector<DirectorySpecifier>::const_iterator i = data_search_path.begin(),
                                               end = data_search_path.end();
    while (i != end) {
      FileSpecifier dir = *i + "Themes";
      finder.Find(dir, WILDCARD_TYPE);
      i++;
    }
  }
  else {
    // Map/phyics/shapes/sounds, find by type
    FindAllFiles finder(files);
    vector<DirectorySpecifier>::const_iterator i = data_search_path.begin(),
                                               end = data_search_path.end();
    while (i != end) {
      FileSpecifier dir = *i;
      finder.Find(dir, type);
      i++;
    }
  }

  // Create structured list of files
  vector<env_item> items;
  vector<FileSpecifier>::const_iterator i = files.begin(), end = files.end();
  string last_base;
  int indent_level = 0;
  for (i = files.begin(); i != end; i++) {
    string base, part;
    i->SplitPath(base, part);
    if (base != last_base) {
      // New directory
      FileSpecifier base_spec = base;
#ifdef __MACOS__
      char name[256];
      base_spec.GetName(name);
      if (name[0] != '\0') {
#endif
      // Subdirectory, insert name as unselectable item, put items on indentation level 1
      items.push_back(env_item(base_spec, 0, false));
      indent_level = 1;
#ifdef __MACOS__
    }
    else {
      // Top-level directory, put items on indentation level 0
      indent_level = 0;
    }
#endif
      last_base = base;
    }
    items.push_back(env_item(*i, indent_level, true));
  }

  // Create dialog
  dialog d;
  vertical_placer *placer = new vertical_placer;

  placer->dual_add(new w_title(menu_title), d);
  placer->add(new w_spacer(), true);
  w_env_list *list_w = new w_env_list(items, item.GetPath(), &d);
  placer->dual_add(list_w, d);
  placer->add(new w_spacer(), true);
  placer->dual_add(new w_button("CANCEL", dialog_cancel, &d), d);

  d.activate_widget(list_w);
  d.set_widget_placer(placer);

  // Clear screen
  clear_screen();

  // Run dialog
  if (d.run() == 0) {       // Accepted
    if (items.size()) {
      set_path(items[list_w->get_selection()].spec.GetPath());
    }

    if(mCallback) {
      mCallback(this);
    }
  }
}
Exemplo n.º 25
0
/*======== void parse_file () ==========
Inputs:   char * filename 
          struct matrix * transform, 
          struct matrix * pm,
          screen s
Returns: 

Goes through the file named filename and performs all of the actions listed in that file.
The file follows the following format:
     Every command is a single character that takes up a line
     Any command that requires arguments must have those arguments in the second line.
     The commands are as follows:
         line: add a line to the edge matrix - 
	    takes 6 arguemnts (x0, y0, z0, x1, y1, z1)
	 circle: add a circle to the edge matrix - 
	    takes 3 arguments (cx, cy, r)
	 hermite: add a hermite curve to the edge matrix -
	    takes 8 arguments (x0, y0, x1, y1, x2, y2, x3, y3)
	 bezier: add a bezier curve to the edge matrix -
	    takes 8 arguments (x0, y0, x1, y1, x2, y2, x3, y3)
	 ident: set the transform matrix to the identity matrix - 
	 scale: create a scale matrix, 
	    then multiply the transform matrix by the scale matrix - 
	    takes 3 arguments (sx, sy, sz)
	 translate: create a translation matrix, 
	    then multiply the transform matrix by the translation matrix - 
	    takes 3 arguments (tx, ty, tz)
	 xrotate: create an x-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 yrotate: create an y-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 zrotate: create an z-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 apply: apply the current transformation matrix to the 
	    edge matrix
	 display: draw the lines of the edge matrix to the screen
	    display the screen
	 save: draw the lines of the edge matrix to the screen
	    save the screen to a file -
	    takes 1 argument (file name)
	 quit: end parsing

See the file script for an example of the file format


IMPORTANT MATH NOTE:
the trig functions int math.h use radian mesure, but us normal
humans use degrees, so the file will contain degrees for rotations,
be sure to conver those degrees to radians (M_PI is the constant
for PI)
====================*/
void parse_file ( char * filename, 
                  struct matrix * transform, 
                  struct matrix * pm,
                  screen s) {
  FILE *f;
  char line[256];
  char next[256];
  char *next_arg;
  color c;
  c.red=255;c.blue=255;c.green=25;
  double args[52];
  double DEFAULT_STEP=0.01;
  clear_screen(s);
  
  if ( strcmp(filename, "stdin") == 0 ) 
    f = stdin;
  else
    f = fopen(filename, "r");
  
  while ( fgets(line, 255, f) != NULL ) {  
    line[strlen(line)-1]='\0';
    if (strcmp(line,"apply")==0){
      matrix_mult(transform,pm);
    }
    else if (strcmp(line,"display")==0){
      draw_lines(pm,s,c);
      display(s);
    }
    else if (strcmp(line,"quit")==0){
      exit(0);
    }
    else if (strcmp(line,"ident")==0){
      ident(transform);
    }
    else{
      fgets(next,255,f);
      next[strlen(next)-1]='\0';
      next_arg=next;
      int i = 0;
      while (next_arg != 0){
	args[i]=strtod(strsep(&next_arg," "),NULL);
	i++;
      }
      if (strcmp(line,"save")==0){
	fgets(next,255,f);
	save_extension(s,next);
      }
    }
    if (strcmp(line,"line")==0){
      add_edge(pm,args[0],args[1],args[2],args[3],args[4],args[5]);
    }
    if (strcmp(line,"circle")==0){
      add_circle(pm,args[0],args[1],args[2],DEFAULT_STEP);
    }
    if (strcmp(line,"hermite")==0){
      add_curve(pm,args[0],args[1],args[4],args[5],args[2]-args[0],args[3]-args[1],args[6]-args[4],args[7]-args[5],DEFAULT_STEP,HERMITE_MODE);
    }
    if (strcmp(line,"bezier")==0){
      add_curve(pm,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],DEFAULT_STEP,BEZIER_MODE);
    }
    if (strcmp(line,"scale")==0){
      matrix_mult(make_scale(args[0],args[1],args[2]),transform);
    }
    if (strcmp(line,"translate")==0){
      matrix_mult(make_translate(args[0],args[1],args[2]),transform);
    }
    if (strcmp(line,"xrotate")==0){
      matrix_mult(make_rotX(M_PI*args[0]/180.0),transform);
    }
    if (strcmp(line,"yrotate")==0){
      matrix_mult(make_rotY(M_PI*args[0]/180.0),transform);
    }
    if (strcmp(line,"zrotate")==0){
      matrix_mult(make_rotZ(M_PI*args[0]/180.0),transform);
    }   
    printf(":%s:\n",line);  
  }
}
Exemplo n.º 26
0
void demo_pong() {
	printf("Demo pong\n");

	int term_setting;

	int size = 20;
    int x=0, y=0;
    int dx=3, dy=1;

    int pady = 30;
    int padx = 100;
    int paddy = 30;
    int paddx = 10;

    int maxd = 4;

    char c;
    int active = 1;
    int alive = 1;

	term_setting = fcntl(0, F_GETFL, 0);
	fcntl (0, F_SETFL, (term_setting | O_NDELAY));

	clear_screen();
	lcd_set_rect(padx, pady, padx+paddx, pady+paddy, FILL, YELLOW, display);

    while (active) {
		/* Clear previous */
		lcd_set_rect(x, y, x+size, y+size, FILL, BLACK, display);

		if (x+size >= padx) {
			if ((y+size < pady) || (y > pady+paddy)) {
				//die
				alive = 0;
				active = 0;
			}
			else  {
				if (dy <= 0) {
					dy = -(rand() % 5);
				}
				else {
					dy = rand() % 5;
				}
				dx = -dx;
				x = padx - size - 1;
				lcd_set_rect(padx, pady, padx+paddx, pady+paddy, FILL, YELLOW, display);
			}
		}
		if (y+size >= 129) {
			dy = -dy;
			y = 129 - size;
		}
		if (x <= 0) {
			dx = -dx;
			x = 0;
		}
		if (y <= 0) {
			dy = -dy;
			y = 0;
		}

		x+=dx;
		y+=dy;

		/* Draw new */
		lcd_set_rect(x, y, x+size, y+size, FILL, GREEN, display);

		c = get_key();
		switch (c) {
		case LEFT:
			lcd_set_rect(padx, pady, padx+paddx, pady+paddy, FILL, BLACK, display);
			pady -= 10;
			lcd_set_rect(padx, pady, padx+paddx, pady+paddy, FILL, YELLOW, display);
			break;
		case RIGHT:
			lcd_set_rect(padx, pady, padx+paddx, pady+paddy, FILL, BLACK, display);
			pady += 10;
			lcd_set_rect(padx, pady, padx+paddx, pady+paddy, FILL, YELLOW, display);
			break;
		case QUIT:
		case ENTER:
			active = 0;
			break;
		}
	}

    fcntl(0, F_SETFL, term_setting);

    /* Player pressed quit */
    if (alive) {
    	return;
    }

    lcd_put_str("YOU LOST", 10, 10, LARGE, YELLOW, display);

    active = 1;
    while (active) {
		/* Clear previous */
		lcd_set_rect(x, y, x+size, y+size, FILL, BLACK, display);

		if (x+size >= 129+size) {
			active = 0;
		}

		x+=dx;
		y+=dy;

		/* Draw new */
		lcd_set_rect(x, y, x+size, y+size, FILL, RED, display);
	}

    get_key();

}
Exemplo n.º 27
0
int more(void)
{
    long present_time;
    static char more_buf[] = "-- more --";
    char c;

    if(!more_val.on
       || !more_val.delay
       || more_val.non_stop
       || kill_client_output
       || kill_socket_output
       || (client_stats < L_BOOTED)) {
        return 0;
    }

    /* If we are doing a forward then skip if need be */
    if(more_val.forward) {
        if(more_val.forward < (more_val.num_rows - 1)) {
            ++more_val.forward;

            return 1;
        }
        else {
            move_val.forward = FALSE;
            more_val.num_lines_scrolled = 0;
        }
    }

    /* Too many lines in specified time? If not continue */
    preset_time = time(0);

    if(present_time > (more_val.last_line_time + more_val.delay)) {
        more_val.num_lines_scrolled = 1;
        move_val.last_line_time = present_time;

        return 0;
    }

    /* Not too many lines yet...so print out the line */
    ++more_val.num_lines_scrolled;

    if(more_val.num_lines_scrolled < more_val.num_rows) {
        return 0;
    }

    /* Oops..too many lines...prompt the more */
    paused = TRUE;
    promptfor(more_buf, &c, PROMPT_CHAR);
    pasued = FALSE;

    if(c == more_val.k_quit) {
        /* Prevent problems if prompt triggers */
        ++kill_client_output;
        ++kill_socket_output;

        return 1;
    }
    else if(c == more_val.k_clear) {
        clear_screen();
        more_val.num_lines_scrolled = 0;
    }
    else if(c == more_val.k_cancel) {
        move_val.on = FALSE;
    }
    else if(c == more_val.k_nonstop) {
        more_val.non_stop = TRUE;
    }
    else if(c == more_val.k_forward) {
        more_val.forward = TRUE;

        return 1;
    }
    else if(c == more_val.k_oneline) {
        --more_val.num_lines_scrolled;
    }
    else {
        more_val.num_lines_scrolled = 0;
    }

    refresh_input();
    more_val.last_line_time = time(0);

    return 0;
}
Exemplo n.º 28
0
int main (int argc, char** argv)
{
   printf("\nPress \"1\" to draw a non-filled rectangle.\n");
   printf("Press \"2\" to draw a filled circle.\n");
   printf("Press \"3\" to display a string.\n");
   printf("**Select shape. Use the \"WASD\" keys to move the shape around.\n");
   printf("**Press the \"q\" at any point to termiante the program.\n");

   char key;
   int x = (640-20)/2;
   int y = (480-20)/2;
   int choice;
   scanf("%d", &choice);

   /**
   * Draw a non-filled rectangle.
   * Move around with 'WASD' keys.
   * Terminate with 'q' key.
   */
   {
   if(choice == 1)
      init_graphics();
      clear_screen();
      draw_rect(x, y, 200, 100, 20);
      do
      {
         key = getkey();
         if(key == 'w') y-=10;
         else if(key == 's') y+=10;
         else if(key == 'a') x-=10;
         else if(key == 'd') x+=10;
         clear_screen();
         draw_rect(x, y, 200, 100, 20);
         sleep_ms(20);
      } while(key != 'q');
      clear_screen();
      exit_graphics();
   }

   /**
   * Draw a filled circle with the midpoint circle algorithm.
   * Move around with 'WASD' keys.
   * Terminate with 'q' key.
   */
   if(choice == 2)
   {
      init_graphics();
      clear_screen();
      fill_circle(x, y, 75, 20);
      do
      {
         key = getkey();
         if(key == 'w') y-=10;
         else if(key == 's') y+=10;
         else if(key == 'a') x-=10;
         else if(key == 'd') x+=10;
         clear_screen();
         fill_circle(x, y, 75, 20);
         sleep_ms(20);
      } while(key != 'q');
         clear_screen();
         exit_graphics();
   }

   /**
   * Write a string usign the iso_font.h header file.
   * Move around with 'WASD' keys.
   * Terminate with 'q' key.
   */
   if(choice == 3)
   {
      const char *text_input = "Hello World!";
      init_graphics();
      clear_screen();
      draw_text(x, y, text_input, 20);
   do
   {
      key = getkey();
      if(key == 'w') x-=10;
      else if(key == 's') x+=10;
      else if(key == 'a') y-=10;
      else if(key == 'd') y+=10;
      clear_screen();
      draw_text(x, y, text_input, 20);
      sleep_ms(20);
   } while(key != 'q');
      clear_screen();
      exit_graphics();
   }

   return 0;
}
Exemplo n.º 29
0
/*======== void my_main() ==========
  Inputs: int polygons
  Returns:

  This is the main engine of the interpreter, it should
  handle most of the commands in mdl.

  If frames is not present in the source (and therefore
  num_frames is 1) then process_knobs should be called.

  If frames is present, the entire op array must be
  applied frames time. At the end of each frame iteration
  save the current screen to a file named the
  provided basename plus a numeric string such that the
  files will be listed in order, then clear the screen and
  reset any other data structures that need it.

  Important note: you cannot just name your files in
  regular sequence, like pic0, pic1, pic2, pic3... if that
  is done, then pic1, pic10, pic11... will come before pic2
  and so on. In order to keep things clear, add leading 0s
  to the numeric portion of the name. If you use sprintf,
  you can use "%0xd" for this purpose. It will add at most
  x 0s in front of a number, if needed, so if used correctly,
  and x = 4, you would get numbers like 0001, 0002, 0011,
  0487

  05/17/12 09:41:35
  jdyrlandweaver
  ====================*/
void my_main( int polygons ) {

  int i, f, j;
  double step;
  double xval, yval, zval, knob_value;
  struct matrix *transform;
  struct matrix *tmp;
  struct stack *s;
  screen t;
  color g;
  char *q;

  int k;
  char *p;
  p = name;
  int m;
  struct vary_node* caller;
  knob_value = 1;
  double carry;

  num_frames = 1;
  step = 0.05;

  g.red = 0;
  g.green = 255;
  g.blue = 255;

  s = new_stack();
  tmp = new_matrix(4, 1000);
  clear_screen( t );

  first_pass();

  if(num_frames < 0){
    printf("AH...NO, NOT WITHOUT FRAMES CAN YOU VARY.\n");
  }

  struct vary_node ** kn = second_pass();

  for(k = 0; k < num_frames; k++){

    for(i = 0; i < XRES; i++){
      for(j = 0; j < YRES; j++){
	zBuffer[i][j] = -2147483647;
      }
    }

    for ( i=0; i < lastsym; i++ ) {

      if ( symtab[i].type == SYM_VALUE ) {
	caller = kn[k];

	while((caller) && (strcmp(caller->name,symtab[i].name) != 0)){
	  caller = caller->next;
	}

	if(caller){
	  (&symtab[i])->s.value = caller->value;
	}

      }
    }

    for (i=0;i<lastop;i++) {
      switch (op[i].opcode) {

      case SETKNOBS:
	//carry = op[i].op.setknobs.value;

	for( i = 0; i < lastsym; i++){

	  if(symtab[i].type == SYM_VALUE){
	    set_value(&(symtab[i]), op[i].op.setknobs.value);
	  }

	}
	break;

      case SET:
	//carry = op[i].op.set.p->s.value;
	set_value(lookup_symbol(op[i].op.set.p->name), op[i].op.set.p->s.value);
	break;

      case SPHERE:
	add_sphere( tmp,op[i].op.sphere.d[0], //cx
		    op[i].op.sphere.d[1], //cy
		    op[i].op.sphere.d[2], //cz
		    op[i].op.sphere.r,
		    step);
	//apply the current top origin
	//pointInfo(op[i].op.sphere.constants->name);
	matrix_mult( s->data[ s->top ], tmp );
	pointInfo(op[i].op.sphere.constants->name);
	ambi.red = ambiRed;
	ambi.green = ambiGreen;
	ambi.blue = ambiBlue;
	draw_polygons( tmp, t, g );
	//printf("%f %f %f\n", ambiRed, ambiGreen, ambiBlue);
	tmp->lastcol = 0;
	break;

      case TORUS:
	add_torus( tmp, op[i].op.torus.d[0], //cx
		   op[i].op.torus.d[1], //cy
		   op[i].op.torus.d[2], //cz
		   op[i].op.torus.r0,
		   op[i].op.torus.r1,
		   step);
	pointInfo(op[i].op.torus.constants->name);
	matrix_mult( s->data[ s->top ], tmp );
	draw_polygons( tmp, t, g );
	tmp->lastcol = 0;
	break;

      case BOX:
	add_box( tmp, op[i].op.box.d0[0],
		 op[i].op.box.d0[1],
		 op[i].op.box.d0[2],
		 op[i].op.box.d1[0],
		 op[i].op.box.d1[1],
		 op[i].op.box.d1[2]);
	pointInfo(op[i].op.box.constants->name);
	matrix_mult( s->data[ s->top ], tmp );
	draw_polygons( tmp, t, g );
	tmp->lastcol = 0;
	break;

      case LINE:
	add_edge( tmp, op[i].op.line.p0[0],
		  op[i].op.line.p0[1],
		  op[i].op.line.p0[1],
		  op[i].op.line.p1[0],
		  op[i].op.line.p1[1],
		  op[i].op.line.p1[1]);
	draw_lines( tmp, t, g );
	tmp->lastcol = 0;
	break;

      case MOVE:

	if(op[i].op.move.p != NULL){
	  caller = kn[k];
	  while((caller) && (strcmp(caller->name, op[i].op.move.p->name) != 0)){
	    caller = caller->next;
	  }
	  if(caller){
	    knob_value = caller->value;
	  }
	}

	//get the factors
	xval = op[i].op.move.d[0] * knob_value;
	yval = op[i].op.move.d[1] * knob_value;
	zval = op[i].op.move.d[2] * knob_value;

	transform = make_translate( xval, yval, zval );
	//multiply by the existing origin
	matrix_mult( s->data[ s->top ], transform );
	//put the new matrix on the top
	copy_matrix( transform, s->data[ s->top ] );
	free_matrix( transform );
	break;

      case SCALE:

	if(op[i].op.scale.p != NULL){
	  caller = kn[k];
	  while((caller) && (strcmp(caller->name, op[i].op.scale.p->name) != 0)){
	    caller = caller->next;
	  }
	  if(caller){
	    knob_value = caller->value;
	  }
	}

	xval = op[i].op.scale.d[0] * knob_value;
	yval = op[i].op.scale.d[1] * knob_value;
	zval = op[i].op.scale.d[2] * knob_value;

	transform = make_scale( xval, yval, zval );
	matrix_mult( s->data[ s->top ], transform );
	//put the new matrix on the top
	copy_matrix( transform, s->data[ s->top ] );
	free_matrix( transform );
	break;

      case ROTATE:

	if(op[i].op.rotate.p != NULL){
	  caller = kn[k];
	  while((caller) && (strcmp(caller->name, op[i].op.rotate.p->name) != 0)){
	    caller = caller->next;
	  }
	  if(caller){
	    knob_value = caller->value;
	  }
	}

	xval = op[i].op.rotate.degrees * ( M_PI / 180 ) * knob_value;

	//get the axis
	if ( op[i].op.rotate.axis == 0 )
	  transform = make_rotX( xval );
	else if ( op[i].op.rotate.axis == 1 )
	  transform = make_rotY( xval );
	else if ( op[i].op.rotate.axis == 2 )
	  transform = make_rotZ( xval );

	matrix_mult( s->data[ s->top ], transform );
	//put the new matrix on the top
	copy_matrix( transform, s->data[ s->top ] );
	free_matrix( transform );
	break;

      case PUSH:
	push( s );
	break;
      case POP:
	pop( s );
	break;
      case SAVE:
	save_extension( t, op[i].op.save.p->name );
	break;
      case DISPLAY:
	display( t );
	break;

      }
    }

    strcpy(name, op[refer].op.basename.p->name);
    char value[256];
    char adder[256];
    strcpy(value, "hermano/");
    strcat(value, name);
    sprintf(adder, "%04d", k);
    strcat(value, adder);
    strcat(value, ".png");
    save_extension(t, value);

    clear_screen(t);
    s = new_stack();
    tmp = new_matrix(4,1000);
  }

  free_stack( s );
  free_matrix( tmp );
  //free_matrix( transform );
}
Exemplo n.º 30
0
/*
 * Check for escape code sequence.
 * Rreturn true if escape
 *
 * <Support list>
 *  ESC[#;#H or	: moves cursor to line #, column #
 *  ESC[#;#f
 *  ESC[#A	: moves cursor up # lines
 *  ESC[#B	: moves cursor down # lines
 *  ESC[#C	: moves cursor right # spaces
 *  ESC[#D	: moves cursor left # spaces
 *  ESC[#;#R	: reports current cursor line & column
 *  ESC[s	: save cursor position for recall later
 *  ESC[u	: return to saved cursor position
 *  ESC[2J	: clear screen and home cursor
 *  ESC[K	: clear to end of line
 *  ESC[#m	: attribute (0=attribure off, 4=underline, 5=blink)
 */
static int
check_escape(char c)
{
	int move = 0;
	int val;
	u_short color;

	if (c == 033) {
		esc_index = 1;
		esc_argc = 0;
		return 1;
	}
	if (esc_index == 0)
		return 0;

	if (c >= '0' && c <= '9') {
		val = c - '0';
		switch (esc_argc) {
		case 0:
			esc_arg1 = val;
			esc_index++;
			break;
		case 1:
			esc_arg1 = esc_arg1 * 10 + val;
			break;
		case 2:
			esc_arg2 = val;
			esc_index++;
			break;
		case 3:
			esc_arg2 = esc_arg2 * 10 + val;
			break;
		default:
			goto reset;
		}
		esc_argc++;
		return 1;
	}

	esc_index++;

	switch (esc_index) {
        case 2:
		if (c != '[')
			goto reset;
		return 1;
	case 3:
		switch (c) {
		case 's':	/* Save cursor position */
			esc_saved_x = pos_x;
			esc_saved_y = pos_y;
			break;
		case 'u':	/* Return to saved cursor position */
			pos_x = esc_saved_x;
			pos_y = esc_saved_y;
			move_cursor();
			break;
		case 'K':	/* Clear to end of line */
			break;
		}
		goto reset;
	case 4:
		switch (c) {
		case 'A':	/* Move cursor up # lines */
			pos_y -= esc_arg1;
			if (pos_y < 0)
				pos_y = 0;
			move = 1;
			break;
		case 'B':	/* Move cursor down # lines */
			pos_y += esc_arg1;
			if (pos_y >= rows)
				pos_y = rows - 1;
			move = 1;
			break;
		case 'C':	/* Move cursor forward # spaces */
			pos_x += esc_arg1;
			if (pos_x >= cols)
				pos_x = cols - 1;
			move = 1;
			break;
		case 'D':	/* Move cursor back # spaces */
			pos_x -= esc_arg1;
			if (pos_x < 0)
				pos_x = 0;
			move = 1;
			break;
		case ';':
			if (esc_argc == 1)
				esc_argc = 2;
			return 1;
		case 'J':
			if (esc_arg1 == 2)	/* Clear screen */
				clear_screen();
			break;
		case 'm':	/* Change attribute */
			switch (esc_arg1) {
			case 0:		/* reset */
				attrib = 0x0F;
				break;
			case 1:		/* bold */
				attrib = 0x0F;
				break;
			case 4:		/* under line */
				break;
			case 5:		/* blink */
				attrib |= 0x80;
				break;
			case 30: case 31: case 32: case 33:
			case 34: case 35: case 36: case 37:
				color = ansi_colors[esc_arg1 - 30];
				attrib = (attrib & 0xf0) | color;
				break;
			case 40: case 41: case 42: case 43:
			case 44: case 45: case 46: case 47:
				color = ansi_colors[esc_arg1 - 40];
				attrib = (attrib & 0x0f) | (color << 4);
				break;
			}
			break;

		}
		if (move)
			move_cursor();
		goto reset;
	case 6:
		switch (c) {
		case 'H':
		case 'f':
			pos_y = esc_arg1;
			pos_x = esc_arg2;
			if (pos_y >= rows)
				pos_y = rows - 1;
			if (pos_x >= cols)
				pos_x = cols - 1;
			move_cursor();
			break;
		case 'R':
			/* XXX */
			break;
		}
		goto reset;
	default:
		goto reset;
	}
	return 1;
 reset:
	esc_index = 0;
	esc_argc = 0;
	return 1;
}