Skip to content

Commit

Permalink
Added widthe to gucntion line in
Browse files Browse the repository at this point in the history
 bmp and fix the createnode added unari - + and added <num>x
  • Loading branch information
KlevisImeri committed Nov 13, 2022
1 parent f0449fd commit 26b3f6d
Show file tree
Hide file tree
Showing 17 changed files with 700 additions and 284 deletions.
5 changes: 2 additions & 3 deletions CnvCharNum.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int char_to_int(char c){
//Creates an integer written as an array of char.
//It evaluates from right ot left form the given starting point or '.' for decimal
int string_to_int(char *start){
//to start form a number not th inputed char
//to start form a number not the inputed char
start--;

//preperation
Expand Down Expand Up @@ -50,11 +50,10 @@ double string_to_decimal(char *start){
//converting a char to double
//Takes in the adress of the first or last dig depending on direction
double convert_to_num(char *adress, Direction DIR){
printf("%c---\n", *adress);
// printf("%c\n", *adress);
char *cursor = adress;
int num = 0;
double decimal = 0;

switch(DIR){
case RIGHT:
//while finds the '.' int the number
Expand Down
Binary file modified a.out
Binary file not shown.
88 changes: 63 additions & 25 deletions bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ void save_bitmap(const char *file_name, int width, int height, int dpi, rgb_data

void create_bitmap(Node *operations, size_t size, double *start, double end, double step, int width, int height, int dpi, int numberline_length){
//saving it for resetting the start
printf("integrator: %f\n", *start);
double i = *start;

rgb_data *pixels = (rgb_data *)malloc(width * height* 3*sizeof(float));

// int numberline_length = 4;
double divisions = 1000/(2*numberline_length);
// int numberline_length ;
double divisions = width/(2*numberline_length);

//color the backgorund black
for(int x = 0; x < width; x++) {
Expand All @@ -111,36 +110,47 @@ void create_bitmap(Node *operations, size_t size, double *start, double end, dou
int square_height;
int start_x;
for(; *start <= end; *start += step){
number_line_y = eval_Node(operations, size);
number_line_y = eval_Nodes(operations, size);
square_height = (number_line_y+numberline_length)*divisions;
start_x = (*start + numberline_length)*divisions;
square_width = (*start + step + numberline_length)*divisions;
//drawing square with specifined x and y
for(x=start_x ; x <= square_width && x<width; x++){
if(square_height>500){
for(y = 500; y<=square_height && y<height; y++){
// drawing square with specifined x and y
//printf("start_x: %d square_width:%d width:%d\n", start_x, square_width, width);
for(x=start_x; x <= square_width && x<width; x++){
if(square_height>=height/2){
//!!!y<height because of the segmentation falt (ovewrflow)
for(y = height/2; y<=square_height && y<height; y++){
int a = y * width + x;

// pixels[a].r = 15;
// pixels[a].g = 172;
// pixels[a].b = 245;

//for the line surronding the squares
if(y==square_height || x==square_width || x==start_x){
pixels[a].r = 1;
pixels[a].g = 49;
pixels[a].b = 112;
pixels[a].r = 255;
pixels[a].g = 77;
pixels[a].b = 77;
}else{
pixels[a].r = 15;
pixels[a].g = 172;
pixels[a].b = 245;
}
}
}else{
for(y = 500; y>=square_height && y>0; y--){
}else{
//!!!y>0 because of the segmentation falt (ovewrflow)
for(y = height/2; y>=square_height && y>0; y--){
int a = y * width + x;

// pixels[a].r = 15;
// pixels[a].g = 172;
// pixels[a].b = 245;

//for the line surronding the squares
if(y==square_height || y==500 || x==square_width || x==start_x){
pixels[a].r = 1;
pixels[a].g = 49;
pixels[a].b = 112;
if(y==square_height || y==height/2 || x==square_width || x==start_x){
pixels[a].r = 255;
pixels[a].g = 77;
pixels[a].b = 77;
}else{
pixels[a].r = 15;
pixels[a].g = 172;
Expand All @@ -156,22 +166,50 @@ void create_bitmap(Node *operations, size_t size, double *start, double end, dou
//it neds the start pointer for eval_Node
for(x = 0; x < width; x++){
*start = (x/divisions)-numberline_length;
number_line_y = eval_Node(operations, size);
y = round((number_line_y+numberline_length)*divisions) ;
if(y<=1000 && y>=0){
number_line_y = eval_Nodes(operations, size);
y = round((number_line_y+numberline_length)*divisions);
if(y<height && y>0){
int a = y * width + x;

pixels[a].r = 255;
pixels[a].g = 255;
pixels[a].b = 255;

//Make it thicker
//The thicnes(3 in this case) can be as a parameter
//to the fucntion
for(int i=0; i<5; i++){

//So we don't oferflow the array at the edges
//printf("Height: %d < %d && %d > 0\n",y+i, height, y-i);
if(y+i<height && y-i>0){
//Right
pixels[a+i].r = 255;
pixels[a+i].g = 255;
pixels[a+i].b = 255;
//Left
pixels[a-i].r = 255;
pixels[a-i].g = 255;
pixels[a-i].b = 255;
//Upp
pixels[a+i*width].r = 255;
pixels[a+i*width].g = 255;
pixels[a+i*width].b = 255;
//Down
pixels[a-i*width].r = 255;
pixels[a-i*width].g = 255;
pixels[a-i*width].b = 255;
}
}

}
}

//y = 0 line
for(x = 0; x < width; x++){
number_line_y = 0;
y = round((number_line_y+numberline_length)*divisions);
if(y<=1000 && y>=0){
y = (number_line_y+numberline_length)*divisions;
if(y<=height && y>=0){
int a = y * width + x;

pixels[a].r = 255;
Expand All @@ -183,8 +221,8 @@ void create_bitmap(Node *operations, size_t size, double *start, double end, dou
//x = 0 line
for(y = 0; y < height; y++){
number_line_x = 0;
x = round((number_line_x+numberline_length)*divisions) ;
if(x<=1000 && x>=0){
x = (number_line_x+numberline_length)*divisions;
if(x<=height && x>=0){
int a = y * width + x;

pixels[a].r = 255;
Expand All @@ -196,7 +234,7 @@ void create_bitmap(Node *operations, size_t size, double *start, double end, dou
//divisions line for x
for(number_line_x=-numberline_length; number_line_x<=numberline_length; number_line_x++){
x = (number_line_x+numberline_length)*divisions;
for(y = 480; y<=520; y++){
for(y = height/2-20; y<=height/2+20; y++){
int a = y * width + x;

pixels[a].r = 255;
Expand Down
89 changes: 76 additions & 13 deletions chararray.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//Prints array in array format
/*
Parameter: array and the size
Return: None
Prints array in array format in the console
*/
void print_char_array(char *array, size_t size){
printf("{");
for(int i=0; i<size-1; i++){
Expand All @@ -9,17 +15,74 @@ void print_char_array(char *array, size_t size){
printf("%c}\n", array[size-1]);
}

void input_char_array(char *array){
array[0] = '(';
/*
Parameter: destination array, source array, size of source
Return: None
It copies the source array into the destination array.
The destination array should be bigger.
*/
void copyarr(char* destination, char* source, size_t size_source){
for(int i=0; i<size_source; i++){
destination[i] = source[i];
}
}

/*
Parameter: Pointer the the size
Return:
-Dynamically allocated char array.
-NULL if the array coudn't allocate.
-Size of this array into the size pointer.
Asks the user to input the mathematical expression
and dynamically allocates the char array for the
expression. Returns the pointer to the array.
Array format: {'(' expression ')'}
*/
char *take_expression(size_t *size){
//preperation
size[0] = 1;
char c;
printf("Write your fucntion: ");
scanf("%c", &c);
int i = 1;
while(c != '\n'){
array[i] = c;
i++;
scanf("%c", &c);
//clering scanf from any unwated '\n'
while(scanf("%c", &c) == 1 && c != '\n'){};

//Creating the array
char *expressionArr = (char *)malloc(sizeof(char)*size[0]);
//if(expressionArr == 0) return NULL;
expressionArr[0] = '(';

//Asking the user
printf("Enter the function: ");

//Inputing the expression into the array
while(scanf("%c", &c) == 1 && c != '\n'){
//Removing the spaces
if(c == ' '){
continue;
}
//Extending the array.
//+2: 1 for newchar and 1 for ')'
char *newArr = (char *)malloc(sizeof(char)*(size[0]+2));
if(newArr == 0){
printf("Error: The array couldn't dynamically allocate!");
return NULL;
}
//Coping the previous array to the newone
copyarr(newArr, expressionArr, size[0]);
//Putiong the newchar in
newArr[*size] = c;
//Freeing the previos array
free(expressionArr);
//Making it point tho the new one
expressionArr = newArr;
//The size increased by one
size[0]++;
}
array[i] = ')';
print_char_array(array, 40);
}
//Putting and ')' at the and for the format
expressionArr[size[0]] = ')';

//compesatig for +2
size[0]++;
//print_char_array(expressionArr, size[0]);
//printf("Size of expression: %ld\n", size[0]);
return expressionArr;
}
5 changes: 4 additions & 1 deletion chararray.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#define chararray

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void print_char_array(char *array, size_t size);
void input_char_array(char *array);
void copyarr(char* destination, char* source, size_t size_source);
void *take_expression(size_t *size);

#endif
Loading

0 comments on commit 26b3f6d

Please sign in to comment.