summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoradmin <contact@optics-design.com>2025-04-25 21:17:07 +0200
committeradmin <contact@optics-design.com>2025-04-25 21:17:07 +0200
commit4b3b08ecadf8604062c7f801668e641cb024e309 (patch)
tree93614c08b9cfabff25e5c790fcfd50d31663ef53 /src
First Commit
Diffstat (limited to 'src')
-rw-r--r--src/lensdrac/lensdrac.c57
-rw-r--r--src/lensdrac/sdl2test.c22
-rw-r--r--src/odutils/contrast.c43
-rw-r--r--src/odutils/oif.c42
-rw-r--r--src/odutils/refl.c39
5 files changed, 203 insertions, 0 deletions
diff --git a/src/lensdrac/lensdrac.c b/src/lensdrac/lensdrac.c
new file mode 100644
index 0000000..abcacb3
--- /dev/null
+++ b/src/lensdrac/lensdrac.c
@@ -0,0 +1,57 @@
+/**
+ * lensdraw.c - source file for trying things with SDL2.
+ *
+ * Copyright (C) 2025 https://optics-design.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * See the COPYING file for the full license text.
+ */
+#include <SDL.h>
+#include <math.h>
+
+#define SCREEN_WIDTH 800
+#define SCREEN_HEIGHT 600
+
+void draw_circle(SDL_Renderer *renderer, int cx, int cy, int r) {
+ for (int x = -r; x <= r; x++) {
+ int y = sqrt(r * r - x * x);
+ SDL_RenderDrawPoint(renderer, cx + x, cy + y);
+ SDL_RenderDrawPoint(renderer, cx + x, cy - y);
+ }
+}
+
+void draw_lens(SDL_Renderer *renderer, int cx, int cy, int r) {
+ SDL_SetRenderDrawColor(renderer, 0, 200, 255, 255); // Light blue color for lens
+
+ for (int x = 0; x <= r; x++) {
+ int y1 = sqrt(r * r - x * x);
+ int y2 = -y1;
+
+ for (int y = y2; y <= y1; y++) {
+ SDL_RenderDrawPoint(renderer, cx + x, cy + y);
+ }
+ }
+}
+int main(int argc, char* argv[]) {
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Window *window = SDL_CreateWindow("Spherical Lens", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
+ SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
+
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // Black background
+ SDL_RenderClear(renderer);
+
+ draw_lens(renderer, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 100); // Draw lens
+
+ SDL_RenderPresent(renderer);
+
+ SDL_Delay(5000); // Show for 5 seconds
+
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+ return 0;
+}
diff --git a/src/lensdrac/sdl2test.c b/src/lensdrac/sdl2test.c
new file mode 100644
index 0000000..511c0bd
--- /dev/null
+++ b/src/lensdrac/sdl2test.c
@@ -0,0 +1,22 @@
+/**
+ * sdl2test.c - source file for trying things with SDL2.
+ *
+ * Copyright (C) 2025 https://optics-design.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * See the COPYING file for the full license text.
+ */
+#include <SDL.h>
+
+int main(int argc, char *argv[]) {
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Window *win = SDL_CreateWindow("Hello SDL2", 100, 100, 800, 600, SDL_WINDOW_SHOWN);
+ SDL_Delay(2000);
+ SDL_DestroyWindow(win);
+ SDL_Quit();
+ return 0;
+}
diff --git a/src/odutils/contrast.c b/src/odutils/contrast.c
new file mode 100644
index 0000000..115bcb0
--- /dev/null
+++ b/src/odutils/contrast.c
@@ -0,0 +1,43 @@
+/**
+ * contrast.c - source file for just testing basic contrast stuff.
+ *
+ * Copyright (C) 2025 https://optics-design.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * See the COPYING file for the full license text.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char* argv[]){
+ int number=1;
+ char ch;
+while (--argc>0) {
+ if ((*++argv)[0] =='-') {
+
+
+while ((ch = *++argv[0])) {
+ switch (ch) {
+ case 'm':
+ number=1;
+ break;
+ case 'w':
+ number = 2;
+ break;
+ default:
+ printf("lmao\n");
+ break;
+
+
+ }
+
+}
+ }
+}
+ printf("this is %d",number);
+ return 0;
+}
diff --git a/src/odutils/oif.c b/src/odutils/oif.c
new file mode 100644
index 0000000..b5ef22f
--- /dev/null
+++ b/src/odutils/oif.c
@@ -0,0 +1,42 @@
+/**
+ * oif.c - source file for just testing basic optics-related functions.
+ *
+ * Copyright (C) 2025 https://optics-design.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * See the COPYING file for the full license text.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[]) {
+ if (argc != 4){
+ printf("This program calculates relations between object, image and focal length.\nIt requires you to provide two of these and leave the third one as any char in the form of O I F.\nExample: 90 x 50 will output 112.5");
+ return 1;
+ }
+ char *po, *pi, *pf;
+ float o,i,f;
+
+ o = strtof(argv[1], &po);
+ i = strtof(argv[2], &pi);
+ f = strtof(argv[3], &pf);
+ if (*po && !*pi && !*pf) {
+ o = i*f/(i-f);
+ }
+ else if (!*po && *pi && !*pf) {
+ i = o*f/(o-f);
+ }
+ else if (!*po && !*pi && *pf) {
+ f = o*i/(o+i);
+ }
+ else {
+ printf("Wrong usage of the program! Refer to help");
+ return 1;
+ }
+ printf("Object Distance: %.5f\nImage Distance: %.5f\nFocal Length: %.5f\n",o,i,f);
+ return 0;
+}
diff --git a/src/odutils/refl.c b/src/odutils/refl.c
new file mode 100644
index 0000000..dc5c205
--- /dev/null
+++ b/src/odutils/refl.c
@@ -0,0 +1,39 @@
+/**
+ * refl.c - source file for just testing basic optics-related functions.
+ *
+ * Copyright (C) 2025 https://optics-design.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * See the COPYING file for the full license text.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+int main(int argc, char *argv[]) {
+ if (argc != 4){
+ printf("This program calculates the reflection losses and transmission through nsurfs number of surfaces.\n The program is called either with parameters n1 n2 nsurfs and uses the formula Losses = (((n2-n1)/(n2+n1))**2)**nsurfs.");
+ return 1;
+ }
+ char *pn1, *pn2;
+ float n1,n2;
+ int nsurfs;
+ float singsurfrefl;
+
+ n1 = strtof(argv[1], &pn1);
+ n2 = strtof(argv[2], &pn2);
+ nsurfs = atoi(argv[3]);
+ // nsurfs = strtof(argv[3], &pnsurfs);
+ if ( *pn1||*pn2||!nsurfs) {
+ printf("Error! You did not provide n1 n2 nsurfs as numbers.");
+ return 1;
+ }
+ singsurfrefl = pow((n2-n1)/(n2+n1),2);
+
+ printf("Single Surface Loss: %.2f%\nSingle Surface Transmission:%.2f%\n%d-Surface Loss:%.2f%\n%d-Surface Transmission:%.2f%\n",100*singsurfrefl,100*(1-singsurfrefl),nsurfs,100*(1-pow(1-singsurfrefl,nsurfs)),nsurfs,100*pow(1-singsurfrefl,nsurfs));
+ return 0;
+}
Back to https://optics-design.com