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
92a715df
Commit
92a715df
authored
2 years ago
by
Finn Bear
Browse files
Options
Downloads
Patches
Plain Diff
Grid.
parent
03f17a99
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/component.rs
+1
-0
1 addition, 0 deletions
src/component.rs
src/component/grid.rs
+64
-0
64 additions, 0 deletions
src/component/grid.rs
src/main.rs
+1
-0
1 addition, 0 deletions
src/main.rs
src/slide/s4_conway.rs
+6
-42
6 additions, 42 deletions
src/slide/s4_conway.rs
with
72 additions
and
42 deletions
src/component.rs
0 → 100644
+
1
−
0
View file @
92a715df
pub
mod
grid
;
This diff is collapsed.
Click to expand it.
src/component/grid.rs
0 → 100644
+
64
−
0
View file @
92a715df
use
eframe
::
egui
::{
Align2
,
Color32
,
Context
,
Pos2
,
Rect
,
Shape
,
Stroke
,
Ui
,
Vec2
,
Window
};
use
eframe
::
emath
;
pub
struct
Grid
{
name
:
&
'static
str
,
offset_x
:
f32
,
offset_y
:
f32
,
size_cells
:
usize
,
size_pixels
:
f32
,
stroke
:
Color32
,
}
impl
Default
for
Grid
{
fn
default
()
->
Self
{
Self
{
name
:
"grid"
,
offset_x
:
0.0
,
offset_y
:
0.0
,
size_cells
:
16
,
size_pixels
:
400.0
,
stroke
:
Color32
::
GRAY
,
}
}
}
impl
Grid
{
pub
fn
show
(
&
self
,
ctx
:
&
Context
)
{
Window
::
new
(
self
.name
)
.title_bar
(
false
)
//.frame(Frame::none())
.anchor
(
Align2
::
CENTER_CENTER
,
Vec2
::
ZERO
)
.fixed_size
(
Vec2
::
splat
(
self
.size_pixels
))
.show
(
ctx
,
|
ui
|
{
let
(
_id
,
rect
)
=
ui
.allocate_space
(
Vec2
::
splat
(
self
.size_pixels
));
let
to_screen
=
emath
::
RectTransform
::
from_to
(
Rect
::
from_x_y_ranges
(
0.0
..=
1.0
,
0.0
..=
1.0
),
rect
,
);
for
c
in
0
..=
self
.size_cells
{
let
coord
=
c
as
f32
/
self
.size_cells
as
f32
;
// Horizontal.
ui
.painter
()
.add
(
Shape
::
LineSegment
{
points
:
[
to_screen
*
Pos2
::
new
(
0.0
,
coord
),
to_screen
*
Pos2
::
new
(
1.0
,
coord
),
],
stroke
:
Stroke
::
new
(
1.0
,
self
.stroke
),
});
// Vertical.
ui
.painter
()
.add
(
Shape
::
LineSegment
{
points
:
[
to_screen
*
Pos2
::
new
(
coord
,
0.0
),
to_screen
*
Pos2
::
new
(
coord
,
1.0
),
],
stroke
:
Stroke
::
new
(
1.0
,
self
.stroke
),
});
}
for
x
in
0
..=
self
.size_cells
{
for
y
in
0
..=
self
.size_cells
{}
}
});
}
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
1
−
0
View file @
92a715df
#![feature(derive_default_enum)]
pub
mod
component
;
pub
mod
image
;
pub
mod
slide
;
...
...
This diff is collapsed.
Click to expand it.
src/slide/s4_conway.rs
+
6
−
42
View file @
92a715df
use
crate
::
component
::
grid
::
Grid
;
use
crate
::
Slide
;
use
eframe
::
egui
::{
Align2
,
Color32
,
Context
,
Frame
,
Grid
,
Pos2
,
Rect
,
Shape
,
Stroke
,
Ui
,
Vec2
,
Window
,
};
use
eframe
::
egui
::{
Align2
,
Color32
,
Context
,
Frame
,
Pos2
,
Rect
,
Shape
,
Stroke
,
Ui
,
Vec2
,
Window
};
use
eframe
::
emath
;
#[derive(Default)]
pub
struct
Conway
{}
pub
struct
Conway
{
life
:
Grid
,
}
impl
Slide
for
Conway
{
fn
show
(
&
mut
self
,
ui
:
&
mut
Ui
,
ctx
:
&
Context
)
{
let
PIXELS
:
f32
=
400.0
;
let
CELLS
:
usize
=
32
;
Window
::
new
(
"conway"
)
.title_bar
(
false
)
//.frame(Frame::none())
.anchor
(
Align2
::
CENTER_CENTER
,
Vec2
::
ZERO
)
.fixed_size
(
Vec2
::
splat
(
PIXELS
))
.show
(
ctx
,
|
ui
|
{
let
(
_id
,
rect
)
=
ui
.allocate_space
(
Vec2
::
splat
(
PIXELS
));
let
to_screen
=
emath
::
RectTransform
::
from_to
(
Rect
::
from_x_y_ranges
(
0.0
..=
1.0
,
0.0
..=
1.0
),
rect
,
);
for
c
in
0
..=
CELLS
{
let
coord
=
c
as
f32
/
CELLS
as
f32
;
// Horizontal.
ui
.painter
()
.add
(
Shape
::
LineSegment
{
points
:
[
to_screen
*
Pos2
::
new
(
0.0
,
coord
),
to_screen
*
Pos2
::
new
(
1.0
,
coord
),
],
stroke
:
Stroke
::
new
(
1.0
,
Color32
::
BLACK
),
});
// Vertical.
ui
.painter
()
.add
(
Shape
::
LineSegment
{
points
:
[
to_screen
*
Pos2
::
new
(
coord
,
0.0
),
to_screen
*
Pos2
::
new
(
coord
,
1.0
),
],
stroke
:
Stroke
::
new
(
1.0
,
Color32
::
GRAY
),
});
}
for
x
in
0
..=
CELLS
{
for
y
in
0
..=
CELLS
{}
}
});
self
.life
.show
(
ctx
);
}
}
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