This commit is contained in:
jonathan santis 2024-12-03 12:36:43 +01:00
parent af65248181
commit 7fbd24b85d
2 changed files with 39 additions and 22 deletions

View File

@ -11,6 +11,7 @@ const rand = prng.random();
const screenWidth = 1200; const screenWidth = 1200;
const screenHeight = 800; const screenHeight = 800;
fn randMinMaxFloat(min: f32, max: f32) f32 { fn randMinMaxFloat(min: f32, max: f32) f32 {
var r1 = rand.float(f32); var r1 = rand.float(f32);
r1 = 2 * (r1 - 0.5); //-0.5..0.5 r1 = 2 * (r1 - 0.5); //-0.5..0.5
@ -100,22 +101,18 @@ const Emitter = struct {
} }
} }
} }
pub fn update(self: *Emitter,att : []Attractor, texture: rl.Texture2D) void { pub fn update(self: *Emitter,att : []Attractor, texture: rl.Texture2D, color : rl.Color) void {
var posx: i32 = 0; var posx: i32 = 0;
var posy: i32 = 0; var posy: i32 = 0;
var vec2 : rl.Vector2=undefined; var vec2 : rl.Vector2=undefined;
if (rl.isMouseButtonPressed(rl.MouseButton.mouse_button_right)) { if (rl.isMouseButtonPressed(rl.MouseButton.mouse_button_right)) {
std.debug.print("right pressed\n",.{});
for (att) |*at| for (att) |*at|
{ {
std.debug.print("loop\n",.{});
if(at.init_done != 1) if(at.init_done != 1)
{ {
at.init(.{.a=.{.x=@floatFromInt(rl.getMouseX() - screenWidth / 2),.y=@floatFromInt(rl.getMouseY() - screenHeight / 2),.z=0}}); at.init(.{.a=.{.x=@floatFromInt(rl.getMouseX() - screenWidth / 2),.y=@floatFromInt(rl.getMouseY() - screenHeight / 2),.z=0}});
std.debug.print("atractorr allocated\n",.{});
break; break;
} }
} }
@ -145,7 +142,7 @@ const Emitter = struct {
} }
//rl.drawRectangle(posx,posy,2,2,rl.Color{.r=p.position.a.color.r,.g=p.position.a.color.g,.b=p.position.a.color.b,.a=255}); //rl.drawRectangle(posx,posy,2,2,rl.Color{.r=p.position.a.color.r,.g=p.position.a.color.g,.b=p.position.a.color.b,.a=255});
vec2 = .{.x = (screenWidth/2+p.position.a.x),.y = (screenHeight/2+p.position.a.y)}; vec2 = .{.x = (screenWidth/2+p.position.a.x),.y = (screenHeight/2+p.position.a.y)};
rl.drawTextureEx(texture, vec2,0.5,p.size, rl.Color.green); rl.drawTextureEx(texture, vec2,0.5,p.size, color);
} }
} }
} }
@ -209,9 +206,7 @@ fn rectangle(x: u16, y: u16, width: u16, height: u16) rl.Rectangle {
} }
pub fn main() anyerror!void { pub fn main() anyerror!void {
const rect3 = rectangle(10, 150, 600, 10);
const rect4 = rectangle(10, 170, 600, 10);
const rect5 = rectangle(10, 190, 600, 10);
var seed: u64 = undefined; var seed: u64 = undefined;
try std.posix.getrandom(std.mem.asBytes(&seed)); try std.posix.getrandom(std.mem.asBytes(&seed));
@ -221,6 +216,7 @@ pub fn main() anyerror!void {
var value: f32 = 0; var value: f32 = 0;
var value2: f32 = 0; var value2: f32 = 0;
var value3: f32 = 0; var value3: f32 = 0;
var color: rl.Color = undefined;
var emitter = Emitter{}; var emitter = Emitter{};
try emitter.init(); try emitter.init();
@ -239,13 +235,15 @@ pub fn main() anyerror!void {
} }
rl.unloadImage(image); rl.unloadImage(image);
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second rl.setTargetFPS(60);
const file = try plot.open("plot.dat"); const file = try plot.open("plot.dat");
var plotStr : []u8 = undefined; var plotStr : []u8 = undefined;
var plotStrBuf : [128]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]Attractor = undefined; var att: [10]Attractor = undefined;
var active : i32 = 0;
var editMode : bool = false;
while (!rl.windowShouldClose()) { // Detect window close button or ESC key while (!rl.windowShouldClose()) { // Detect window close button or ESC key
rl.beginDrawing(); rl.beginDrawing();
@ -258,10 +256,28 @@ pub fn main() anyerror!void {
.a = 255, .a = 255,
}); });
_ = rg.guiSlider(rect3, "0", "500", &value, ItoF(0), ItoF(500)); if(rg.guiDropdownBox(rectangle(10,10,100,20),"Settings;Particles",&active,editMode) != 0) {
_ = rg.guiSlider(rect4, "-3", "3", &value2, ItoF(-100), ItoF(100)); editMode = !editMode;
_ = rg.guiSlider(rect5, "-3", "3", &value3, -100, 100); 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);
}
else
{
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(value)), value2, value3);
} }
@ -270,9 +286,10 @@ pub fn main() anyerror!void {
try plot.log(file,plotStr); try plot.log(file,plotStr);
rl.beginBlendMode(rl.BlendMode.blend_additive); rl.beginBlendMode(rl.BlendMode.blend_additive);
emitter.update(&att,texture); emitter.update(&att,texture,color);
rl.endBlendMode(); rl.endBlendMode();
} }
}
plot.close(file); plot.close(file);
} }

Binary file not shown.