Exemple #1
0
int main(int argc, char ** argv) {
	int res;
	Matrix * A = readFromFile(argv[1]);
	Matrix * b = readFromFile(argv[2]);
	Matrix * x;

	if (A == NULL) return -1;
	if (b == NULL) return -2;
	printToScreen(A);
	printToScreen(b);

	res = eliminate(A,b);
	x = createMatrix(b->r, 1);
	if (x != NULL) {
		res = backsubst(x,A,b);

		printToScreen(x);
	  freeMatrix(x);
	} else {
					fprintf(stderr,"Błąd! Nie mogłem utworzyć wektora wynikowego x.\n");
	}

	freeMatrix(A);
	freeMatrix(b);

	return 0;
}
Exemple #2
0
void game::run(){
	//TODO nanti harus diganti
	init();
	drawCanvas(0,0,0,255);
	drawTextCentered("GRAPHICAT",9,50,3,255,0,0,255);
	drawTextCentered("PLANE SHOOTER",13,150,3,255,0,0,255);
	drawTextCentered("Press A or D to move ship left or right",39,250,1,255,0,0,255);
	drawTextCentered("Press J or L to rotate the ship turret",38,300,1,255,0,0,255);
	drawTextCentered("Press Space to shoot",20,350,1,255,0,0,255);
	drawTextCentered("Press Q to change weapon",24,400,1,255,0,0,255);
	printToScreen();
	sleep(5);
	while (!gameOver()){
		updateControls();
		updateLogic();
		drawScreen();

		usleep(200);
	}
	usleep(500);
	drawTextCentered("YOU WIN",7,300,5,255,0,0,255);
	printToScreen();
	usleep(500);

	finishPrinter();
	resetTermios();
	sleep(2);
}
int main() {
	if (initializePrinter()!=0) return 1;

	system("setterm -cursor off");

	drawCanvas(255,255,255,255);
	printToScreen();

	//drawPixSquare(5, 5, 5, 22, 22, 22, 255);

	circle C = circle(100,100,100,2);
	C.drawCircle(55,22,11,255, true, true);
	printToScreen();



	usleep(1000000);
	system("setterm -cursor on");
	finishPrinter();



	
	return 0;
}
int main(){
	system("setterm -cursor on");

	//coba bikin huruf terus print

	//bikin huruf A kebalik
	polygon p;
	p.push_back(0,0);
	p.push_back(4,12);
	p.push_back(8,0);
	p.push_back(7,0);
	p.push_back(6,3);
	p.push_back(2,3);
	p.push_back(1,0);

	std::vector<polygon> bidangs;
	bidangs.push_back(p);

	polygon p2;
	p2.push_back(3,5);
	p2.push_back(4,10);
	p2.push_back(5,5);

	std::vector<polygon>lubangs;
	lubangs.push_back(p2);

// Ini mau implementasi teks
	letter letterAKebalik(bidangs,lubangs,9,13);
	initializePrinter();
	pixelBoolMatrix pbm1 = letterAKebalik.toPixelBoolMatrix(1);

	drawCanvas(0,0,0,255);
	pbm1.draw(10,10,255,255,255,255);
	printToScreen();
	sleep(1);
// Akhir


	for (int i=0;i<100;i++){
		pixelBoolMatrix pbm = letterAKebalik.toPixelBoolMatrix(1+(float)i/10);
		drawCanvas(0,0,0,255);
		pbm.draw(10,10,255,255,255,255);
		printToScreen();
		usleep(1000);

	}
	finishPrinter();
	system("setterm -cursor on");
	
}
int main(){

	initializePrinter();
	
	polygon p;
	p.push_back(4,4);
	p.push_back(30,100);
	p.push_back(100,4);
	p.push_back(30,400);

	//test print
	std::cout<<"hasil putar: "<<std::endl;
	polygon pPutar = p.hasilRotasi(180);
	for (int i=0;i<pPutar.size();i++){
		std::cout<<pPutar[i].getX()<<"\t"<<pPutar[i].getY()<<std::endl;
	}
	std::cout<<"\n"<<std::endl;

	polygon pGeser = p.hasilGeser(100,100);
	for (int i=0;i<pPutar.size();i++){
		std::cout<<pGeser[i].getX()<<"\t"<<pGeser[i].getY()<<std::endl;
	}
	std::cout<<"\n"<<std::endl;

	drawCanvas(0,0,0,255);
	p.draw(10,10,255,255,255,255,true);
	printToScreen();
	sleep(3);
	p.draw(10,10,255,255,255,255,true);	
	printToScreen();
	sleep(3);

	for (float f = 0; f < 360; f+=1){
		drawCanvas(0,0,0,255);
		p.hasilRotasi(f).draw(10,10,255,255,255,255,true);
		printToScreen();
		usleep(100);
	}
	point poros(50,50);
	for (float f = 0; f < 360; f+=1){
		
		drawCanvas(0,0,0,255);
		p.hasilRotasi(f,poros).draw(10,10,255,255,255,255,true);
		printToScreen();
		usleep(100);
	}

	finishPrinter();
}
Exemple #6
0
void game::drawScreen(){
	drawCanvas(0,0,0,255);
	for (int i=screenObjects.size()-1;i>=0;i--){
		screenObjects[i]->draw();
	}
	printToScreen();
}
Exemple #7
0
void radixSort(int *x, int n)
{
    int max=0,i;
    for (i=0; i<n; i++) if (x[i]>max)
        {
            max=x[i];
            assignments++;
        }
    radix(x,n,max,1);
    printToScreen(x,n);
}
int main(){
	initializePrinter();
	drawCanvas(0,0,0,255);
	int x,y;
	y = getYRes()/2;
	x = getXRes()/2;
	circle C = makeCircle(0,0,0,255,20,x,y);
	for (i=0;i<=360;i++) {
		rotateCircle(C,i,x,y);
		drawCircle(C);
	}
	printToScreen();
	finishPrinter();
}
/* Channel is open, so monitor data */
static void UserAppSM_ChannelOpen(void)
{
  static u8 u8LastState = 0xff;
  static u8 au8TickMessage[] = "EVENT x\n\r";  /* "x" at index [6] will be replaced by the current code */
  static u8 au8DataContent[] = "xxxxxxxxxxxxxxxx";
  static u8 au8LastAntData[ANT_APPLICATION_MESSAGE_BYTES] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  static u8 au8TestMessage[] = {0, 0, 0, 0, 0xA5, 0, 0, 0};
  bool bGotNewData;

  /* Check for BUTTON0 to close channel */
  if(WasButtonPressed(BUTTON0))
  {
    /* Got the button, so complete one-time actions before next state */
    ButtonAcknowledge(BUTTON0);
    
    /* Queue close channel and change LED to blinking green to indicate channel is closing */
    AntCloseChannel();
    u8LastState = 0xff;

#ifdef MPG1
    LedOff(YELLOW);
    LedOff(BLUE);
    LedBlink(GREEN, LED_2HZ);
#endif /* MPG1 */    
    
#ifdef MPG2
    LedOff(RED0);
    LedOff(BLUE0);
    LedBlink(GREEN0, LED_2HZ);
#endif /* MPG2 */
    
    /* Set timer and advance states */
    UserApp_u32Timeout = G_u32SystemTime1ms;
    UserApp_StateMachine = UserAppSM_WaitChannelClose;
  } /* end if(WasButtonPressed(BUTTON0)) */
  
  /* Always check for ANT messages */
  if( AntReadData() )
  {
     /* New data message: check what it is */
    if(G_eAntApiCurrentMessageClass == ANT_DATA)
    {
      UserApp_u32DataMsgCount++;
      
      /* Check if the new data is the same as the old data and update as we go */
      bGotNewData = TRUE;//used to be false
      for(u8 i = 0; i < ANT_APPLICATION_MESSAGE_BYTES; i++)
      {
        if(G_au8AntApiCurrentData[i] != au8LastAntData[i])
        {
          bGotNewData = TRUE;
          au8LastAntData[i] = G_au8AntApiCurrentData[i];

          au8DataContent[2 * i] = HexToASCIICharUpper(G_au8AntApiCurrentData[i] / 16);
          au8DataContent[2 * i + 1] = HexToASCIICharUpper(G_au8AntApiCurrentData[i] % 16); 
        }
      }
      
      
      if(bGotNewData)
      {
        /* We got new data: show on LCD */
#ifdef MPG1
        LCDClearChars(LINE2_START_ADDR, 20); 
        LCDMessage(LINE2_START_ADDR, au8DataContent); 
#endif /* MPG1 */    
    
#ifdef MPG2
        PixelAddressType sStringLocation1 = {0, 122}; 
        PixelAddressType sStringLocation2 = {8, 122};
        PixelAddressType sStringLocation3 = {16, 122};
        const unsigned char * HRTop = ReturnTopDigit(G_au8AntApiCurrentData[7]);
        const unsigned char * HRMiddle = ReturnMiddleDigit(G_au8AntApiCurrentData[7]);
        const unsigned char * HRBottom = ReturnLastDigit(G_au8AntApiCurrentData[7]);
        LcdLoadString(HRTop, LCD_FONT_SMALL, &sStringLocation1); 
        LcdLoadString(HRMiddle, LCD_FONT_SMALL, &sStringLocation2); 
        LcdLoadString(HRBottom, LCD_FONT_SMALL, &sStringLocation3); 
        //LcdLoadString(" ",LCD_FONT_SMALL, &sStringLocation);
        printToScreen(G_au8AntApiCurrentData[7]);
#endif /* MPG2 */

        /* Update our local message counter and send the message back */
        au8TestMessage[7]++;
        if(au8TestMessage[7] == 0)
        {
          au8TestMessage[6]++;
          if(au8TestMessage[6] == 0)
          {
            au8TestMessage[5]++;
          }
        }
        AntQueueBroadcastMessage(au8TestMessage);

        /* Check for a special packet and respond */
#ifdef MPG1
        if(G_au8AntApiCurrentData[0] == 0xA5)
        {
          LedOff(LCD_RED);
          LedOff(LCD_GREEN);
          LedOff(LCD_BLUE);
          
          if(G_au8AntApiCurrentData[1] == 1)
          {
            LedOn(LCD_RED);
          }
          
          if(G_au8AntApiCurrentData[2] == 1)
          {
            LedOn(LCD_GREEN);
          }

          if(G_au8AntApiCurrentData[3] == 1)
          {
            LedOn(LCD_BLUE);
          }
        }
#endif /* MPG1 */    
    
#ifdef MPG2
        /*if(G_au8AntApiCurrentData[0] == 0xFF)
        {
          LedOff(RED3);
          LedOff(GREEN3);
          LedOff(BLUE3);
          
          if(G_au8AntApiCurrentData[1] == 0xFF)
          {
            LedOn(RED3);
          }
          
          if(G_au8AntApiCurrentData[2] == 0xFF)
          {
            LedOn(GREEN3);
          }

          if(G_au8AntApiCurrentData[3] == 0xFF)
          {
            LedOn(BLUE3);
          }
        }*/
        
        
#endif /* MPG2 */
      } /* end if(bGotNewData) */
    } /* end if(G_eAntApiCurrentMessageClass == ANT_DATA) */
    
    else if(G_eAntApiCurrentMessageClass == ANT_TICK)
    {
      UserApp_u32TickMsgCount++;

      /* Look at the TICK contents to check the event code and respond only if it's different */
      if(u8LastState != G_au8AntApiCurrentData[ANT_TICK_MSG_EVENT_CODE_INDEX])
      {
        /* The state changed so update u8LastState and queue a debug message */
        u8LastState = G_au8AntApiCurrentData[ANT_TICK_MSG_EVENT_CODE_INDEX];
        au8TickMessage[6] = HexToASCIICharUpper(u8LastState);
        DebugPrintf(au8TickMessage);

        /* Parse u8LastState to update LED status */
        switch (u8LastState)
        {
#ifdef MPG1
          /* If we are synced with a device, blue is solid */
          case RESPONSE_NO_ERROR:
          {
            LedOff(GREEN);
            LedOn(BLUE);
            break;
          }

          /* If we are paired but missing messages, blue blinks */
          case EVENT_RX_FAIL:
          {
            LedOff(GREEN);
            LedBlink(BLUE, LED_2HZ);
            break;
          }

          /* If we drop to search, LED is green */
          case EVENT_RX_FAIL_GO_TO_SEARCH:
          {
            LedOff(BLUE);
            LedOn(GREEN);
            break;
          }
#endif /* MPG 1 */
#ifdef MPG2
          /* If we are synced with a device, blue is solid */
          case RESPONSE_NO_ERROR:
          {
            LedOff(GREEN0);
            LedOn(BLUE0);
            break;
          }

          /* If we are paired but missing messages, blue blinks */
          case EVENT_RX_FAIL:
          {
            LedOff(GREEN0);
            LedBlink(BLUE0, LED_2HZ);
            break;
          }

          /* If we drop to search, LED is green */
          case EVENT_RX_FAIL_GO_TO_SEARCH:
          {
            LedOff(BLUE0);
            LedOn(GREEN0);
            break;
          }
#endif /* MPG 2 */
          /* If the search times out, the channel should automatically close */
          case EVENT_RX_SEARCH_TIMEOUT:
          {
            DebugPrintf("Search timeout\r\n");
            break;
          }

          default:
          {
            DebugPrintf("Unexpected Event\r\n");
            break;
          }
        } /* end switch (G_au8AntApiCurrentData) */
      } /* end if (u8LastState != G_au8AntApiCurrentData[ANT_TICK_MSG_EVENT_CODE_INDEX]) */
    } /* end else if(G_eAntApiCurrentMessageClass == ANT_TICK) */
    
  } /* end AntReadData() */
  
  /* A slave channel can close on its own, so explicitly check channel status */
  if(AntRadioStatus() != ANT_OPEN)
  {
#ifdef MPG1
    LedBlink(GREEN, LED_2HZ);
    LedOff(BLUE);
#endif /* MPG1 */

#ifdef MPG2
    LedBlink(GREEN0, LED_2HZ);
    LedOff(BLUE0);
#endif /* MPG2 */
    u8LastState = 0xff;
    
    UserApp_u32Timeout = G_u32SystemTime1ms;
    UserApp_StateMachine = UserAppSM_WaitChannelClose;
  } /* if(AntRadioStatus() != ANT_OPEN) */
      
} /* end UserAppSM_ChannelOpen() */
int mainLoop()
{   
    wchar_t ch = 0;
    int running = 1;
    int roundEnd = 0;

    int i = 0;
    while(running)
    {
        ch = getChar();
        if(ch == 27)
           break;

        /*
         * Rotates specified lines the
         * specified amount (in radians
         */
        rotateLine(line1,M_PI/1000);
        rotateLine(line2,M_PI/900);
        rotateLine(line3,-M_PI/900);

        /*
         * Firethruster handles input
         */
        fireThruster(ch);
        moveLander();

        /*
         * Time to sleep between frames
         */
        usleep(1000);

        if(roundEnd)
        {
            roundEnd = 0;
            clearPrintScreen();
            usleep(1000000);
            if(fuel < 0)
                running = 0;
        }

        /*
         * Convert fuel int to string 
         * and add to textVector
         */
        char fuelstr[7];
        sprintf(fuelstr,"%d",fuel_int);
        changeText(fuel,fuelstr);
        char scorestr[7];
        sprintf(scorestr,"%d",score_int);
        changeText(score,scorestr);

        draw();

        switch(detectWin(platform1,platform2))
        {
            case 0:
                break;
            case 1:
                printToScreen("Crashed!");
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 21:
                printToScreen("Landed too hard :( -100 fuel");
                score_int += 50;
                fuel_int -= 100;
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 22:
                printToScreen("Landed too hard :( -100 fuel");
                score_int += 75;
                fuel_int -= 100;
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 31:
                printToScreen("PERFECT LANDING!");
                score_int += 300;
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 32:
                printToScreen("PERFECT LANDING!");
                score_int += 200;
                draw();
                resetLander();
                roundEnd = 1;
                break;
            case 4:
                printToScreen("Out of fuel!");
                draw();
                resetLander();
                roundEnd = 1;
        }

    }
    exitVect();
    return 0;
}