-
Notifications
You must be signed in to change notification settings - Fork 0
/
subject_micro.en.txt
66 lines (54 loc) · 3.7 KB
/
subject_micro.en.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Assignment name : micro_paint
Expected files : *.c *.h
Allowed functions: fopen, fread, fscanf, fclose, write, malloc, calloc, realloc, free, memset, powf, sqrtf
--------------------------------------------------------------------------------------
Write a program that will read an "operation file" and print the result in the terminal
Your program must take one argument, it will be the path to the "operation file"
If 0 or more than 1 argument is given to your program write "Error: argument" followed by a \n in STDOUT
$> ./micro_paint | cat -e
Error: argument$
$> ./micro_paint do not fear mathematics | cat -e
Error: argument$
$>
If any problem occurs while you open and/or read the "operation file" write "Error: Operation file corrupted" followed by a \n in STDOUT
The "operation file" will contains lines with one operation per line
If a line is incorrect an error occurs.
If an error has occured your program must return 1
If no error has occured it must return 0
The last line can be with or without a \n
The lines must be read in order and therefore operations must be executed in the same order
There must be at least one space between each variable in a line
WIDTH HEIGHT BACKGROUND_CHAR
This line is always the first line of the file and it defines the zone where to draw. Your program should not display anything outside the draw zone. It must be there only once.
- WIDTH: must be a int with 0 < WIDTH <= 300, the horizontal number of characters to use for the draw zone
- HEIGHT: must be a int with 0 < HEIGHT <= 300, the vertical number of characters to use for the draw zone
- BACKGROUND_CHAR: any empty space will be filled with BACKGROUND_CHAR
r X Y WIDTH HEIGHT CHAR
This operation will draw an empty rectangle, where only the border of the rectangle is drawn
- r: the character r
- X: any float, the horizontal position of the top left corner of the rectangle
- Y: any float, the vertical position of the top left corner of the rectangle
- WIDTH: a positive float but not 0, the width of the rectangle (horizontal)
- HEIGHT: a positive float but not 0, the height of the rectangle (vertical)
- CHAR: the char use to draw the rectangle
R X Y WIDTH HEIGHT CHAR
This operation will draw a filled rectangle
- R: the character R
- X: any float, the horizontal position of the top left corner of the rectangle
- Y: any float, the vertical position of the top left corner of the rectangle
- WIDTH: a positive float but not 0, the width of the rectangle (horizontal)
- HEIGHT: a positive float but not 0, the height of the rectangle (vertical)
- CHAR: the char use to draw the rectangle
The draw zone is divided in rectangles that can contain one character each (because we are in a terminal...), we will call them pixel
To make everything easier, we will use only the top left corner of the pixel to know if that pixel is in a rectangle or not
A pixel with a top left corner with a distance bigger or equal than 1 from the border of a rectangle is not part of an empty rectangle
A pixel with a top left corner with a distance lower than 1 from the border of a rectangle is part of an empty rectangle.
You should look at the image while reading the next few lines. It represents a terminal. We've set a draw zone of WIDTH 5 and HEIGHT 3.
We've wrote different character to help you understand the following explanations.
- If you want to draw the operation: r 2.5 1.5 1 1 X (the green rectangle)
-- it means that the character 'D' in the image will be replaced by 'X'
You should find our_micro_paint to help you test yours with some operation_file.example
Hint:
If a point is defined as (Xa, Ya)
And a rectangle with a top left corner (Xtl, Ytl) and a bottom right corner (Xbr, Ybr)
If Xtl <= Xa <= Xbr and Ytl <= Ya <= Ybr then the point is in the rectangle