sdf
This commit is contained in:
parent
e07b6caa19
commit
76fde82477
101
src/main.zig
101
src/main.zig
@ -6,6 +6,7 @@ const particles = @import("particles.zig");
|
|||||||
const plot = @import("plot.zig");
|
const plot = @import("plot.zig");
|
||||||
|
|
||||||
const allocator = std.heap.page_allocator;
|
const allocator = std.heap.page_allocator;
|
||||||
|
const DEBUG = true;
|
||||||
|
|
||||||
const screenWidth = 1200;
|
const screenWidth = 1200;
|
||||||
const screenHeight = 800;
|
const screenHeight = 800;
|
||||||
@ -16,13 +17,20 @@ fn ItoF(x: i32) f32 {
|
|||||||
fn rectangle(x: u16, y: u16, width: u16, height: u16) rl.Rectangle {
|
fn rectangle(x: u16, y: u16, width: u16, height: u16) rl.Rectangle {
|
||||||
return rl.Rectangle{ .x = @as(f32, @floatFromInt(x)), .y = @as(f32, @floatFromInt(y)), .width = @as(f32, @floatFromInt(width)), .height = @as(f32, @floatFromInt(height)) };
|
return rl.Rectangle{ .x = @as(f32, @floatFromInt(x)), .y = @as(f32, @floatFromInt(y)), .width = @as(f32, @floatFromInt(width)), .height = @as(f32, @floatFromInt(height)) };
|
||||||
}
|
}
|
||||||
|
const Settings = struct {
|
||||||
|
particleCount: f32 = 1,
|
||||||
|
spread_x: f32 = 0,
|
||||||
|
spread_y: f32 = 0,
|
||||||
|
color: rl.Color = .{ .r = 255, .g = 255, .b = 0, .a = 100 },
|
||||||
|
active: i32 = 0,
|
||||||
|
editMode: bool = false,
|
||||||
|
};
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
var value: f32 = 0;
|
if(DEBUG) {
|
||||||
var value2: f32 = 0;
|
std.debug.print("DEBUG mode enabled",.{});
|
||||||
var value3: f32 = 0;
|
}
|
||||||
var color: rl.Color = undefined;
|
|
||||||
|
|
||||||
|
var settings = Settings{};
|
||||||
var emitter = particles.Emitter{};
|
var emitter = particles.Emitter{};
|
||||||
try emitter.init(allocator, screenWidth, screenHeight);
|
try emitter.init(allocator, screenWidth, screenHeight);
|
||||||
|
|
||||||
@ -42,55 +50,72 @@ pub fn main() anyerror!void {
|
|||||||
rl.setTargetFPS(60);
|
rl.setTargetFPS(60);
|
||||||
|
|
||||||
const file = try plot.open("plot.dat");
|
const file = try plot.open("plot.dat");
|
||||||
var plotStr: []u8 = undefined;
|
|
||||||
var plotStrBuf: [128]u8 = undefined;
|
|
||||||
try plot.log(file, "acceleration, position, velocity, show\n");
|
try plot.log(file, "acceleration, position, velocity, show\n");
|
||||||
|
|
||||||
var att: [10]particles.Attractor = undefined;
|
var att: [10]particles.Attractor = undefined;
|
||||||
var active: i32 = 0;
|
|
||||||
var editMode: bool = false;
|
|
||||||
|
|
||||||
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
|
while (!rl.windowShouldClose()) {
|
||||||
rl.beginDrawing();
|
rl.beginDrawing();
|
||||||
defer rl.endDrawing();
|
defer rl.endDrawing();
|
||||||
|
|
||||||
rl.clearBackground(rl.Color{
|
updateGui(&settings);
|
||||||
.r = 0,
|
|
||||||
.g = 0,
|
|
||||||
.b = 0,
|
|
||||||
.a = 255,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (rg.guiDropdownBox(rectangle(10, 10, 100, 20), "Settings;Particles", &active, editMode) != 0) {
|
|
||||||
editMode = !editMode;
|
|
||||||
std.debug.print("dropdownbox: {}", .{active});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (active == 1) {
|
|
||||||
if (rg.guiWindowBox(rectangle(10, 10, 800, 600), "Window Box") == 1) {
|
|
||||||
active = 0;
|
|
||||||
editMode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = rg.guiSlider(rectangle(10, 150, 600, 10), "0", "500", &value, ItoF(0), ItoF(500));
|
|
||||||
_ = rg.guiSlider(rectangle(10, 170, 600, 10), "-3", "3", &value2, ItoF(-100), ItoF(100));
|
|
||||||
_ = rg.guiSlider(rectangle(10, 190, 600, 10), "-3", "3", &value3, -100, 100);
|
|
||||||
_ = rg.guiColorPicker(rectangle(10, 200, 300, 100), "Choose Color", &color);
|
|
||||||
}
|
|
||||||
if (rl.isMouseButtonDown(rl.MouseButton.mouse_button_left)) {
|
if (rl.isMouseButtonDown(rl.MouseButton.mouse_button_left)) {
|
||||||
emitter.emit(@as(u32, @intFromFloat(value)), value2, value3);
|
emitter.emit(
|
||||||
|
@as(u32, @intFromFloat(settings.particleCount)),
|
||||||
|
settings.spread_x,
|
||||||
|
settings.spread_y
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
plotStr = try std.fmt.bufPrint(&plotStrBuf, "{d}, {d}, {d}, {d}\n", .{ emitter.particles[0].acceleration.a.x, emitter.particles[0].position.a.x, emitter.particles[0].velocity.a.x, emitter.particles[0].show });
|
|
||||||
try plot.log(file, plotStr);
|
|
||||||
|
|
||||||
rl.beginBlendMode(rl.BlendMode.blend_additive);
|
rl.beginBlendMode(rl.BlendMode.blend_additive);
|
||||||
emitter.update(&att, texture, color);
|
emitter.update(&att, texture, settings.color);
|
||||||
rl.endBlendMode();
|
rl.endBlendMode();
|
||||||
|
|
||||||
|
try log_emitter(file,0,emitter);
|
||||||
|
|
||||||
}
|
}
|
||||||
plot.close(file);
|
plot.close(file);
|
||||||
}
|
}
|
||||||
fn updateGUI() !void {}
|
|
||||||
|
fn log_emitter(file : std.fs.File, index : u32, emitter : particles.Emitter) !void
|
||||||
|
{
|
||||||
|
var plotStr: []u8 = undefined;
|
||||||
|
var plotStrBuf: [128]u8 = undefined;
|
||||||
|
plotStr = try std.fmt.bufPrint(&plotStrBuf, "{d}, {d}, {d}, {d}\n", .{
|
||||||
|
emitter.particles[index].acceleration.a.x,
|
||||||
|
emitter.particles[index].position.a.x,
|
||||||
|
emitter.particles[index].velocity.a.x,
|
||||||
|
emitter.particles[index].show });
|
||||||
|
try plot.log(file, plotStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn updateGui(set: *Settings) void {
|
||||||
|
rl.clearBackground(rl.Color{
|
||||||
|
.r = 0,
|
||||||
|
.g = 0,
|
||||||
|
.b = 0,
|
||||||
|
.a = 255,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (rg.guiDropdownBox(rectangle(10, 10, 100, 20), "Settings;Particles", &set.active, set.editMode) != 0) {
|
||||||
|
set.editMode = !set.editMode;
|
||||||
|
std.debug.print("dropdownbox: {}", .{set.active});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (set.active == 1) {
|
||||||
|
if (rg.guiWindowBox(rectangle(10, 10, 800, 600), "Window Box") == 1) {
|
||||||
|
set.active = 0;
|
||||||
|
set.editMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = rg.guiSlider(rectangle(10, 150, 600, 10), "0", "500", &set.particleCount, 0, 500);
|
||||||
|
_ = rg.guiSlider(rectangle(10, 170, 600, 10), "-3", "3", &set.spread_x, -100, 100);
|
||||||
|
_ = rg.guiSlider(rectangle(10, 190, 600, 10), "-3", "3", &set.spread_y, -100, 100);
|
||||||
|
_ = rg.guiColorPicker(rectangle(10, 200, 300, 100), "Choose Color", &set.color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "simple test" {
|
test "simple test" {
|
||||||
var list = std.ArrayList(i32).init(std.testing.allocator);
|
var list = std.ArrayList(i32).init(std.testing.allocator);
|
||||||
|
@ -48,7 +48,6 @@ pub const Particle = struct {
|
|||||||
self.acceleration.a.x = xrnr;
|
self.acceleration.a.x = xrnr;
|
||||||
self.acceleration.a.y = yrnr;
|
self.acceleration.a.y = yrnr;
|
||||||
self.position.a.x = @floatFromInt(rl.getMouseX() - @divTrunc(self.max_x, 2));
|
self.position.a.x = @floatFromInt(rl.getMouseX() - @divTrunc(self.max_x, 2));
|
||||||
std.debug.print("divtrunc x: {}\n,max_x:{}\n", .{ @divTrunc(self.max_x, 2), self.max_x });
|
|
||||||
self.position.a.y = @floatFromInt(rl.getMouseY() - @divTrunc(self.max_y, 2));
|
self.position.a.y = @floatFromInt(rl.getMouseY() - @divTrunc(self.max_y, 2));
|
||||||
self.velocity.a.x = 0;
|
self.velocity.a.x = 0;
|
||||||
self.velocity.a.y = 0;
|
self.velocity.a.y = 0;
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
pub fn init() void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
pub fn log(self : std.fs.File,data : []const u8) !void
|
pub fn log(self : std.fs.File,data : []const u8) !void
|
||||||
{
|
{
|
||||||
try self.writeAll(data);
|
try self.writeAll(data);
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user