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
e30c69b1
Commit
e30c69b1
authored
2 years ago
by
Finn Bear
Browse files
Options
Downloads
Patches
Plain Diff
WIP.
parent
b3f5c6a4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main.rs
+32
-7
32 additions, 7 deletions
src/main.rs
src/slide.rs
+5
-0
5 additions, 0 deletions
src/slide.rs
src/slide/s3_complexity.rs
+71
-8
71 additions, 8 deletions
src/slide/s3_complexity.rs
with
108 additions
and
15 deletions
src/main.rs
+
32
−
7
View file @
e30c69b1
#![feature(derive_default_enum)]
pub
mod
image
;
pub
mod
slide
;
...
...
@@ -43,16 +45,20 @@ pub struct Cartoon {
impl
Default
for
Cartoon
{
fn
default
()
->
Self
{
Self
{
slides
:
vec!
[
Box
::
new
(
Title
::
default
())
as
Box
<
dyn
Slide
>
,
Box
::
new
(
Introduction
::
default
()),
Box
::
new
(
Complexity
::
default
()),
],
slides
:
create_slides
(),
slide_index
:
0
,
}
}
}
fn
create_slides
()
->
Vec
<
Box
<
dyn
Slide
>>
{
vec!
[
Box
::
new
(
Title
::
default
())
as
Box
<
dyn
Slide
>
,
Box
::
new
(
Introduction
::
default
()),
Box
::
new
(
Complexity
::
default
()),
]
}
impl
epi
::
App
for
Cartoon
{
fn
name
(
&
self
)
->
&
str
{
"Generative Art Cartoon"
...
...
@@ -94,8 +100,27 @@ impl epi::App for Cartoon {
});
*/
if
ctx
.input
()
.key_pressed
(
Key
::
Space
)
{
self
.slide_index
=
(
self
.slide_index
+
1
)
%
self
.slides
.len
();
let
advance
=
ctx
.input
()
.key_pressed
(
Key
::
Space
)
||
ctx
.input
()
.key_pressed
(
Key
::
ArrowRight
)
||
ctx
.input
()
.key_pressed
(
Key
::
D
);
let
retreat
=
ctx
.input
()
.key_pressed
(
Key
::
ArrowLeft
)
||
ctx
.input
()
.key_pressed
(
Key
::
A
);
if
advance
||
retreat
{
self
.slide_index
=
if
advance
{
if
self
.slides
[
self
.slide_index
]
.transition
(
ctx
)
{
let
new
=
(
self
.slide_index
+
1
)
%
self
.slides
.len
();
if
new
==
0
{
self
.slides
=
create_slides
();
}
ctx
.request_repaint
();
new
}
else
{
self
.slide_index
}
}
else
{
ctx
.request_repaint
();
self
.slide_index
.saturating_sub
(
1
)
};
}
egui
::
CentralPanel
::
default
()
.show
(
ctx
,
|
ui
|
{
...
...
This diff is collapsed.
Click to expand it.
src/slide.rs
+
5
−
0
View file @
e30c69b1
...
...
@@ -7,4 +7,9 @@ pub mod s3_complexity;
pub
trait
Slide
{
fn
show
(
&
mut
self
,
ui
:
&
mut
Ui
,
ctx
:
&
Context
);
/// Returns whether "done."
/// Repaint automatically requested.
fn
transition
(
&
mut
self
,
ctx
:
&
Context
)
->
bool
{
true
}
}
This diff is collapsed.
Click to expand it.
src/slide/s3_complexity.rs
+
71
−
8
View file @
e30c69b1
...
...
@@ -3,11 +3,33 @@ use crate::{Key, Slide};
use
eframe
::
egui
::
text_edit
::{
CCursorRange
,
CursorRange
,
TextEditState
};
use
eframe
::
egui
::{
Align
,
Align2
,
Frame
,
Layout
,
TextEdit
,
Vec2
};
use
eframe
::
epaint
::
text
::
cursor
::{
CCursor
,
Cursor
};
use
std
::
ops
::
RangeInclusive
;
#[derive(Default)]
pub
struct
Complexity
{}
pub
struct
Complexity
{
state
:
ComplexityState
,
last_time
:
f64
,
}
#[derive(Default,
Eq,
PartialEq,
Debug)]
enum
ComplexityState
{
#[default]
Before
,
Selecting
(
usize
),
Typing
(
usize
),
After
,
}
impl
Slide
for
Complexity
{
fn
transition
(
&
mut
self
,
ctx
:
&
Context
)
->
bool
{
if
self
.state
==
ComplexityState
::
Before
{
self
.state
=
ComplexityState
::
Selecting
(
0
);
false
}
else
{
true
}
}
fn
show
(
&
mut
self
,
ui
:
&
mut
Ui
,
ctx
:
&
Context
)
{
Window
::
new
(
"complexity"
)
.title_bar
(
false
)
...
...
@@ -16,15 +38,56 @@ impl Slide for Complexity {
.anchor
(
Align2
::
CENTER_CENTER
,
Vec2
::
ZERO
)
.fixed_size
(
Vec2
::
new
(
440.0
,
100.0
))
.show
(
ctx
,
|
ui
|
{
ui
.ctx
()
.request_repaint
();
let
time
=
ui
.input
()
.time
;
let
time_delta
=
(
time
-
self
.last_time
)
.min
(
1.0
);
let
made_progress
=
time_delta
>
0.1
;
if
made_progress
{
self
.last_time
=
time
;
}
ui
.vertical_centered_justified
(|
ui
|
{
let
mut
state
=
TextEditState
::
default
();
state
.set_ccursor_range
(
Some
(
CCursorRange
::
two
(
CCursor
::
new
(
0
),
CCursor
::
new
(
7
),
)));
let
text_edit
=
ui
.text_edit_singleline
(
&
mut
"Complex Rules ➡ Complex Results?"
);
text_edit
.request_focus
();
let
text
;
match
&
mut
self
.state
{
ComplexityState
::
Before
=>
{
text
=
String
::
from
(
"Complex Rules ➡ Complex Results?"
);
}
ComplexityState
::
Selecting
(
progress
)
=>
{
text
=
String
::
from
(
"Complex Rules ➡ Complex Results?"
);
state
.set_ccursor_range
(
Some
(
CCursorRange
::
two
(
CCursor
::
new
(
0
),
CCursor
::
new
(
*
progress
),
)));
if
made_progress
{
if
*
progress
==
"Complex"
.len
()
{
self
.state
=
ComplexityState
::
Typing
(
0
);
}
else
{
*
progress
+=
1
;
}
}
}
ComplexityState
::
Typing
(
progress
)
=>
{
text
=
format!
(
" {} Rules ➡ Complex Results?"
,
&
"Simple"
[
0
..*
progress
]);
if
made_progress
{
if
*
progress
==
"Simple"
.len
()
{
self
.state
=
ComplexityState
::
After
;
}
else
{
*
progress
+=
1
;
}
}
}
ComplexityState
::
After
=>
{
text
=
String
::
from
(
" Simple Rules ➡ Complex Results!"
);
}
}
let
text_edit
=
ui
.text_edit_singleline
(
&
mut
text
.as_str
());
if
state
.ccursor_range
()
.is_some
()
{
text_edit
.request_focus
();
}
else
{
text_edit
.surrender_focus
();
}
TextEdit
::
store_state
(
ctx
,
text_edit
.id
,
state
);
});
});
...
...
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