1. Introduction
The color of an object is one of the first characteristics that captures our attention. In the 17th and 18th centuries—the Age of Enlightenment—vigorous efforts were made to understand natural phenomena, and the study of light and color was systematized by luminaries such as Isaac Newton and Augustin-Jean Fresnel. With the advancement of computational techniques and theoretical frameworks, the simulation of color based on electrodynamics and optics has become an effective tool for predicting and elucidating experimental results in condensed matter physics and materials science [1,2,3]. As thin-film interference and multilayer coatings have recently garnered significant attention due to their ability to manipulate light at the nanoscale, color simulation techniques have been employed increasingly frequently. These techniques aim to describe or predict colors based on various factors, such as surface oxidation [4], crystallinity [5], and composition [6]. They have also been applied to explain the color variations generated in Mie resonators based on liquid crystals [7].
Despite the availability of commercial software and web-based tools used for optical simulations [8,9,10], access to internal processes is often restricted due to proprietary algorithms, limiting customization. Nevertheless, researchers and engineers frequently look for flexible and customizable tools to adjust their simulations to meet specific experimental conditions and material properties.
Recently, many individuals have used programming languages to carry out their own tasks, such as data analysis [11,12], fitting [13,14], and simulation [15,16]. Among the different programming languages, Python stands out because of its open-source license, user-friendly interface, and various libraries which include functions essential for simulation, including calculation, visualization, and interpolation [17,18,19]. In addition to these features, advanced algorithms such as machine learning algorithms have been developed and utilized [20,21,22]. Consequently, there is a growing demand for fundamental theoretical simulations that can complement and work with modern programming languages and algorithmic approaches.
Here, we introduce a Python-based approach for simulating the color of thin-film multilayers, while providing ample background on its underlying physics and coding—from basic electrodynamics, including the Fresnel equations, to the conversion of reflectance spectrum to RGB values based on a color matching function. Our code requires only information on the complex refractive indices (within the visible range) and thickness of each layer and a specific incident angle. To validate this code, we compare the simulated colors of several thin films with other results: SiO2 films from the existing literature and SnO2 and ZnO thin films with a thickness gradient, which were prepared for this study. The code is straightforward and allows individuals with basic Python knowledge to easily modify or add conditions, facilitating color simulation under various conditions and for integration with other applications. We hope that this code helps students and researchers working on materials science and AI-based research in various ways.
2. Materials and Methods
2.1. Theoretical Background
2.1.1. Reflection from a Bulk Surface
When light is incident on an object, it undergoes multiple absorptions, reflections, and transmissions at the surface, and the color of that object is determined by the spectrum of light reflected from its surface. Fresnel equations describe the reflected and transmitted amplitudes of light with respect to that of the incident wave, which can be derived from the boundary conditions of electric and magnetic fields at an interface.
We define the plane of incidence that contains the surface normal vector and the propagation vector of incident light and determine p- or s-polarization from the direction of E oscillation with respect to the plane of incidence (Figure 1). The p-polarization indicates that E oscillates parallel to the plane of incidence (Figure 1a). Here, we first derive the Fresnel equations for the case of polarization parallel to the plane of incidence (i.e., p-polarization). Since the parallel component of E and the normal component of B with respect to the interface need to be continuous, we arrive at the following equations:
(1)
(2)
where the subscripts i, r, and t represent the incident, reflected, and transmitted waves, respectively. Since (n: refractive index,) where is the speed of an electromagnetic wave in matter [23], Equation (2) indicates that(3)
where and are the refractive indices of the media before and after transmission. Given the laws of reflection () and refraction (i.e., Snell’s law; ) and by solving Equations (1) and (2), we obtain the reflection and transmission coefficients for p-polarized light:(4)
(5)
For s-polarization (Figure 1b), the boundary conditions for E and B become
(6)
(7)
The reflection and transmission coefficients for s-polarized light can be obtained by the same procedure.
(8)
(9)
The reflectance (R) and transmittance (T) are defined by the ratio of the reflected and transmitted intensity (average power per unit area) to the incident intensity (); thus,
(10)
(11)
The reflectance depends on the polarization of the light, and we consider natural, or unpolarized, light in this article. The reflectance of unpolarized light (Rn) can be given by the averaged reflectance of all incident waves with different polarization angles:
(12)
where is the polarization angle [24].2.1.2. Reflection from a (Multilayered) Thin Film
For a thin film or multilayered structure, we need to consider the absorption and optical interference of multiple reflections, transmissions, and absorptions occurring at interfaces underneath the surface.
This absorption can be formulated by incorporating a complex refractive index into the wave function (Figure 2). The wave function of a plane wave traveling in the x direction can be written in complex notation as follows:
(13)
where , , t, , and x are the complex wave amplitude’s, angular frequency, time, complex wavenumber, and position, respectively. The complex wavenumber can be written as(14)
where is the complex refractive index. is defined as(15)
where n and k are the refractive index and extinction coefficient, respectively. By substituting Equations (14) and (15) into Equation (13), we obtain an expression for the electromagnetic wave that takes attenuation (i.e., exponential decay) due to the absorption into account:(16)
In addition to absorption, we need to consider optical interference. Figure 3 shows the presence of reflected light from the interfaces between (1) air and the thin film (upper) and (2) the thin film and its substrate (lower). The reflected light waves will interfere either constructively or destructively, depending on the phase difference between the two waves. The path length difference between the two waves is . The paths and traverse a medium with a refractive index of , while path traverses a medium with a refractive index of . Therefore, the phase difference () is obtained by applying the different wavenumbers () as follows:
(17)
Considering the incident and transmitted angles, we obtain and , which lead to
(18)
By incorporating Snell’s law (),
(19)
Using Equation (19) and , we arrive at
(20)
The plane wave, when considering the phase difference, becomes
(21)
Equation (21) indicates that the phase difference can be imposed by multiplying . To account for the optical interference, we need to find the superposition of the light waves which are reflected from both upper and lower boundaries. The primary wave (i.e., that directly reflected from the film surface) becomes , which is the reflection coefficient determined by the Fresnel equations for the boundary between the air and the thin film. The secondary wave, which is transmitted at the boundary between the air and the thin film, is then reflected from the substrate and transmitted at the boundary between the thin film and air and can be written by imposing the coefficients corresponding to each stage as follows:
(22)
As each additional order is considered, the wave undergoes two reflections (r10 and r12) and acquires a phase difference. Each subsequent term is multiplied by a factor of . The total reflected wave (E012) can be expressed as the sum of the primary wave (E1), the secondary wave (E2), the third wave (E3), and so on:
(23)
thus represents the reflection coefficient obtained when considering the optical interference. Using the formula for the sum of an infinite geometric series, we can simply write Equation (23) as
(24)
Using and , obtained by Equations (4), (5), (8), and (9), can be reduced further [25]:
(25)
Using Equation (25), the reflection coefficient for the air/thin film/substrate structure (Figure 3) can be obtained. Based on Equation (25), additional layers can be incorporated. When an additional layer is introduced (e.g., the buffer layer in an air/thin film/buffer layer/substrate structure), the reflection coefficient is derived. To determine , Equation (25) is first applied to compute :
(26)
By substituting , obtained from Equation (26), into the term in Equation (25), the expression for is obtained as follows:
(27)
This recursive approach, based on Equation (25), allows us to determine the reflection coefficient of a multilayer structure with an arbitrary number of layers. Using Equations (10) and (27), we can obtain the reflectance of multilayered structures for a specific single wavelength. To simulate the color, we need to obtain the reflectance spectrum in the visible range, which thus requires us to use different refractive indices and extinction coefficients depending on the wavelength (i.e., dispersion) for the visible range.
2.1.3. Color Simulation
To convert a reflectance spectrum to a color (i.e., sRGB value), the spectrum is first mapped to the CIE 1931 XYZ color space using formulas based on color matching functions [26]:
(28)
(29)
(30)
(31)
where is the wavelength and , , and are the color-matching functions, which are numerical descriptions of the chromatic and tristimulus response of cone cells [27]. The parameters and are the spectral reflectance and standard illuminant, respectively. In this study, we employed a CIE 1931 2° standard observer and D65 white reference as the color matching functions and the reference illuminant, respectively [28,29]. The CIE 1931 2° standard observer quantifies human color perception. Due to the distribution of cones in the human eye, the tristimulus values of colors vary depending on the observer’s field of view. The standard observer model was defined based on stimuli subtending a 2° visual angle, corresponding to the foveal region of the retina. The D65 white reference is the standard daylight illuminant, positioned using CIE values. The values X, Y, and Z can be converted to either CIE xy values or sRGB values. For CIE xy values,(32)
(33)
where x and y are the coordinates of the CIE 1931 color space chromaticity diagram, which is widely used to specify colors in practice. CIE XYZ coordinates are linearly transformed to sRGB coordinates using the following conversion matrix [30]:(34)
where r, g, and b are linear RGB. The sRGB color space defines its values in a nonlinear form that corresponds to human visual perception. However, the conversion from XYZ to RGB derived above produces linear RGB values. To obtain sRGB values, a gamma-compressed transformation is used [30]:(35)
where and . Since the values obtained using Equation (35) are in the nominal range (0–1), we multiply each component by 255 to represent conventional sRGB values in the range of 0–255.2.2. Python Coding
Based on the aforementioned theoretical background, we developed a Python 3.9.13 code to simulate the colors of multilayered thin films. We imported libraries—NumPy, pandas, SciPy, and matplotlib—for numerical computations, data manipulation, interpolation, and visualization, respectively. A wavelength array in the visible range with a fixed step size was generated using the arange function in the NumPy library (line 2 in Listing 1). To use the dispersion relation of each layer, we needed to import the refractive indices (n) and extinction coefficients (k) of the wavelengths in the array (lines 4–10 in Listing 1). Using this code, we aimed to simulate the color of SnO2 layers on a Si substrate, which has a native oxide layer; thus we used the n and k values of SnO2, SiO2, and Si from the literature [31,32,33,34]. We imported a standard illuminant (D65) and applied it to the obtained reflectance spectra to simulate the spectra from the sample, and the color-matching functions (CMFs) were imported and applied to extract RGB values from the simulated spectra (lines 35–42 in Listing 1). Here, missing n, k, and CMFs values, which are required but absent in the literature, can be estimated by interpolation using the interp1d function in the SciPy library. Since both the extinction coefficients and dispersion of air in the visible range are negligible, we set the refractive index of air as the constant, 1.0003, and defined the imaginary unit as j (lines 12–15 in Listing 1).
Listing 1. Python code for data preprocessing. |
The reflection coefficients of the p- and s-polarized waves and the reflectance are calculated in lines 1–10 and lines 11–45 of Listing 2, respectively. Here, N_j and N_k indicate the complex refractive indices of media j and k, respectively. ang_j and ang_k are the angles of incidence and transmission, respectively. In line 11 of Listing 2, wl, N_0, N_1, N_2, and N_3 are the wavelength and the complex refractive indices of the atmosphere (i.e., air), top, middle, and bottom layers (here the bottom layer corresponds to the substrate), respectively. d_1, and d_2 are the thicknesses of the top and middle layers, respectively. The mathematical expression corresponding to each line of code is given above it using the equation numbers described in Section 2.1 (Theoretical Background).
Listing 2. Python code used to calculate the reflection coefficients and the reflectance. |
By modifying the values of d_1, d_2, and the angle in line 11 of Listing 2, we can obtain reflectance spectra for various thicknesses and incident ray angles. To convert the reflectance spectra into RGB values, we apply Listing 3; in line 1, R_n is the calculated reflectance spectrum, while D65, CMFs_X, CMFs_Y, and CMFs_Z are the standard illuminant and the color matching functions for X, Y, and Z, respectively, which were imported and defined earlier (in line 38–42 of Listing 1).
Listing 3. Python code used to convert the reflectance spectrum to RGB values. |
3. Results and Discussion
To validate the Python code used for simulating the color of multilayered structures, we simulated the colors of three different oxide thin films (SiO2, SnO2, and ZnO) deposited on a Si substrate as a function of the films’ thickness and compared them with the literature and our own experiment. We first checked the color of the SiO2 thin film on a Si substrate using a function of the film thickness. It can be clearly seen that the obtained color chart is very consistent with the reported simulation result (Figure 4a) [35]. For the comparative analysis with our experiment, we fabricated a SnO2 film with a thickness gradient on a Si wafer using a sputtering method and measured its thicknesses by performing line profile measurements across a masked area using noncontact (tapping mode) atomic force microscopy (AFM; Icon-PT-PLUS, Bruker, Germany). For each point, three independent line profile measurements were taken to obtain average thickness and estimate the standard deviation. The step size of the line profile measurements was 1.5 μm, and the standard deviation of the thickness values was generally around 0.3 nm. The base pressure was ≈3 × 10−8 Torr, and the working pressure of 10 mTorr was adjusted using Ar (99.9999%). The films were grown at room temperature. We assumed the presence of a 2 nm thick native oxide layer (SiO2) between the film and substrate [36,37]. The two white dashed lines in Figure 4b indicate the experimentally measured thickness range (i.e., 76–385 nm). Although the thickness gradient of the experimental samples is nonlinear with respect to the position of each measured point, the colors and the thicknesses measured at the nine points are in good agreement with the theoretically predicted colors and thicknesses.
Figure 5a shows the experimental colors of a ZnO thin film with a thickness gradient on a Si substrate, taken at different incident angles (5, 30, and 45°). Similarly to the SnO2 thin film, we fabricated the ZnO film using the sputtering method and measured its thicknesses using AFM. As the incident angle increases, the overall color gradient shifts toward the thicker region, and as the thickness increases, the gradient becomes more pronounced. For instance, the color of the film changes from blue to magenta at 240 nm and from cyan to pink at 410 nm as the angle varies. To visualize the change in the color gradient, we simulated the colors of the ZnO thin film on a Si substrate, with a 2 nm thick SiO2 layer in between the two, as a function of the thickness and angle (Figure 5b). In this simulation, we used the n and k values of ZnO from the literature [38]. The simulation results obtained using the Python code describe the experimental color variations as depending on both thicknesses and incident angles. The three white boxes in Figure 5b represent the color ranges expected for the given thicknesses and angle variations in the experimental sample. The theoretical results clearly demonstrate the color transition seen due to the change in angle: from cyan to pink in the thicker regions and with an expansion of the yellow region in the thinner regions.
So far, we have obtained CIE XYZ values from simulated reflectance spectra and have converted them into sRGB for more intuitive color representations. Additionally, using Equations (32) and (33), we can transform CIE XYZ into CIE xy, allowing us to map the colors onto the CIE 1931 color space. This two-dimensional color space facilitates the identifying of color differences and supports a device- and observer-independent color representations suitable for various display and printing applications. Figure 6 shows the simulated colors of the SnO2 and ZnO thin films represented in both the sRGB and CIE xy color spaces. In the sRGB representation, the fact that the color variations are a function of thickness is easily observable. In contrast, the CIE xy representation provides insight into the color gamut achievable from a given material. For example, although the colors of SnO₂ and ZnO appear similar in the RGB color space, the CIE color space reveals that SnO₂ can be used to produce a slightly more vivid blue.
The results above demonstrate the ability of the Python code to create accurate reflectance spectra and corresponding color simulations. This code could be developed further to estimate the thickness of a film based on known n and k values, and vice versa. Moreover, recent advances in materials research have increasingly made use of AI-driven approaches, such as optics-based inverse design [39,40,41,42,43,44,45] and active learning [46]. In this context, this code, implemented in Python, which has been primarily used in AI research, serves as an accessible and easily modifiable, yet powerful, tool.
4. Conclusions
We demonstrated that our Python script can simulate the color of multilayered structures, with a detailed theoretical background and annotations provided for readers as well as users. The developed code was validated by applying it to well-known oxide materials (SnO2 and ZnO). We believe that anyone can adjust its structural and material parameters for their own system and research by following the instructions presented here. It is also worthwhile noting that the code generates a substantial quantity of data very rapidly—for example, simulating the 54,000 colors displayed in Figure 5b took merely 52 s (using CPU: Intel i7-1255U; GPU: Intel Iris Xe Graphics). This code can be further used and developed for various purposes—especially for machine learning, which requires a large amount of spectral and color data for model training.
Conceptualization, S.L.; methodology, D.L. and S.L.; validation, D.L.; formal analysis, D.L.; investigation, D.L.; writing—original draft preparation, D.L. and S.L.; writing—review and editing, D.L. and S.L.; visualization, D.L.; supervision, S.L.; project administration, S.L.; funding acquisition, S.L. All authors have read and agreed to the published version of the manuscript.
Not applicable.
Not applicable.
The data and their implementation details are available on GitHub (
The authors declare no conflicts of interest.
The following abbreviations are used in this manuscript:
SnO2 | Tin dioxide |
ZnO | Zinc oxide |
SiO2 | Silicon dioxide |
Si | Silicon |
RGB | Red, Green, and Blue |
AI | Artificial intelligence |
sRGB | Standard Red, Green, and Blue |
CIE | Commission International de l’Eclairage |
CMFs | Color-matching functions |
Footnotes
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Figure 1 Incident wave at angle θi hits the interface between two media with refractive indices n1 and n2: (a) the electric field (E) parallel to the plane of incidence (p-polarization) and (b) E perpendicular to the plane of incidence (s-polarization). E and the magnetic field (B) are mutually perpendicular (i.e., the propagation vector k = E × B). The subscripts i, r, and t represent the incident, reflected, and transmitted waves, respectively.
Figure 2 Wave propagation in a medium with (a) zero and (b) a nonzero extinction coefficient (k). When the extinction coefficient is zero (a), the amplitude (Et) remains constant. In contrast, with a nonzero extinction coefficient (b), the amplitude exhibits exponential decay.
Figure 3 Optical interference in a thin film. The interference between the reflected light from both the upper and lower boundaries needs to be taken into account. θi and θt are the angles of incidence and refraction, respectively. θi and θt are equal to the ∠ACD and half of the ∠ABC, respectively, according to the reflection law. d is the thickness of the film. Each arrow represents the path of a reflected or transmitted wave, and the adjacent coefficients
Figure 4 Comparison of simulated colors with literature and experiment: (a) SiO2 thin film on a Si substrate: simulated colors as a function of the SiO2 film thickness from literature (upper) [
Figure 5 Comparison of experimental colors and simulated colors of the ZnO thin film. (a) Experimental colors of the ZnO thin film on a Si substrate: photographs of the ZnO thin film with a thickness gradient taken from various angles (5, 30, and 45°). The dots marked on the Si substrate are approximately 1 cm apart and the values below each dot correspond to the thicknesses obtained from line profile measurements nearby. (b) Simulated colors of the ZnO thin film on a Si substrate, using the Python code, as a function of the thickness and incident angle. The thickness of the native SiO2 layer was set to 2 nm in the simulation. The three white dashed boxes correspond to the color ranges expected from the experimental samples (thickness range: 200–410 nm; incident angle: 5, 30, and 45°).
Figure 6 Simulated color gamuts of SnO2 and ZnO thin films on a Si substrate, presented as sRGB (upper, colors as a function of thickness) and CIE 1931 xy chromaticity diagrams (lower): (a) SnO2 and (b) ZnO. The thickness of the films was simulated in the range of 0 to 2000 nm, with an incident angle of zero. The points in the CIE xy diagram correspond to the obtained sRGB values demonstrated in the color bar.
You have requested "on-the-fly" machine translation of selected content from our databases. This functionality is provided solely for your convenience and is in no way intended to replace human translation. Show full disclaimer
Neither ProQuest nor its licensors make any representations or warranties with respect to the translations. The translations are automatically generated "AS IS" and "AS AVAILABLE" and are not retained in our systems. PROQUEST AND ITS LICENSORS SPECIFICALLY DISCLAIM ANY AND ALL EXPRESS OR IMPLIED WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES FOR AVAILABILITY, ACCURACY, TIMELINESS, COMPLETENESS, NON-INFRINGMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Your use of the translations is subject to all use restrictions contained in your Electronic Products License Agreement and by using the translation functionality you agree to forgo any and all claims against ProQuest or its licensors for your use of the translation functionality and any output derived there from. Hide full disclaimer
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/). Notwithstanding the ProQuest Terms and Conditions, you may use this content in accordance with the terms of the License.
Abstract
Physical insight into a material can be first gained by its color, as the reflectance spectrum of an object reflects its microstructure and complex refractive indices. Here, we present a comprehensive overview of electrodynamics and optics related to reflectance spectra and color. We provide an open-source Python code for simulating reflectance spectra and extracting color values. The validity and applicability of the code are demonstrated through a comparative analysis with both the literature and experimental data. For SnO2 and ZnO thin films deposited on SiO2/Si substrates using rf sputtering, the Python code and simulation predict color variations with the film thickness and effectively capture their angular dependence. This code will help in understanding and making use of color-related phenomena. It can be further used and developed for various purposes, particularly machine learning, which requires extensive spectral and color data for model training.
You have requested "on-the-fly" machine translation of selected content from our databases. This functionality is provided solely for your convenience and is in no way intended to replace human translation. Show full disclaimer
Neither ProQuest nor its licensors make any representations or warranties with respect to the translations. The translations are automatically generated "AS IS" and "AS AVAILABLE" and are not retained in our systems. PROQUEST AND ITS LICENSORS SPECIFICALLY DISCLAIM ANY AND ALL EXPRESS OR IMPLIED WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES FOR AVAILABILITY, ACCURACY, TIMELINESS, COMPLETENESS, NON-INFRINGMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Your use of the translations is subject to all use restrictions contained in your Electronic Products License Agreement and by using the translation functionality you agree to forgo any and all claims against ProQuest or its licensors for your use of the translation functionality and any output derived there from. Hide full disclaimer