Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libsimple_graphical
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
We are moving to Forgejo!
You are on a read-only GitLab instance.
Show more breadcrumbs
namark
libsimple_graphical
Commits
12f8ce39
Commit
12f8ce39
authored
6 years ago
by
namark
Browse files
Options
Downloads
Patches
Plain Diff
Improvements in example 13_draw_line.
parent
08f807fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/13_draw_line.cpp
+10
-8
10 additions, 8 deletions
examples/13_draw_line.cpp
with
10 additions
and
8 deletions
examples/13_draw_line.cpp
+
10
−
8
View file @
12f8ce39
...
...
@@ -12,6 +12,7 @@ using namespace simple::graphical;
using
namespace
color_literals
;
using
namespace
std
::
chrono_literals
;
using
simple
::
geom
::
vector
;
using
simple
::
support
::
min_element
;
using
rgb_pixels
=
pixel_writer
<
rgb_pixel
,
surface
::
byte
>
;
const
auto
tau
=
2
*
std
::
acos
(
-
1
);
...
...
@@ -41,9 +42,10 @@ int main(int argc, char const* argv[]) try
surface
canvas
(
logical_size
,
pixel_format
(
pixel_format
::
type
::
rgb24
));
auto
pixels
=
std
::
get
<
rgb_pixels
>
(
canvas
.
pixels
());
const
int
half_size
=
min_element
(
win
.
size
())
/
2
-
1
;
// -1 becaus we set the enpoints
const
float
offset
=
tau
/
10
;
const
float
radius
=
199
/
zoom
;
const
auto
position
=
float2
::
one
(
199
)
/
zoom
;
const
float
radius
=
half_size
/
zoom
;
const
auto
position
=
float2
::
one
(
half_size
)
/
zoom
;
const
auto
color
=
0xffffff
_rgb
;
for
(
float
i
=
0
;
i
<
tau
;
i
+=
tau
*
0.001
f
)
{
...
...
@@ -62,10 +64,10 @@ int main(int argc, char const* argv[]) try
floating_vector_line
({
position
+
from_angle
(
angle
)
*
radius
/
2
,
position
+
from_angle
(
angle
)
*
radius
},
pixels
,
color
);
angle
-=
offset
;
bresenham_line
({
int2
(
floor
(
position
+
from_angle
(
angle
)
*
radius
/
2
)),
int2
(
floor
(
position
+
from_angle
(
angle
)
*
radius
))},
pixels
,
color
);
bresenham_line
({
int2
(
round
(
position
+
from_angle
(
angle
)
*
radius
/
2
)),
int2
(
round
(
position
+
from_angle
(
angle
)
*
radius
))},
pixels
,
color
);
angle
-=
offset
;
xiaolin_wu_line
({
int2
(
floor
(
position
+
from_angle
(
angle
)
*
radius
/
2
)),
int2
(
floor
(
position
+
from_angle
(
angle
)
*
radius
))},
pixels
,
color
);
xiaolin_wu_line
({
int2
(
round
(
position
+
from_angle
(
angle
)
*
radius
/
2
)),
int2
(
round
(
position
+
from_angle
(
angle
)
*
radius
))},
pixels
,
color
);
blit
(
canvas
,
win
.
surface
(),
rect
{
win
.
surface
().
size
()});
...
...
@@ -132,18 +134,18 @@ void integer_vector_line(const line<float2>& line, rgb_pixels pixels, rgb_pixel
setter
(
vector_line
(
line
,
setter
).
end
());
}
void
bresenham_line
(
line
<
int2
>
l
,
rgb_pixels
pixels
,
rgb_pixel
value
)
void
bresenham_line
(
line
<
int2
>
l
ine
,
rgb_pixels
pixels
,
rgb_pixel
value
)
{
bresenham_line
(
l
,
[
&
pixels
,
&
value
](
int2
position
)
bresenham_line
(
l
ine
,
[
&
pixels
,
&
value
](
int2
position
)
{
pixels
.
set
(
value
,
position
);
});
}
void
xiaolin_wu_line
(
line
<
int2
>
l
,
rgb_pixels
pixels
,
rgb_pixel
value
)
void
xiaolin_wu_line
(
line
<
int2
>
l
ine
,
rgb_pixels
pixels
,
rgb_pixel
value
)
{
using
rational
=
rational
<
int
>
;
bresenham_line
(
l
,
[
&
pixels
,
&
value
](
int2
position
,
rational
ratio
)
bresenham_line
(
l
ine
,
[
&
pixels
,
&
value
](
int2
position
,
rational
ratio
)
{
const
auto
blended
=
value
.
mutant_clone
([
&
ratio
](
auto
coord
)
{
return
rgb_pixel
::
coordinate_type
((
int
)
coord
*
ratio
);
});
...
...
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