updates
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					.zig-cache/
 | 
				
			||||||
 | 
					zig-out/
 | 
				
			||||||
							
								
								
									
										15
									
								
								src/main.zig
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/main.zig
									
									
									
									
									
								
							@@ -7,7 +7,6 @@ const SCREENHEIGHT = 1080;
 | 
				
			|||||||
const SCALE = 50;
 | 
					const SCALE = 50;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn main() !void {
 | 
					pub fn main() !void {
 | 
				
			||||||
    // std.debug.print("{d}\n", .{SCREENWIDTH / 2});
 | 
					 | 
				
			||||||
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
 | 
					    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
 | 
				
			||||||
    defer _ = gpa.deinit();
 | 
					    defer _ = gpa.deinit();
 | 
				
			||||||
    const allocator = gpa.allocator();
 | 
					    const allocator = gpa.allocator();
 | 
				
			||||||
@@ -19,19 +18,17 @@ pub fn main() !void {
 | 
				
			|||||||
    rl.setTargetFPS(60);
 | 
					    rl.setTargetFPS(60);
 | 
				
			||||||
    rl.beginDrawing();
 | 
					    rl.beginDrawing();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rl.clearBackground(rl.Color.white);
 | 
					    rl.clearBackground(rl.Color.light_gray);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    plotGraph();
 | 
					    plotGraph();
 | 
				
			||||||
    drawAxis();
 | 
					    drawAxis();
 | 
				
			||||||
    try markAxis(allocator);
 | 
					    try markAxis(allocator);
 | 
				
			||||||
 | 
					    calculateArea();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rl.endDrawing();
 | 
					    rl.endDrawing();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (!rl.windowShouldClose()) {
 | 
					    while (!rl.windowShouldClose()) {
 | 
				
			||||||
        rl.beginDrawing();
 | 
					        rl.beginDrawing();
 | 
				
			||||||
        // DEBUG
 | 
					 | 
				
			||||||
        // const pos = rl.getMousePosition();
 | 
					 | 
				
			||||||
        // std.debug.print("x: {d} y:{}\n", .{ pos.x, pos.y });
 | 
					 | 
				
			||||||
        rl.endDrawing();
 | 
					        rl.endDrawing();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -50,7 +47,7 @@ fn markAxis(allocator: std.mem.Allocator) !void {
 | 
				
			|||||||
    const font_size = 20;
 | 
					    const font_size = 20;
 | 
				
			||||||
    const start_x = SCREENWIDTH / 2;
 | 
					    const start_x = SCREENWIDTH / 2;
 | 
				
			||||||
    const start_y = SCREENHEIGHT / 2;
 | 
					    const start_y = SCREENHEIGHT / 2;
 | 
				
			||||||
    const radius = SCALE / 15;
 | 
					    const radius = 50 / 15;
 | 
				
			||||||
    var buf: [20]u8 = undefined;
 | 
					    var buf: [20]u8 = undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var cnt: usize = 0;
 | 
					    var cnt: usize = 0;
 | 
				
			||||||
@@ -131,7 +128,7 @@ fn plotGraph() void {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// f(x)
 | 
					// f(x)
 | 
				
			||||||
fn getY(x: f32) !f32 {
 | 
					fn getY(x: f32) !f32 {
 | 
				
			||||||
    return math.calculate(x, -3, .Power);
 | 
					    return try math.calculate(x, 2, .Power) / -2 + 6;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn adjustForGridSystem(input_vector: rl.Vector2) rl.Vector2 {
 | 
					fn adjustForGridSystem(input_vector: rl.Vector2) rl.Vector2 {
 | 
				
			||||||
@@ -144,3 +141,7 @@ fn adjustForGridSystem(input_vector: rl.Vector2) rl.Vector2 {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return new_vector;
 | 
					    return new_vector;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn calculateArea() void {
 | 
				
			||||||
 | 
					    rl.drawText("Test", SCREENWIDTH - 75, 25, 20, rl.Color.red);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								src/math.zig
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								src/math.zig
									
									
									
									
									
								
							@@ -15,11 +15,10 @@ pub fn calculate(first: f32, second: f32, op: MathOperation) !f32 {
 | 
				
			|||||||
            return first / second;
 | 
					            return first / second;
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        .Power => {
 | 
					        .Power => {
 | 
				
			||||||
            if (first == 0) std.debug.print("KOK", .{});
 | 
					 | 
				
			||||||
            if (first == 0 and second < 0) {
 | 
					            if (first == 0 and second < 0) {
 | 
				
			||||||
                return error.InvalidParam;
 | 
					                return error.InvalidParam;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return pow(first, @intFromFloat(second));
 | 
					            return std.math.pow(f32, first, second);
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        .Root => {
 | 
					        .Root => {
 | 
				
			||||||
            if (first < 0 or second < 0) {
 | 
					            if (first < 0 or second < 0) {
 | 
				
			||||||
@@ -37,23 +36,3 @@ fn abs(a: f32) f32 {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return a;
 | 
					    return a;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
fn pow(a: f32, b: i32) f32 {
 | 
					 | 
				
			||||||
    var res: f32 = 1.0;
 | 
					 | 
				
			||||||
    var n: usize = undefined;
 | 
					 | 
				
			||||||
    var f: f32 = undefined;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (b < 0) {
 | 
					 | 
				
			||||||
        f = 1 / a;
 | 
					 | 
				
			||||||
        n = @intCast(-b);
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        f = a;
 | 
					 | 
				
			||||||
        n = @intCast(b);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (0..n) |_| {
 | 
					 | 
				
			||||||
        res *= f;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return res;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user