uni update

This commit is contained in:
Martin Vrhovšek 2025-02-20 21:13:35 +01:00
parent da2b271865
commit 14a0678835

View File

@ -16,19 +16,16 @@ pub fn main() !void {
defer rl.closeWindow();
rl.setTargetFPS(60);
rl.beginDrawing();
rl.clearBackground(rl.Color.light_gray);
plotGraph();
drawAxis();
try markAxis(allocator);
calculateArea();
rl.endDrawing();
while (!rl.windowShouldClose()) {
rl.beginDrawing();
rl.clearBackground(rl.Color.white);
plotGraph();
drawAxis();
try markAxis(allocator);
rl.endDrawing();
}
}
@ -142,6 +139,34 @@ fn adjustForGridSystem(input_vector: rl.Vector2) rl.Vector2 {
return new_vector;
}
fn calculateArea() void {
rl.drawText("Test", SCREENWIDTH - 75, 25, 20, rl.Color.red);
fn calculateArea(val: f32) !void {
var buf: u8[20] = undefined;
const txt = try std.fmt.bufPrintZ(&buf, "{}", .{val});
rl.drawText(txt, SCREENWIDTH - 75, 25, 20, rl.Color.red);
}
const SimpsonsError = error{
InvalidParValue,
};
fn simpsonsRule(start: f32, end: f32, n: usize) !f32 {
if (start > end) return SimpsonsError.InvalidParValue;
const h = (end - start) / @as(f32, @floatFromInt(n));
var sum: f32 = getY(start) + getY(end);
var i: usize = 1;
// we iterate through amount of subintervals
while (i < n) : (i += 1) {
// calculate x of the slice we're adding (start + )
const x = start + i * h;
// determine weights 4 for odd, 2 for even
sum += if (x % 2 == 0) 2 * getY(x) else 4 * getY(x);
}
return (h / 3.0) * sum;
}