Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton Ahrens
hp
Commits
481c9891
Commit
481c9891
authored
Feb 5, 2018
by
Peter Gerwinski
Browse files
Options
Downloads
Patches
Plain Diff
Beispielprogramme 5.2.2018
parent
6ac649ea
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
20180205/test-textgraph.c
+48
-0
48 additions, 0 deletions
20180205/test-textgraph.c
20180205/textgraph.c
+154
-0
154 additions, 0 deletions
20180205/textgraph.c
20180205/textgraph.h
+32
-0
32 additions, 0 deletions
20180205/textgraph.h
with
234 additions
and
0 deletions
20180205/test-textgraph.c
0 → 100644
+
48
−
0
View file @
481c9891
#include
<stdio.h>
#include
<unistd.h>
#include
"textgraph.h"
void
draw_smiley
(
void
)
{
clear
(
' '
);
put_point
(
-
5
,
10
,
'X'
);
for
(
int
i
=
16
;
i
<
24
;
i
++
)
put_point
(
i
,
5
,
'*'
);
put_point
(
15
,
6
,
'*'
);
put_point
(
14
,
7
,
'*'
);
put_point
(
13
,
8
,
'*'
);
put_point
(
13
,
9
,
'*'
);
put_point
(
14
,
10
,
'*'
);
put_point
(
15
,
11
,
'*'
);
for
(
int
i
=
16
;
i
<
24
;
i
++
)
put_point
(
i
,
12
,
'*'
);
put_point
(
24
,
11
,
'*'
);
put_point
(
25
,
10
,
'*'
);
put_point
(
26
,
9
,
'*'
);
put_point
(
26
,
8
,
'*'
);
put_point
(
25
,
7
,
'*'
);
put_point
(
24
,
6
,
'*'
);
put_point
(
18
,
8
,
'O'
);
put_point
(
21
,
8
,
'O'
);
put_point
(
17
,
10
,
'`'
);
for
(
int
i
=
18
;
i
<
22
;
i
++
)
put_point
(
i
,
10
,
'-'
);
put_point
(
22
,
10
,
'\''
);
put_point
(
13
,
42
,
'Y'
);
printf
(
"get_point (%d, %d): '%c'
\n
"
,
13
,
9
,
get_point
(
13
,
9
));
printf
(
"get_point (%d, %d): '%c'
\n
"
,
14
,
9
,
get_point
(
14
,
9
));
printf
(
"get_point (%d, %d): '%c'
\n
"
,
94
,
9
,
get_point
(
94
,
9
));
}
int
main
(
void
)
{
draw_smiley
();
fill_animated
(
21
,
7
,
'.'
,
' '
);
sleep
(
5
);
draw_smiley
();
fill_stack
(
21
,
7
,
'.'
,
' '
);
sleep
(
5
);
draw_smiley
();
fill_fifo
(
21
,
7
,
'.'
,
' '
);
return
0
;
}
This diff is collapsed.
Click to expand it.
20180205/textgraph.c
0 → 100644
+
154
−
0
View file @
481c9891
#include
<stdio.h>
#include
<unistd.h>
#include
"textgraph.h"
char
buffer
[
HEIGHT
][
WIDTH
];
void
clear
(
char
c
)
{
for
(
int
y
=
0
;
y
<
HEIGHT
;
y
++
)
for
(
int
x
=
0
;
x
<
WIDTH
;
x
++
)
buffer
[
y
][
x
]
=
c
;
}
static
int
check_coordinates
(
int
x
,
int
y
,
char
*
function
)
{
if
(
x
>=
0
&&
x
<
WIDTH
&&
y
>=
0
&&
y
<
HEIGHT
)
return
1
;
else
{
fprintf
(
stderr
,
"coordinates (%d,%d) out of range in %s
\n
"
,
x
,
y
,
function
);
return
0
;
}
}
void
put_point
(
int
x
,
int
y
,
char
c
)
{
if
(
check_coordinates
(
x
,
y
,
"put_point"
))
buffer
[
y
][
x
]
=
c
;
}
char
get_point
(
int
x
,
int
y
)
{
if
(
check_coordinates
(
x
,
y
,
"get_point"
))
return
buffer
[
y
][
x
];
else
return
0
;
}
void
fill
(
int
x
,
int
y
,
char
c
,
char
o
)
{
if
(
get_point
(
x
,
y
)
==
o
)
{
put_point
(
x
,
y
,
c
);
fill
(
x
-
1
,
y
,
c
,
o
);
fill
(
x
+
1
,
y
,
c
,
o
);
fill
(
x
,
y
-
1
,
c
,
o
);
fill
(
x
,
y
+
1
,
c
,
o
);
}
}
void
display
(
void
)
{
for
(
int
y
=
0
;
y
<
HEIGHT
;
y
++
)
{
for
(
int
x
=
0
;
x
<
WIDTH
;
x
++
)
printf
(
"%c"
,
buffer
[
y
][
x
]);
printf
(
"
\n
"
);
}
}
void
clear_display
(
void
)
{
printf
(
"\e[H\e[J"
);
}
void
fill_animated
(
int
x
,
int
y
,
char
c
,
char
o
)
{
if
(
get_point
(
x
,
y
)
==
o
)
{
put_point
(
x
,
y
,
c
);
clear_display
();
display
();
usleep
(
200000
);
fill_animated
(
x
-
1
,
y
,
c
,
o
);
fill_animated
(
x
+
1
,
y
,
c
,
o
);
fill_animated
(
x
,
y
-
1
,
c
,
o
);
fill_animated
(
x
,
y
+
1
,
c
,
o
);
}
}
pair
stack
[
STACK_SIZE
];
int
stack_pointer
=
0
;
void
stack_push
(
int
x
,
int
y
)
{
stack
[
stack_pointer
].
x
=
x
;
stack
[
stack_pointer
].
y
=
y
;
stack_pointer
++
;
}
void
stack_pop
(
int
*
x
,
int
*
y
)
{
stack_pointer
--
;
*
x
=
stack
[
stack_pointer
].
x
;
*
y
=
stack
[
stack_pointer
].
y
;
}
void
fill_stack
(
int
x
,
int
y
,
char
c
,
char
o
)
{
stack_push
(
x
,
y
);
while
(
stack_pointer
>
0
)
{
stack_pop
(
&
x
,
&
y
);
if
(
get_point
(
x
,
y
)
==
o
)
{
put_point
(
x
,
y
,
c
);
clear_display
();
display
();
usleep
(
200000
);
stack_push
(
x
,
y
+
1
);
stack_push
(
x
,
y
-
1
);
stack_push
(
x
+
1
,
y
);
stack_push
(
x
-
1
,
y
);
}
}
}
pair
fifo
[
FIFO_SIZE
];
int
fifo_read
=
0
;
int
fifo_write
=
0
;
void
fifo_push
(
int
x
,
int
y
)
{
fifo
[
fifo_write
].
x
=
x
;
fifo
[
fifo_write
].
y
=
y
;
fifo_write
=
(
fifo_write
+
1
)
%
FIFO_SIZE
;
}
void
fifo_pop
(
int
*
x
,
int
*
y
)
{
*
x
=
fifo
[
fifo_read
].
x
;
*
y
=
fifo
[
fifo_read
].
y
;
fifo_read
=
(
fifo_read
+
1
)
%
FIFO_SIZE
;
}
void
fill_fifo
(
int
x
,
int
y
,
char
c
,
char
o
)
{
fifo_push
(
x
,
y
);
while
(
fifo_write
!=
fifo_read
)
{
fifo_pop
(
&
x
,
&
y
);
if
(
get_point
(
x
,
y
)
==
o
)
{
put_point
(
x
,
y
,
c
);
clear_display
();
display
();
usleep
(
200000
);
fifo_push
(
x
,
y
+
1
);
fifo_push
(
x
,
y
-
1
);
fifo_push
(
x
+
1
,
y
);
fifo_push
(
x
-
1
,
y
);
}
}
}
This diff is collapsed.
Click to expand it.
20180205/textgraph.h
0 → 100644
+
32
−
0
View file @
481c9891
#ifndef TEXTGRAPH_H
#define TEXTGRAPH_H
#define WIDTH 40
#define HEIGHT 20
#define STACK_SIZE 100
#define FIFO_SIZE 100
typedef
struct
{
int
x
,
y
;
}
pair
;
extern
void
clear
(
char
c
);
extern
void
put_point
(
int
x
,
int
y
,
char
c
);
extern
char
get_point
(
int
x
,
int
y
);
extern
void
fill
(
int
x
,
int
y
,
char
c
,
char
o
);
extern
void
display
(
void
);
extern
void
clear_display
(
void
);
extern
void
fill_animated
(
int
x
,
int
y
,
char
c
,
char
o
);
extern
void
stack_push
(
int
x
,
int
y
);
extern
void
stack_pop
(
int
*
x
,
int
*
y
);
extern
void
fill_stack
(
int
x
,
int
y
,
char
c
,
char
o
);
extern
void
fifo_push
(
int
x
,
int
y
);
extern
void
fifo_pop
(
int
*
x
,
int
*
y
);
extern
void
fill_fifo
(
int
x
,
int
y
,
char
c
,
char
o
);
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment