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
a68eaa55
Commit
a68eaa55
authored
2 years ago
by
Finn Bear
Browse files
Options
Downloads
Patches
Plain Diff
Docs and cleanup.
parent
bfae19f3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cartoon.rs
+7
-12
7 additions, 12 deletions
src/cartoon.rs
src/slide/s4_automata.rs
+2
-0
2 additions, 0 deletions
src/slide/s4_automata.rs
src/slide/s5_fractals.rs
+10
-5
10 additions, 5 deletions
src/slide/s5_fractals.rs
with
19 additions
and
17 deletions
src/cartoon.rs
+
7
−
12
View file @
a68eaa55
...
...
@@ -16,6 +16,8 @@ use eframe::{egui, epi};
/// Top-level state.
pub
struct
Cartoon
{
/// All slides (including their state).
///
/// Note: The slides are dynamically (`dyn`) typed.
slides
:
Vec
<
Box
<
dyn
Slide
>>
,
/// Current index into [`slides`].
slide_index
:
usize
,
...
...
@@ -39,6 +41,8 @@ impl Default for Cartoon {
///
/// This is also how the chronology of the slideshow is determined.
fn
create_slides
()
->
Vec
<
Box
<
dyn
Slide
>>
{
// Slides are dynamically typed, so we use indirection (`Box`) to ensure the collection (`Vec`)
// has items whose sizes are the same and known at compile-time.
vec!
[
Box
::
new
(
Title
::
default
())
as
Box
<
dyn
Slide
>
,
Box
::
new
(
Introduction
::
default
()),
...
...
@@ -98,18 +102,6 @@ impl epi::App for Cartoon {
fn
update
(
&
mut
self
,
ctx
:
&
egui
::
Context
,
_frame
:
&
epi
::
Frame
)
{
// For inspiration and more examples, go to https://emilk.github.io/egui
/*
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
if ui.button("Quit").clicked() {
frame.quit();
}
});
});
});
*/
// Go forward one slide (don't wait for intra-slide transitions).
//
// This will wrap around to the beginning.
...
...
@@ -149,6 +141,9 @@ impl epi::App for Cartoon {
};
}
// The slide gets rendered in here.
// TODO(finnb): Figure out way to fade out old slide and fade in new slide at the same time,
// without breaking everything.
egui
::
CentralPanel
::
default
()
.show
(
ctx
,
|
ui
|
{
// The current slide may be fading in.
fade_in
(
ui
,
self
.transition_time
,
|
ui
|
{
...
...
This diff is collapsed.
Click to expand it.
src/slide/s4_automata.rs
+
2
−
0
View file @
a68eaa55
...
...
@@ -54,9 +54,11 @@ impl Slide for Automata {
// Need to continuously animate the grid, or at least poll the governor.
ui
.ctx
()
.request_repaint
();
// Iterate grid ~5 times a second.
if
self
.governor
.ready
(
ui
.ctx
()
.input
()
.time
,
0.2
)
{
self
.life
=
conways_game_of_life
(
&
self
.life
);
}
self
.life
.show
(
ui
.ctx
());
}
}
...
...
This diff is collapsed.
Click to expand it.
src/slide/s5_fractals.rs
+
10
−
5
View file @
a68eaa55
...
...
@@ -106,7 +106,12 @@ impl Slide for Fractals {
ui
.ctx
()
.request_repaint
();
// The function that will be used to color the grid.
let
algo
:
Box
<
dyn
Fn
(
f32
,
f32
)
->
bool
>
;
//
// It is dynamically typed (so that multiple distinct functions can be used).
//
// Note that we use indirection via a reference but not a heap-allocated [`Box`]. We can get
// away with that since the function doesn't leave our stack frame.
let
algo
:
&
dyn
Fn
(
f32
,
f32
)
->
bool
;
match
self
.state
{
FractalsState
::
Before
=>
{
...
...
@@ -119,19 +124,19 @@ impl Slide for Fractals {
let
alpha
=
(
elapsed
*
2.0
)
.min
(
1.0
)
as
f32
;
self
.code.alpha
=
alpha
;
self
.grid.alpha
=
alpha
;
algo
=
Box
::
new
(
|
_
,
_
|
false
)
;
algo
=
&
|
_
,
_
|
false
;
}
FractalsState
::
Rectangle
{
..
}
=>
{
self
.code.code
=
pseudocode
(
include_str!
(
"s5_fractals/rectangle.rs"
));
algo
=
Box
::
new
(
rectangle
)
;
algo
=
&
rectangle
;
}
FractalsState
::
Circle
{
..
}
=>
{
self
.code.code
=
pseudocode
(
include_str!
(
"s5_fractals/circle.rs"
));
algo
=
Box
::
new
(
circle
)
;
algo
=
&
circle
;
}
FractalsState
::
Mandelbrot
{
..
}
=>
{
self
.code.code
=
pseudocode
(
include_str!
(
"s5_fractals/mandelbrot.rs"
));
algo
=
Box
::
new
(
mandelbrot
)
;
algo
=
&
mandelbrot
;
}
}
...
...
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