mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-07-04 15:43:11 +02:00
feat: move folder
This commit is contained in:
parent
aa5f59c32e
commit
8333a455e2
21
C/1dvelocitysimulator/LICENSE
Normal file
21
C/1dvelocitysimulator/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022 Krzysztof Rudnicki
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
171
C/1dvelocitysimulator/main.c
Executable file
171
C/1dvelocitysimulator/main.c
Executable file
@ -0,0 +1,171 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#define LINE_LENGTH 100
|
||||||
|
|
||||||
|
void C()
|
||||||
|
{
|
||||||
|
printf("\nCheck\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printAcceleration(int acceleration)
|
||||||
|
{
|
||||||
|
printf("The value of acceleration is: %d\n", acceleration);
|
||||||
|
system("PAUSE");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pauseSystem()
|
||||||
|
{
|
||||||
|
system("PAUSE");
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearScreen()
|
||||||
|
{
|
||||||
|
system("CLS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pauseForASecond()
|
||||||
|
{
|
||||||
|
Sleep(1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pauseForGivenTime(float given_time)
|
||||||
|
{
|
||||||
|
Sleep(fabs(given_time * 1000));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float calculateVelocity(float starting_velocity, unsigned int physics_time, int *acceleration)
|
||||||
|
{
|
||||||
|
return (*acceleration) * physics_time + starting_velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
int calculateDisplacement(float starting_velocity, int *acceleration, unsigned int physics_time)
|
||||||
|
{
|
||||||
|
return starting_velocity * physics_time + ( (1 / 2) * (*acceleration) * (physics_time ^ 2) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void printXPosition(int position)
|
||||||
|
{
|
||||||
|
printf("\nx position is: %d\n", position);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printClock(unsigned int *time)
|
||||||
|
{
|
||||||
|
printf("%d seconds passed\n", *time);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float calculateStopTime(float velocity)
|
||||||
|
{
|
||||||
|
return 1 / velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printLine(int position)
|
||||||
|
{
|
||||||
|
clearScreen();
|
||||||
|
for(int i = -(LINE_LENGTH / 2); i < LINE_LENGTH / 2; i++)
|
||||||
|
{
|
||||||
|
if(i == position) printf("x");
|
||||||
|
else printf("-");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printVelocity(float velocity)
|
||||||
|
{
|
||||||
|
printf("Velocity is: %f\n", velocity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int calculateTimePassed(float velocity)
|
||||||
|
{
|
||||||
|
if(velocity >= 1 || velocity <= -1) return 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Time passed is: %f\n", fabs(1 / velocity));
|
||||||
|
return fabs(1 / velocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void printAllInfo(int position, unsigned int *time, float *velocity)
|
||||||
|
{
|
||||||
|
pauseForGivenTime(calculateStopTime(*velocity));
|
||||||
|
printLine(position);
|
||||||
|
printXPosition(position);
|
||||||
|
*time += calculateTimePassed(*velocity);
|
||||||
|
printClock(time);
|
||||||
|
printVelocity(*velocity);
|
||||||
|
//pauseForASecond();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float chooseVelocity()
|
||||||
|
{
|
||||||
|
float velocity;
|
||||||
|
printf("Write velocity of the object in m / s: ");
|
||||||
|
scanf("%f", &velocity);
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
int chooseAcceleration()
|
||||||
|
{
|
||||||
|
int acceleration;
|
||||||
|
printf("Choose acceleration of the object in m / (s ^ 2):");
|
||||||
|
scanf("%d", &acceleration);
|
||||||
|
return acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
|
int outOfLine(int position)
|
||||||
|
{
|
||||||
|
if((position < LINE_LENGTH / 2) && (position > -1 * (LINE_LENGTH / 2)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}else return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveUntillOutOfLine(int position, unsigned int *time)
|
||||||
|
{
|
||||||
|
while(!outOfLine(position))
|
||||||
|
{
|
||||||
|
float velocity = chooseVelocity();
|
||||||
|
float *Pvelocity = &velocity;
|
||||||
|
position += calculateDisplacement(velocity, 0, 1);
|
||||||
|
printAllInfo(position, time, Pvelocity);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveUntillOutOfVelocity(int position, int *acceleration, unsigned int *time)
|
||||||
|
{
|
||||||
|
float velocity = 0;
|
||||||
|
float *Pvelocity = &velocity;
|
||||||
|
while(!outOfLine(position))
|
||||||
|
{
|
||||||
|
position += calculateDisplacement(velocity, acceleration, 1);
|
||||||
|
printXPosition(position);
|
||||||
|
pauseSystem();
|
||||||
|
velocity = calculateVelocity(velocity, 1, acceleration);
|
||||||
|
printAllInfo(position, time, Pvelocity);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int position = 0, acceleration = -1;
|
||||||
|
int *Pacceleration = &acceleration;
|
||||||
|
unsigned int time = 0;
|
||||||
|
unsigned int *Ptime = &time;
|
||||||
|
moveUntillOutOfLine(position, Ptime);
|
||||||
|
//moveUntillOutOfVelocity(position, Pacceleration, Ptime);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user