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
d553505d
Commit
d553505d
authored
2 years ago
by
Finn Bear
Browse files
Options
Downloads
Patches
Plain Diff
Conway progress.
parent
51c5f2f8
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/image.rs
+1
-1
1 addition, 1 deletion
src/image.rs
src/image/conway_portrait.png
+0
-0
0 additions, 0 deletions
src/image/conway_portrait.png
src/slide/s1_title.rs
+3
-4
3 additions, 4 deletions
src/slide/s1_title.rs
src/slide/s4_automata.rs
+59
-6
59 additions, 6 deletions
src/slide/s4_automata.rs
with
63 additions
and
11 deletions
src/image.rs
+
1
−
1
View file @
d553505d
...
...
@@ -15,7 +15,7 @@ macro_rules! img {
#[macro_export]
macro_rules!
ctx_img
{
(
$ctx
:
expr
,
$name
:
literal
)
=>
{{
$ctx
.load_texture
(
$name
,
img!
(
$name
))
$ctx
.load_texture
(
$name
,
crate
::
img!
(
$name
))
}};
}
...
...
This diff is collapsed.
Click to expand it.
src/image/conway_portrait.png
0 → 100644
+
0
−
0
View file @
d553505d
57.4 KiB
This diff is collapsed.
Click to expand it.
src/slide/s1_title.rs
+
3
−
4
View file @
d553505d
use
crate
::
egui
::
Align2
;
use
crate
::
slide
::
Slide
;
use
crate
::{
ctx_img
,
img
,
Margin
};
use
eframe
::
egui
;
use
eframe
::
egui
::{
Frame
,
Ui
,
Vec2
,
Window
};
use
crate
::{
ctx_img
,
Margin
};
use
eframe
::
egui
::{
Frame
,
TextureHandle
,
Ui
,
Vec2
,
Window
};
/// The first slide in the cartoon.
#[derive(Default)]
pub
struct
Title
{
examples
:
Vec
<
egui
::
TextureHandle
>
,
examples
:
Vec
<
TextureHandle
>
,
}
impl
Slide
for
Title
{
...
...
This diff is collapsed.
Click to expand it.
src/slide/s4_automata.rs
+
59
−
6
View file @
d553505d
use
crate
::
color
::
set_alpha
;
use
crate
::
component
::
arrow
::
Arrow
;
use
crate
::
component
::
grid
::
Grid
;
use
crate
::
egui
::
Context
;
use
crate
::
fade_in
::
fade_in_manual
;
use
crate
::
ctx_img
;
use
crate
::
egui
::{
Align2
,
Context
,
TextureHandle
,
Vec2
,
Window
};
use
crate
::
fade_in
::{
fade_in
,
fade_in_manual
};
use
crate
::
governor
::
Governor
;
use
crate
::
slide
::
Slide
;
use
eframe
::
egui
::
style
::
Margin
;
...
...
@@ -18,6 +19,8 @@ pub struct Automata {
state
:
AutomataState
,
/// For knowing when to advance the simulation.
governor
:
Governor
,
/// John Conway portrait, loaded lazily.
conway_portrait
:
Option
<
TextureHandle
>
,
}
#[derive(Default)]
...
...
@@ -31,6 +34,8 @@ enum AutomataState {
alive
:
Option
<
f64
>
,
/// When started fading in "alive" arrow.
dead
:
Option
<
f64
>
,
/// When rules started fading in.
rules
:
Option
<
f64
>
,
},
/// Simulation.
Life
,
...
...
@@ -65,6 +70,7 @@ impl Default for Automata {
life
,
state
:
AutomataState
::
default
(),
governor
:
Governor
::
default
(),
conway_portrait
:
None
,
}
}
}
...
...
@@ -76,6 +82,7 @@ impl Slide for Automata {
self
.state
=
AutomataState
::
Static
{
alive
:
None
,
dead
:
None
,
rules
:
None
,
};
let
mut
rng
=
ChaCha8Rng
::
seed_from_u64
(
123456789876543216
);
...
...
@@ -89,12 +96,14 @@ impl Slide for Automata {
}
}
}
AutomataState
::
Static
{
alive
,
dead
}
=>
{
// Enable arrows one by one.
AutomataState
::
Static
{
alive
,
dead
,
rules
}
=>
{
// Enable arrows
/text
one by one.
if
alive
.is_none
()
{
*
alive
=
Some
(
ctx
.input
()
.time
);
}
else
if
dead
.is_none
()
{
*
dead
=
Some
(
ctx
.input
()
.time
);
}
else
if
rules
.is_none
()
{
*
rules
=
Some
(
ctx
.input
()
.time
)
}
else
{
self
.state
=
AutomataState
::
Life
;
}
...
...
@@ -111,22 +120,66 @@ impl Slide for Automata {
});
});
// TODO: Fade/move/position as appropriate.
Window
::
new
(
"portrait"
)
.title_bar
(
false
)
.resizable
(
false
)
.frame
(
Frame
::
window
(
&
ui
.style
())
.margin
(
Margin
::
same
(
5.0
)))
.show
(
ui
.ctx
(),
|
ui
|
{
ui
.image
(
self
.conway_portrait
.get_or_insert_with
(||
ctx_img!
(
ui
.ctx
(),
"conway_portrait.png"
)),
Vec2
::
splat
(
128.0
),
);
});
// Need to continuously animate the grid, or at least poll the governor.
ui
.ctx
()
.request_repaint
();
// If [`None`], don't show rules. If [`Some`], fade in rules as if they started fading in
// at this time.
let
mut
rules_fade
:
Option
<
f64
>
=
None
;
// How much grid goes left and rules go right.
const
HORIZONTAL_OFFSET
:
f32
=
250.0
;
match
&
self
.state
{
AutomataState
::
Empty
=>
{}
AutomataState
::
Static
{
..
}
=>
{}
AutomataState
::
Static
{
rules
,
..
}
=>
{
if
let
&
Some
(
rules
)
=
rules
{
let
elapsed
=
ui
.ctx
()
.input
()
.time
-
rules
;
self
.life.offset_x
=
(
elapsed
as
f32
*
-
400.0
)
.max
(
-
HORIZONTAL_OFFSET
);
rules_fade
=
Some
(
rules
);
}
}
AutomataState
::
Life
=>
{
// Iterate grid ~5 times a second.
if
self
.governor
.ready
(
ui
.ctx
()
.input
()
.time
,
0.2
)
{
self
.life
=
conways_game_of_life
(
&
self
.life
);
}
// Kludge to render rules with full opacity.
rules_fade
=
Some
(
0.0
);
}
}
if
let
Some
(
rules_fade
)
=
rules_fade
{
fade_in
(
ui
,
rules_fade
,
|
ui
|
{
Window
::
new
(
"conway_rules"
)
.frame
(
Frame
::
window
(
&
ui
.ctx
()
.style
()))
.anchor
(
Align2
::
CENTER_CENTER
,
Vec2
::
new
(
HORIZONTAL_OFFSET
,
0.0
))
.title_bar
(
false
)
.resizable
(
false
)
.show
(
ui
.ctx
(),
|
ui
|
{
ui
.label
(
" ⏵ Cells with fewer than two neighbors die"
);
ui
.label
(
" ⏵ Cells with more than three neighbors die"
);
ui
.label
(
" ⏵ Cells with three neighbors become alive"
);
});
});
}
self
.life
.show_with_overlays
(
ui
.ctx
(),
|
ui
,
to_screen
|
{
if
let
&
AutomataState
::
Static
{
alive
,
dead
}
=
&
self
.state
{
if
let
&
AutomataState
::
Static
{
alive
,
dead
,
..
}
=
&
self
.state
{
if
let
Some
(
alive
)
=
alive
{
fade_in_manual
(
ui
,
alive
,
|
ui
,
alpha
|
{
let
color
=
set_alpha
(
Color32
::
GREEN
,
alpha
);
...
...
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