Skip to content

Commit 43bd0dd

Browse files
committed
upgrade to use macroquad over ggez
1 parent 31f6d6c commit 43bd0dd

File tree

12 files changed

+568
-3200
lines changed

12 files changed

+568
-3200
lines changed

Cargo.lock

Lines changed: 396 additions & 2839 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[package]
22
name = "vector_field_visualization"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Zelda Hessler <[email protected]>"]
5-
edition = "2018"
5+
edition = "2024"
66

77
[profile.release]
88
lto = "thin"
99

1010
[dependencies]
1111
chrono = "0.4.19"
1212
dotenv = "0.15.0"
13-
env_logger = "0.9.0"
14-
ggez = "0.6.0-rc2"
13+
env_logger = "0.11.8"
1514
log = "0.4.14"
16-
noise = "0.7.0"
17-
rand = "0.8.4"
18-
svg = "0.10.0"
15+
noise = "0.9.0"
16+
rand = "0.9.0"
17+
svg = "0.18.0"
18+
macroquad = "0.4.14"

src/circles.rs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
use crate::{
22
consts::{
3-
CIRCLE_TOLERANCE, GRID_CELL_H, GRID_CELL_W, GRID_SIZE_X, GRID_SIZE_Y, SCREEN_H, SCREEN_W,
4-
VECTOR_SCALE, VECTOR_WIDTH,
3+
GRID_CELL_H, GRID_CELL_W, GRID_SIZE_X, GRID_SIZE_Y, SCREEN_H, SCREEN_W, VECTOR_SCALE,
54
},
65
visualizer::{Visualizer, VisualizerParams},
76
};
8-
use ggez::{
9-
graphics::{Color, DrawMode, Mesh, MeshBuilder},
10-
Context,
11-
};
127
use log::info;
8+
use macroquad::prelude::*;
139
use svg::node::element;
1410

1511
type Point2<T> = [T; 2];
@@ -91,31 +87,10 @@ impl Visualizer for Circles {
9187
}
9288
}
9389

94-
fn build_mesh(&self, ctx: &mut Context) -> Option<Mesh> {
95-
let mut circle_mesh_builder = MeshBuilder::new();
96-
let color = Color::new(1.0, 1.0, 1.0, 1.0);
97-
98-
for circle in self.circles.iter() {
99-
let [x, y] = circle.location;
100-
101-
circle_mesh_builder
102-
.circle(
103-
DrawMode::stroke(VECTOR_WIDTH as f32),
104-
[x as f32, y as f32],
105-
circle.radius as f32,
106-
CIRCLE_TOLERANCE,
107-
color,
108-
)
109-
.unwrap();
110-
}
111-
112-
circle_mesh_builder.build(ctx).ok()
113-
}
114-
11590
fn build_svg_document_from_state(&self) -> svg::Document {
11691
let doc = svg::Document::new().set("viewBox", (0, 0, SCREEN_W, SCREEN_H));
11792

118-
let mut group = svg::node::element::Group::new()
93+
let mut group = element::Group::new()
11994
.set("fill", "none")
12095
.set("stroke", "black")
12196
.set("stroke-width", "0.3mm");
@@ -132,7 +107,7 @@ impl Visualizer for Circles {
132107
group = group.add(path);
133108
}
134109

135-
let bounding_rect = svg::node::element::Rectangle::new()
110+
let bounding_rect = element::Rectangle::new()
136111
.set("width", SCREEN_W)
137112
.set("height", SCREEN_H)
138113
.set("fill", "none")
@@ -141,4 +116,12 @@ impl Visualizer for Circles {
141116

142117
doc.add(group).add(bounding_rect)
143118
}
119+
120+
fn render(&self) {
121+
for circle in self.circles.iter() {
122+
let [x, y] = circle.location;
123+
124+
draw_circle(x as f32, y as f32, circle.radius as f32, WHITE);
125+
}
126+
}
144127
}

src/consts.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ pub const GRID_SIZE_X: usize = 96;
44
pub const GRID_SIZE_Y: usize = 60;
55
pub const VECTOR_SCALE: f64 = 20.0;
66
pub const VECTOR_WIDTH: f64 = 2.0;
7-
pub const CIRCLE_TOLERANCE: f32 = 1.0;
87

9-
pub const DEFAULT_MOVE_SPEED: f64 = 0.05;
10-
pub const DEFAULT_NOISE_SCALE: f64 = 0.01;
11-
pub const DEFAULT_NOISE_SCALE_INCREMENT: f64 = DEFAULT_NOISE_SCALE * 0.2;
12-
pub const DEFAULT_NOISE_SPEED: f64 = 0.00001;
13-
pub const DEFAULT_NOISE_SPEED_INCREMENT: f64 = DEFAULT_NOISE_SPEED * 0.2;
8+
pub const DEFAULT_MOVE_SPEED: f64 = 0.001;
9+
pub const DEFAULT_NOISE_SCALE: f64 = 0.001;
10+
pub const DEFAULT_NOISE_SCALE_INCREMENT: f64 = DEFAULT_NOISE_SCALE * 0.01;
11+
pub const DEFAULT_NOISE_SPEED: f64 = 0.000005;
12+
pub const DEFAULT_NOISE_SPEED_INCREMENT: f64 = DEFAULT_NOISE_SPEED * 0.01;
1413

1514
pub const SCREEN_W: usize = 1920;
1615
pub const SCREEN_H: usize = 1080;

src/counter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ pub struct Counter {
55
}
66

77
impl Counter {
8+
/// Creates a new Counter with the given minimum and maximum values.
89
pub fn new(min: usize, max: usize) -> Self {
910
assert!(min <= max);
1011

1112
Counter { count: 0, min, max }
1213
}
1314

15+
/// Get the current count.
1416
pub fn count(&self) -> usize {
1517
self.count
1618
}

src/letters.rs

Lines changed: 0 additions & 144 deletions
This file was deleted.

src/line_segments.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ use crate::{
55
},
66
visualizer::{Visualizer, VisualizerParams},
77
};
8-
use ggez::{
9-
graphics::{Color, Mesh, MeshBuilder},
10-
Context,
11-
};
128
use log::info;
139
use std::f64::consts::TAU;
1410
use svg::node::element;
11+
use macroquad::prelude::*;
1512

1613
type Point2<T> = [T; 2];
1714

@@ -93,26 +90,10 @@ impl Visualizer for LineSegments {
9390
}
9491
}
9592

96-
fn build_mesh(&self, ctx: &mut Context) -> Option<Mesh> {
97-
let mut line_mesh_builder = MeshBuilder::new();
98-
let color = Color::new(1.0, 1.0, 1.0, 1.0);
99-
100-
for line_segment in self.line_segments.iter() {
101-
let [[x1, y1], [x2, y2]] = line_segment.points;
102-
let points = [[x1 as f32, y1 as f32], [x2 as f32, y2 as f32]];
103-
104-
line_mesh_builder
105-
.line(&points, VECTOR_WIDTH as f32, color)
106-
.unwrap();
107-
}
108-
109-
line_mesh_builder.build(ctx).ok()
110-
}
111-
11293
fn build_svg_document_from_state(&self) -> svg::Document {
11394
let doc = svg::Document::new().set("viewBox", (0, 0, SCREEN_W, SCREEN_H));
11495

115-
let mut group = svg::node::element::Group::new()
96+
let mut group = element::Group::new()
11697
.set("fill", "none")
11798
.set("stroke", "black")
11899
.set("stroke-width", "0.3mm");
@@ -130,7 +111,7 @@ impl Visualizer for LineSegments {
130111
group = group.add(path);
131112
}
132113

133-
let bounding_rect = svg::node::element::Rectangle::new()
114+
let bounding_rect = element::Rectangle::new()
134115
.set("width", SCREEN_W)
135116
.set("height", SCREEN_H)
136117
.set("fill", "none")
@@ -139,4 +120,11 @@ impl Visualizer for LineSegments {
139120

140121
doc.add(group).add(bounding_rect)
141122
}
123+
124+
fn render(&self) {
125+
for line_segment in self.line_segments.iter() {
126+
let [[x1, y1], [x2, y2]] = line_segment.points;
127+
draw_line(x1 as f32, y1 as f32, x2 as f32, y2 as f32,VECTOR_WIDTH as f32, WHITE);
128+
}
129+
}
142130
}

0 commit comments

Comments
 (0)