Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
generative_art_cartoon
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Finn Bear
generative_art_cartoon
Commits
04f93587
Commit
04f93587
authored
2 years ago
by
Finn Bear
Browse files
Options
Downloads
Patches
Plain Diff
Basic triangle mosaic.
parent
6d023bad
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/component/triangle.rs
+8
-2
8 additions, 2 deletions
src/component/triangle.rs
src/slide/s8_mosaic.rs
+55
-20
55 additions, 20 deletions
src/slide/s8_mosaic.rs
with
63 additions
and
22 deletions
src/component/triangle.rs
+
8
−
2
View file @
04f93587
...
...
@@ -22,11 +22,17 @@ impl Default for Triangle {
}
impl
Triangle
{
/// Draws the triangle to the ui.
pub
fn
show
(
&
self
,
ui
:
&
mut
Ui
)
{
ui
.painter
()
.add
(
Shape
::
convex_polygon
(
ui
.painter
()
.add
(
self
.shape
());
}
/// Gets the raw shape.
pub
fn
shape
(
&
self
)
->
Shape
{
Shape
::
convex_polygon
(
self
.points
.into
(),
self
.fill
,
Stroke
::
new
(
self
.stroke_width
,
self
.stroke
),
)
);
)
}
}
This diff is collapsed.
Click to expand it.
src/slide/s8_mosaic.rs
+
55
−
20
View file @
04f93587
use
crate
::
color
::
set_alpha
;
use
crate
::
component
::
grid
::
Grid
;
use
crate
::
component
::
image
::{
Image
,
ImagePosition
};
use
crate
::
component
::
triangle
::
Triangle
;
use
crate
::
ctx_img
;
use
crate
::
egui
::{
Color32
,
TextureHandle
,
Ui
,
Vec2
}
;
use
crate
::
egui
::{
TextureHandle
,
Ui
,
Vec2
}
;
use
crate
::
img
;
use
crate
::
slide
::
Slide
;
use
eframe
::
egui
::
style
::
Margin
;
use
eframe
::
egui
::{
Frame
,
Pos2
};
use
eframe
::
egui
::{
ColorImage
,
Frame
,
Pos2
,
Shape
};
use
eframe
::
emath
::
Rot2
;
use
rand
::{
thread_rng
,
Rng
};
#[derive(Default)]
pub
struct
Mosaic
{
squirrel
:
Option
<
TextureHandle
>
,
image
:
ColorImage
,
texture
:
Option
<
TextureHandle
>
,
shapes
:
Vec
<
Shape
>
,
}
impl
Default
for
Mosaic
{
fn
default
()
->
Self
{
Self
{
image
:
img!
(
"squirrel0.png"
),
texture
:
None
,
shapes
:
Vec
::
new
(),
}
}
}
impl
Slide
for
Mosaic
{
...
...
@@ -17,18 +31,6 @@ impl Slide for Mosaic {
// TODO: Finish this slide.
Frame
::
none
()
.margin
(
Margin
::
same
(
20.0
))
.show
(
ui
,
|
ui
|
{
ui
.heading
(
"Generative Image Processing"
);
Triangle
{
points
:
[
Pos2
::
new
(
200.0
,
150.0
),
Pos2
::
new
(
500.0
,
220.0
),
Pos2
::
new
(
300.0
,
400.0
),
],
stroke_width
:
0.0
,
fill
:
Color32
::
RED
,
..
Triangle
::
default
()
}
.show
(
ui
)
});
Image
::
default
()
...
...
@@ -37,8 +39,9 @@ impl Slide for Mosaic {
.margin
(
16.0
)
.show
(
ui
,
self
.squirrel
.get_or_insert_with
(||
ctx_img!
(
ui
.ctx
(),
"squirrel0.png"
)),
self
.texture
.get_or_insert_with
(||
{
ui
.ctx
()
.load_texture
(
"squirrel0.png"
,
self
.image
.clone
())
}),
);
Grid
{
...
...
@@ -47,6 +50,38 @@ impl Slide for Mosaic {
offset_x
:
300.0
,
..
Grid
::
default
()
}
.show
(
ui
.ctx
());
.show_with_overlays
(
ui
.ctx
(),
|
ui
,
to_screen
|
{
ui
.ctx
()
.request_repaint
();
let
mut
rng
=
thread_rng
();
for
_
in
0
..
50
{
let
x
:
f32
=
rng
.gen
();
let
y
:
f32
=
rng
.gen
();
let
size
:
f32
=
rng
.gen
::
<
f32
>
()
*
0.025
;
let
rot
=
Rot2
::
from_angle
(
rng
.gen
::
<
f32
>
()
*
std
::
f32
::
consts
::
TAU
);
let
center
=
Pos2
::
new
(
x
,
y
);
let
image_x
=
((
x
*
self
.image
.width
()
as
f32
)
as
usize
)
.min
(
self
.image
.width
()
-
1
);
let
image_y
=
((
y
*
self
.image
.height
()
as
f32
)
as
usize
)
.min
(
self
.image
.height
()
-
1
);
self
.shapes
.push
(
Triangle
{
points
:
[
to_screen
*
(
center
+
rot
*
Vec2
::
new
(
-
1.0
,
-
1.0
)
*
size
),
to_screen
*
(
center
+
rot
*
Vec2
::
new
(
1.0
,
-
1.0
)
*
size
),
to_screen
*
(
center
+
rot
*
Vec2
::
new
(
-
1.0
,
1.0
)
*
size
),
],
stroke_width
:
0.0
,
fill
:
set_alpha
(
self
.image
[(
image_x
,
image_y
)],
0.2
),
..
Triangle
::
default
()
}
.shape
(),
);
}
ui
.painter
()
.extend
(
self
.shapes
.clone
());
});
}
}
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