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 screenHeight = 800;
fn randMinMaxFloat(min: f32, max: f32) f32 {
var r1 = rand.float(f32);
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 posy: i32 = 0;
var vec2 : rl.Vector2=undefined;
if (rl.isMouseButtonPressed(rl.MouseButton.mouse_button_right)) {
std.debug.print("right pressed\n",.{});
for (att) |*at|
{
std.debug.print("loop\n",.{});
if(at.init_done != 1)
{
at.init(.{.a=.{.x=@floatFromInt(rl.getMouseX() - screenWidth / 2),.y=@floatFromInt(rl.getMouseY() - screenHeight / 2),.z=0}});
std.debug.print("atractorr allocated\n",.{});
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});
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 {
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;
try std.posix.getrandom(std.mem.asBytes(&seed));
@ -221,6 +216,7 @@ pub fn main() anyerror!void {
var value: f32 = 0;
var value2: f32 = 0;
var value3: f32 = 0;
var color: rl.Color = undefined;
var emitter = Emitter{};
try emitter.init();
@ -239,13 +235,15 @@ pub fn main() anyerror!void {
}
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");
var plotStr : []u8 = undefined;
var plotStrBuf : [128]u8 = undefined;
try plot.log(file,"acceleration, position, velocity, show\n");
var att: [10]Attractor = undefined;
var active : i32 = 0;
var editMode : bool = false;
while (!rl.windowShouldClose()) { // Detect window close button or ESC key
rl.beginDrawing();
@ -258,20 +256,39 @@ pub fn main() anyerror!void {
.a = 255,
});
_ = rg.guiSlider(rect3, "0", "500", &value, ItoF(0), ItoF(500));
_ = rg.guiSlider(rect4, "-3", "3", &value2, ItoF(-100), ItoF(100));
_ = rg.guiSlider(rect5, "-3", "3", &value3, -100, 100);
if (rl.isMouseButtonDown(rl.MouseButton.mouse_button_left)) {
emitter.emit(@as(u32, @intFromFloat(value)), value2, value3);
if(rg.guiDropdownBox(rectangle(10,10,100,20),"Settings;Particles",&active,editMode) != 0) {
editMode = !editMode;
std.debug.print("dropdownbox: {}",.{active});
}
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);
if(active == 1)
{
if(rg.guiWindowBox(rectangle(10,10,800,600),"Window Box") == 1)
{
active = 0;
editMode = false;
}
rl.beginBlendMode(rl.BlendMode.blend_additive);
emitter.update(&att,texture);
rl.endBlendMode();
_ = 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)) {
emitter.emit(@as(u32, @intFromFloat(value)), value2, value3);
}
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);
emitter.update(&att,texture,color);
rl.endBlendMode();
}
}
plot.close(file);
}

Binary file not shown.