{"id":27924437,"url":"https://github.com/oonap0oo/small-python-projects","last_synced_at":"2025-08-07T02:13:33.802Z","repository":{"id":283119297,"uuid":"950752254","full_name":"oonap0oo/small-Python-projects","owner":"oonap0oo","description":"small pieces of Python code","archived":false,"fork":false,"pushed_at":"2025-07-28T10:44:20.000Z","size":12160,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-28T12:31:22.615Z","etag":null,"topics":["matplotlib-python","numpy-python","python","scipy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oonap0oo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-18T16:25:52.000Z","updated_at":"2025-07-28T10:44:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d96f546-2148-4d8f-a76f-c68bab62873f","html_url":"https://github.com/oonap0oo/small-Python-projects","commit_stats":null,"previous_names":["oonap0oo/small-pyhton-projects"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oonap0oo/small-Python-projects","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oonap0oo%2Fsmall-Python-projects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oonap0oo%2Fsmall-Python-projects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oonap0oo%2Fsmall-Python-projects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oonap0oo%2Fsmall-Python-projects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oonap0oo","download_url":"https://codeload.github.com/oonap0oo/small-Python-projects/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oonap0oo%2Fsmall-Python-projects/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269185726,"owners_count":24374634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matplotlib-python","numpy-python","python","scipy"],"created_at":"2025-05-06T23:50:39.480Z","updated_at":"2025-08-07T02:13:33.784Z","avatar_url":"https://github.com/oonap0oo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# small-Python-projects\nsmall pieces of Python code\n\n## [mandelbrot_v1.py](mandelbrot_v1.py)\n\n![mandelbrot_v1_image.png](mandelbrot_v1_image.png)\n\nThis code calculates a image of the Mandelbrot set, it uses numpy for vectorized calculations and\nmatplotlib for display. \n\nThis version has parameters set to view the complete Mandelbrot fractal\n\nThe image can be saved as png image file\n\n## [mandelbrot_v1_detail.py](mandelbrot_v1_detail.py)\n\n![mandelbrot_v1_detail_image.png](mandelbrot_v1_detail_image.png)\n\nThis code calculates a image of the Mandelbrot set, it uses numpy for vectorized calculations and\nmatplotlib for display. \n\nThis version has parameters set to view a detail of the Mandelbrot fractal\n\nThe image can be saved as png image file\n\n## [julia_v1.py](julia_v1.py)\n\n![julia1.png](julia1.png)\n\nA modification of the Mandelbrot code allows to calculate the Julia set.\n\n## [logistic_map_calculate_image_v3.py](logistic_map_calculate_image_v3.py)\n\n![logistic_map_calculate_image_v3_plot.png](logistic_map_calculate_image_v3_plot.png)\n\nThis code calculates an image of the bifurcation diagram for the logistic map.\n```\n Xn+1 = a. Xn.(1 - Xn)\n```\n\nIterations are done for increasing values of 'a', the logistic map is represented as a Numpy array\n\nThe image of the map is displayed using Matplotlib and can be saved as a PNG image file.\n\n## [kings_dream_cpython.py](kings_dream_cpython.py)\n\n\n![kings_dream_cpython_screenshot.png\\-}-](kings_dream_cpython_screenshot.png)\n\nThis script draws the fractal defined by iterating the x,y values through the following function\n\n        x = sin(a*x) + b*sin(a*y)\n        y = sin(c*x) + d*sin(c*y)\n\nwith constants of \n\n        a = 2.879879\n        b = -0.765145\n        c = -0.966918\n        d = 0.744728\n\nand initial values of x=2, y=0 \n\nThe image can be saved as PNG file.\nThe script uses the numpy, matplotlib and math libraries.\n\n## [hopalong.py](hopalong.py)\n\n\n![hopalong_screenshot.png\\-}-](hopalong_screenshot.png)\n\nA variation of the code for the 'King's dream fractal' yields this 'hopalong' fractal.\nThis script draws the fractal defined by iterating the x,y values through the following function\n\n        x = y - 1 - sqrt(abs(bx - 1 - c)) . sign(x-1)\n        y = a - x - 1\n\nInitial values are 0.0 for x and y\nThe parameters a,b,c can be any value between 0.0 and 10.0. A lot of combinations seem to give an intresting fractal\n\n## [tinkerbell.py](tinkerbell.py)\n\n\n![tinkerbell_screenshot.png\\-}-](tinkerbell_screenshot.png)\n\nA variation of the code for the 'King's dream fractal' yields this 'tinkerbell' fractal.\nThis script draws the fractal defined by iterating the x,y values through the following function\n\n        x = x² -y² +ax + by\n        y = 2xy + cx + dy\n\nwith constants of \n\n        a = 0.9\n        b = -0.6013\n        c = 2.0\n        d = 0.5\n\nand initial values of x=0.01, y=0.01\n\nThe image can be saved as PNG file.\nThe script uses the numpy, matplotlib and math libraries.\n\n## [quadrup_two.py](quadrup_two.py)\n\n![quadrup_two_screenshot.png](quadrup_two_screenshot.png)\n\nA further variation of the code for the 'King's dream fractal' yields the 'Quadrup Two' fractal.\nThis script draws the fractal defined by iterating the x,y values through the following function\n\n        x = y - sgn(x) * sin(ln|b * x - c|) * atan( (c * xn - b)2 )\n        y = a - x\n\nwith constants for example, they can be varied to give different fractals\n\n        a = 34\n        b = 1\n        c = 5\n\nand initial values of x=0, y=0\n\nThe image can be saved as PNG file.\nThe script uses the numpy, matplotlib and math libraries.\n\n## [Gumowski_Mira.py](Gumowski_Mira.py)\n\n![Gumowski_Mira6.png](Gumowski_Mira6.png)\n\nThis Gumowski-Mira fractal seems very sensitive to parameter and intial values.\nThis script draws the fractal defined by iterating the x,y values through the following function\n\n        f(x) = ax + 2(1-a). x² / (1+x²)²\n        xn+1 = by + f(xn)\n        yn+1 = f(xn+1) - xn\n\nwith constants for example, they can be varied to give different fractals\n\n        a = -0.7  a should be within [-1,1]\n        b = 1.0 should be 1.0 (or very close?)\n\nand initial values of x=-5.5, y=-5.0, they should be in [-20,20]\n\nThe image can be saved as PNG file.\nThe script uses the numpy, matplotlib and math libraries.\n \n## [sierpinski_triangle_tkinter_v6.py](sierpinski_triangle_tkinter_v6.py)\n\n![sierpinski_triangle_tkinter_v6_screenshot.png](sierpinski_triangle_tkinter_v6_screenshot.png)\n\nSierpinski Triangle constructed using the Chaos game method. \nIt rotates and scales in and out.\nThe triangle is drawn on a tkinter canvas widget.\n\n## [pascal_triangle_ansi.py](pascal_triangle_ansi.py)\n\n![pascal_triangle.png](pascal_triangle.png)\n\nThis code calculates the first 32 rows of Pascal's triangle.\nIt then prints the last digit of each value\nby marking if that digit is uneven, the Sierpinski triangle appears.\nThis version uses ANSI escape codes to generate colors and reverse characters\n\n## [pascal_triangle_no_ansi_v2.py](pascal_triangle_no_ansi_v2.py)\n\n\nThis code calculates the first 32 rows of Pascal's triangle\nIt then prints the last digit of each value\nby marking if that digit is uneven, the Sierpinski triangle appears.\nThis version avoids using ANSI escape codes by reprinting the triangle\nusing a character in place of uneven values\n\n## [mandelbrot_text_CPython.py](mandelbrot_text_CPython.py)\n\n\n![mandelbrot_text_CPython_screenshot.png](mandelbrot_text_CPython_screenshot.png)\n\nThis code displays a text output of the Mandelbrot fractal. \n\nANSI commands are used to generate color.\n\nThe Mandelbrot values are displayed as 2 digit hexadecimal characters.\n\n## [mandelbrot_text_CPython_no_ansi.py](mandelbrot_text_CPython_no_ansi.py)\n\n\nA version of mandelbrot_text_CPython.py without the ANSI commands.\n\nGenerates a much more basic output witout color.\n\n## [sierpinsky_turtle_cpython.py](sierpinsky_turtle_cpython.py)\n\n\n![sierpinsky_turtle_cpython_screenshot.png](sierpinsky_turtle_cpython_screenshot.png)\n\nThis script draws a Sierpinsky triangle recursively using turtle. \n\nThis one makes use extra functionality in CPython's turtle on the PC, such as drawing filled shapes. \n\nThe code shows several triangles using  successively deeper recursion.\n\n\n## [logistic_map_test_v2.py](logistic_map_test_v2.py)\n\n![logistic_map_test_v2.jpg](logistic_map_test_v2.jpg)\n\nGenerating a bifurcation diagram of the Logistic Map.\nusing Numpy and Matplotlib\n\n## [gingerbread_CPython.py](gingerbread_CPython.py)\n\n![gingerbread_CPython_screenshot.png](gingerbread_CPython_screenshot.png)\n\nThis script draws a “Gingerbread man” fractal. The shape is generated by applying a simple iteration and plotting the x,y values. It has an extra function which keeps track of the distance between successive x,y points in the iterations, this is used to derive the color of the points to make the fractal look more interesting visually. It uses Tkinter for plotting also the math library.\n\n## [recursive_tree_canvas_v4.py](recursive_tree_canvas_v4.py)\n\n![recursive_tree_canvas_v4.png](recursive_tree_canvas_v4.png)\n \n Drawing recursive trees on a Tkinter canvas. Four different looking\n trees are drawn using the same code with different parameters.\n Function branch() draws one branch and calls function start_new_branches().\n Function start_new_branches() calls branch() three times to draw branches\n with different angles. Recursion depth is controlled by parameter number_of_recursions\n\n## [pi_monte_carlo_circle.py](pi_monte_carlo_circle.py)\n\n ![pi_monte_carlo_circle_plots.png](pi_monte_carlo_circle_plots.png)\n\nMonte Carlo approximation of PI, using Python and Numpy. \nA series of points with random x,y coördinates are calculated, whether they fall inside the unit circle can be used to approximate the value of PI. Calculations are done in a series of parts called intervals. The code keeps track of the successive PI approximations taking the extra data into account after each interval, it prints a table and plots a graph. \n\n## [perimeter_ellipse_v4.py](perimeter_ellipse_v4.py)\n\n![perimeter_ellipse_v4_py.png](perimeter_ellipse_v4_py.png)\n\nThree methods to approximate the Circumference of an ellipse, using Python + Scipy + Numpy + Matplotlib\nThe Circumference of a series of elipses with identical surface area is calculated,\nthe shape ranging from a circle to the flattest ellipse.\nUsing the complete elliptic integral of the second kind function ellipe() and\nthe Binomial coefficients function binom() from scipy.special.\n\n## [wbridge.py](wbridge.py)\n\n\nCalculate output voltage of a Wheatstone Bridge as function of one\nvariable resistor Rx using Kirchhoff circuit laws and left division operator with a matrix and vector.\nMade to compare code with a GNU Octave script doing the same calculations: [wbridge.m](https://github.com/oonap0oo/GNU_Octave_scripts/blob/23891978e31cf807bc051fc30719fc4f2e71cebe/wbridge.m)\n\n## [lorenz_system_scipy_numpy_v2.py](lorenz_system_scipy_numpy_v2.py)\n\n![lorenz_system_plots_scipy_python.png](lorenz_system_plots_scipy_python.png)\n\nThis code calculates a solution for the Lorenz System with the system parameters sigma = 10, beta = 8.0 / 3.0, rho = 28.0.\nIt uses the Scipy function scipy.integrate.solve_ivp() to solve the system of ODEs. A series of plots is created using matplotlib.\nShowing the three variables x, y and z vs time and also a 3D line plot.\n\n## [runge_kutta_python_code_exp_decay.py](runge_kutta_python_code_exp_decay.py)\n\n![runge_kutta_python_code_exp_deca_plots.png](runge_kutta_python_code_exp_deca_plots.png)\n\nComparing three methods to solve a ODE:\n* First-order Euler method, coded directly in Python\n* Fourth-order Runge-Kutta method, coded directly in Python\n* Scipy function solve_ivp()\nUsing a a simple exponential decay system because it has an\nexact solution: N(t) = Nₒ.exp(-λ.t)\nComparing the results with the exact values and mesuring the execution time\nusing time.perf_counter().\nPlots are made using matplotlib.\n\n## [fourier_series_v4.py](fourier_series_v4.py)\n\n![fourier_series_plot1.png](fourier_series_plot1.png)\n\nThis code calculates the coefficients of the Fourier Series of a number\nof functions.\n* square_wave\n* pulse\n* sawtooth\n* the absolute value of a sine function\n* a chopped sine function\n* a half sine function\n\nEach function is plotted with their approximations using several numbers \nof coefficients. Also the Fourier Series coefficients themselves are plotted. \nThe code uses the function integrate.quad() from the Scipy library to calculate the various\nintegrals. The plots are made using Matplotlib, Numpy is also used.\n\n## [scipy_convolution_sallen_key_lpf_v2.py](scipy_convolution_sallen_key_lpf_v2.py)\n\n![scipy_convolution_sallen_key_lpf_v2_plot.png](scipy_convolution_sallen_key_lpf_v2_plot.png)\n\nThis code defines the transferfunction of an example VCVS Sallen-Key active analog low pass filter\nas function of s.\nIt uses the information to: \n* calculate the impulse response using Scipy function signal.impulse()  \n* calculate the frequency response using scipy function signal.bode()\n* calculate the output signal as function of time for two types of input signals. It performs a convolution of the input signals and the impulse response using scipy function signal.convolve()\n\nThe input signals are a square wave generated using Scipy function signal.square() \nand a sawtooth generated using Scipy function signal.sawtooth().\n\nGraphs are made using matplotlib. Calculations use numpy arrays.\n\n## [simple_linear_regression_dataset_v2.py](simple_linear_regression_dataset_v2.py)\n\n![simple_linear_regression_plot.png](simple_linear_regression_plot.png)\n\nThis code explores 4 different methods for simple linear regression in Python\nIt uses a function directly coded in Python:\n1. From python's statistics library: function statistics.linear_regression()\n2. From the Numpy library function numpy.polynomial.polynomial.Polynomial.fit()\n3. From the Scipy library function nscipy.stats.linregress()\n4. It plots the xy data and the linear regression lines\n\nIt displays a table using matplotlib underneath the plot \nthe test data is the duration of one swing for different lengths of a pendulum\n\n## [monte_carlo_circuit.py](monte_carlo_circuit.py)\n\n![monte_carlo_circuit_screenshot.png](monte_carlo_circuit_screenshot.png)\n\nMONTE CARLO ANALYSIS USING PYTHON, NUMPY AND MATPLOTLIB\nthis code performs a Monte Carlo analysis of a voltage divider with two resistors\nNumpy is used to generate the random values with a normal distribution\nmatplotlib is used to generate the plot\n\n## [lotka_volterra_predator_prey_model_v2.py](lotka_volterra_predator_prey_model_v2.py)\n\n![lotka_volterra_screenshot.png](lotka_volterra_screenshot.png)\n\nThis code calculates some solutions to an example Lotka–Volterra predator–prey model. \nFunction solve_ivp() is used from module Scipy to calculate solutions for 3 different initial conditions.\nThe result is plotted as function of time and in a phase-space plot using Matplotlib.\n\n## [buffons_needle_pi_approximation.py](buffons_needle_pi_approximation.py)\n\n![buffons_needle_pi_approximation_screenshot.png](buffons_needle_pi_approximation_screenshot.png)\n\nThis code uses Buffon's needle problem to approximate PI. A number of needles is randomly dropped on the floor.\nBy keeping track of the number of needles touching a set of parallel lines PI can be approximated. It is a Monte Carlo method.\n\n## [pendulum.py](pendulum.py)\n\n\n![pendulum_screenshot.png](pendulum_screenshot.png)\n\nDamped, driven pendulum\n\nThis script calculates a solution to the ODE for a driven pendulum with damping. \n\n    I*d(dθ/dt)/dt + m*g*l*sin(θ) + b*dθ/dt = a*cos(Ω*t)\n\nThis second order non linear ODE has been to be modified to a system of two first order ODEs. \n\n    dω/dt = 1/I*( -g*m/l*sin(θ) - b*ω + a*cos(Ω*t) )\n    dθ/dt = ω\n\nThe script uses a 4th order Runge-Kutta method solve_ivp() from scipy.integrate to calculate a solution of this system.\n\n## [van_der_pol_oscillator.py](van_der_pol_oscillator.py)\n\n\n![van_der_pol_oscillator_screenshot.png](van_der_pol_oscillator_screenshot.png)\n\nThis script calculates a response of a Van Der Pol Oscillator \n\n    d(d(x)/dt)/dt -  μ * (1 - x**2) * dx/dt + x = A * sin( ω*t )\n    μ: \"mu\" is non linear damping\n    x: displacement\n    A: amplitude of driving source\n    ω: angular frequency of driving source [rad/s]\n\nThe response is calculated in two cases:\n\n* Case 1: undriven with non linear damping mu=0.1\n* Case 2: oscillator with damping mu=8.53, driven with a sinewave source of amplitube A=1.2 and time period T=10s\n\nThe response is shown as function of time and as phase plot\n\n## [aizawa_attractor_scipy_numpy.py](aizawa_attractor_scipy_numpy.py)\n\n\n![Aizawa_Attractor_1.png](Aizawa_Attractor_1.png)\n\nThis 3D Aizawa Attractor has 6 parameters and gives a spherical appearance.\n\nCalculations done using scipy function solveivp(). Plotting done using matplotlib.\n\n### equations\n\n    dx/dt = (z - b) * x - d * y\n    dy/dt = d * x + (z - b) * y\n    dz/dt = c + a * z - z**3 / 3.0 - (x**2 + y**2) * (1 + e * z)  + f * z * x**3\n\n### Parameters of the Aizawa attractor\n\n    a = 0.95, b = 0.7, c = 0.6, d = 3.5, e = 0.25, f = 0.1\n    \n### Initial conditions\n\nx0 = 0.1, y0 = 0.0, z0 = 0.0\n\n## [batch_resizer.py](batch_resizer.py)\n\n![batch_resizer_screenshot.png](batch_resizer_screenshot.png)\n\nThis python code resizes all supported image files in a directory.\n\nThe resized version of the images are saved as new image files.\n\n## [hex_view4.py](hex_view4.py)\n\n![hex_view_screenshot.png](hex_view_screenshot.png)\n\nA simple hex viewer running in a console\n\n## [decimal_degrees_to_dms.py](decimal_degrees_to_dms.py)\n\n\nContains one function that takes an angle as float and returns degrees, minutes, seconds as tuple\n\nA second function takes tuple of  degrees, minutes, seconds and returns string representation   \n\n## [pasword_generator _v2.py](pasword_generator _v2.py)\n\ngenerate a password of given length containing numbers, upper case letters,\nlower case letters and optionally symbols\n\n## [function_sortandfilter_v2.py](function_sortandfilter_v2.py)\n\nfunction which accepts a list of strings, removes duplicates, sorts alphabetically\nand fiters using a optional search string\n\n## [class_color_code.py](class_color_code.py)\n\ncontains three class definitions:\n\n### class resistor()\ncontains code to find the value of a resistor \nout of the color codes present on the component\ncan return a tuple containing (value, tolerance) as values\nor a string representation such as \"12 MOhm 5%\"\n\n### class resistance()\ncontains code to find the colorband colors\nout of the value and tolerance of the component\nboth for sets of 4 and 5 colorbands \n\n### class colors\ncontains dictionaries to facilitate printing in\ncolor in the console using ANSI escape sequences\n\n## [get_color_codes.py](get_color_codes.py)\n\nfind the color code of a resistor using the classes in class_color_code.py\nprints the color bands in color on a console using ANSI escape sequences.\n\n## [get_value_from_color_codes.py](get_value_from_color_codes.py)\n\nfind the value and tolerance of a resistor based on the color bands.\nIt uses the classes in class_color_code.py and prints color bands in color\nusing ANSI escape sequences.\n\n## [several_methods_fibonacci_sequence_v2.py](several_methods_fibonacci_sequence_v2.py)\n\nThese 6 different Python functions generate the same list containing a specified number of Fibonacci numbers.\nIncluded are a generator function, recursive functions with and without memoization, \na function from the sympy library and Binet's formula, a closed-form expression.\n\n## [roman_numerals_v2.py](roman_numerals_v2.py)\n\nThis code converts a roman numeral in standard form to an integer\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foonap0oo%2Fsmall-python-projects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foonap0oo%2Fsmall-python-projects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foonap0oo%2Fsmall-python-projects/lists"}