<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>نوشته های lordtec</title><link>https://virgool.ir/feed/@sourcecity</link><description></description><language>fa</language><pubDate>2026-11-11 10:18:52</pubDate><image><url>https://virgool.ir/images/default-avatar.jpg</url><title>lordtec</title><link>https://virgool.ir/@sourcecity</link></image><item><title>ماشین حساب مهندسی پیشرفته با رسم نمودار دوبعدی و سه بعدی</title><link>https://virgool.ir/@sourcecity/ماشین-حساب-مهندسی-پیشرفته-با-رسم-نمودار-دوبعدی-و-سه-بعدی-endvzcn5mvgp</link><description>ماشین حساب مهندسی پیشرفته با رسم نمودار دوبعدی و سه بعدی#خب اولین کارمون رایگان در اختیار شما&#xA;# scientific_calculator_3d.py&#xA;&#34;&#34;&#34;&#xA;ماشینحساب مهندسی با رسم 2D و 3D (z = f(x,y))&#xA;- امنسازی eval با توابع math و numpy محدود&#xA;- رسم دوبعدی f(x) و رسم سهبعدی z=f(x,y) با matplotlib (Axes3D)&#xA;&#34;&#34;&#34;&#xA;&#xA;import tkinter as tk&#xA;from tkinter import ttk, filedialog, messagebox&#xA;import math&#xA;import numpy as np&#xA;import matplotlib&#xA;matplotlib.use(&#34;TkAgg&#34;)&#xA;from matplotlib.figure import Figure&#xA;from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg&#xA;from mpl_toolkits.mplot3d import Axes3D  # noqa: F401&#xA;import sympy as sp&#xA;import traceback&#xA;&#xA;# --- امنسازی محیط eval ---&#xA;_safe_dict = {}&#xA;for name in dir(math):&#xA;    if not name.startswith(&#34;_&#34;):&#xA;        _safe_dict[name] = getattr(math, name)&#xA;# allowed numpy functions (limited)&#xA;_np_allowed = [&#34;sin&#34;, &#34;cos&#34;, &#34;tan&#34;, &#34;arcsin&#34;, &#34;arccos&#34;, &#34;arctan&#34;,&#xA;               &#34;sinh&#34;, &#34;cosh&#34;, &#34;tanh&#34;, &#34;exp&#34;, &#34;log&#34;, &#34;log10&#34;,&#xA;               &#34;sqrt&#34;, &#34;abs&#34;, &#34;pi&#34;, &#34;e&#34;, &#34;sin&#34;, &#34;cos&#34;]&#xA;for name in _np_allowed:&#xA;    if hasattr(np, name):&#xA;        _safe_dict[&#34;np_&#34;+name] = getattr(np, name)&#xA;&#xA;def safe_eval(expr, local_vars=None):&#xA;    if local_vars is None:&#xA;        local_vars = {}&#xA;    expr = expr.replace(&#34;^&#34;, &#34;**&#34;)&#xA;    env = dict(_safe_dict)&#xA;    # expose math names directly&#xA;    for name in dir(math):&#xA;        if not name.startswith(&#34;_&#34;):&#xA;            env[name] = getattr(math, name)&#xA;    # limited numpy as dict under &#39;np&#39;&#xA;    limited_np = {}&#xA;    for name in set(_np_allowed):&#xA;        if hasattr(np, name):&#xA;            limited_np[name] = getattr(np, name)&#xA;    limited_np[&#34;pi&#34;] = np.pi&#xA;    limited_np[&#34;e&#34;] = np.e&#xA;    env[&#34;np&#34;] = limited_np&#xA;    env.update(local_vars)&#xA;    env[&#34;__builtins__&#34;] = {}&#xA;    return eval(expr, env)&#xA;&#xA;# --- GUI ---&#xA;class ScientificCalculator3D(tk.Tk):&#xA;    def __init__(self):&#xA;        super().__init__()&#xA;        self.title(&#34;ماشینحساب مهندسی 2D/3D&#34;)&#xA;        self.geometry(&#34;1200x780&#34;)&#xA;        self.resizable(True, True)&#xA;&#xA;        self.expr_var = tk.StringVar()&#xA;        self.result_var = tk.StringVar()&#xA;        self.plot_expr = tk.StringVar(value=&#34;sin(x)&#34;)&#xA;        self.plot3_expr = tk.StringVar(value=&#34;sin(x*y)&#34;)&#xA;        self.history = []&#xA;&#xA;        self._build_ui()&#xA;&#xA;    def _build_ui(self):&#xA;        top = ttk.Frame(self)&#xA;        top.pack(side=&#34;top&#34;, fill=&#34;x&#34;, padx=8, pady=6)&#xA;        entry = ttk.Entry(top, textvariable=self.expr_var, font=(&#34;Consolas&#34;, 18))&#xA;        entry.pack(side=&#34;left&#34;, fill=&#34;x&#34;, expand=True, padx=(0,6))&#xA;        entry.bind(&#34;&lt;Return&gt;&#34;, lambda e: self.evaluate())&#xA;        ttk.Label(top, textvariable=self.result_var, font=(&#34;Consolas&#34;, 14)).pack(side=&#34;right&#34;)&#xA;&#xA;        main = ttk.Frame(self)&#xA;        main.pack(fill=&#34;both&#34;, expand=True)&#xA;&#xA;        left = ttk.Frame(main)&#xA;        left.pack(side=&#34;left&#34;, fill=&#34;y&#34;, padx=6, pady=6)&#xA;&#xA;        btns = [&#xA;            [&#34;7&#34;,&#34;8&#34;,&#34;9&#34;,&#34;/&#34;,&#34;sqrt(&#34;],&#xA;            [&#34;4&#34;,&#34;5&#34;,&#34;6&#34;,&#34;*&#34;,&#34;^&#34;],&#xA;            [&#34;1&#34;,&#34;2&#34;,&#34;3&#34;,&#34;-&#34;,&#34;(&#34;],&#xA;            [&#34;0&#34;,&#34;.&#34;,&#34;%&#34;,&#34;+&#34;,&#34;)&#34;],&#xA;            [&#34;pi&#34;,&#34;e&#34;,&#34;ans&#34;,&#34;C&#34;,&#34;DEL&#34;]&#xA;        ]&#xA;        for r,row in enumerate(btns):&#xA;            rf = ttk.Frame(left); rf.pack(pady=2)&#xA;            for txt in row:&#xA;                ttk.Button(rf, text=txt, width=6, command=lambda t=txt: self.on_button(t)).pack(side=&#34;left&#34;, padx=2)&#xA;&#xA;        func_frame = ttk.LabelFrame(left, text=&#34;Functions&#34;)&#xA;        func_frame.pack(pady=6)&#xA;        funcs = [&#34;sin(&#34;,&#34;cos(&#34;,&#34;tan(&#34;,&#34;asin(&#34;,&#34;acos(&#34;,&#34;atan(&#34;,&#34;sinh(&#34;,&#34;cosh(&#34;,&#34;tanh(&#34;,&#34;log(&#34;,&#34;log10(&#34;,&#34;exp(&#34;,&#34;abs(&#34;,&#34;factorial(&#34;]&#xA;        for i,fn in enumerate(funcs):&#xA;            ttk.Button(func_frame, text=fn.rstrip(&#34;(&#34;), width=8, command=lambda f=fn: self.on_button(f)).grid(row=i//3, column=i%3, padx=2, pady=2)&#xA;&#xA;        mid = ttk.Frame(main)&#xA;        mid.pack(side=&#34;left&#34;, fill=&#34;y&#34;, padx=6, pady=6)&#xA;        ttk.Button(mid, text=&#34;=&#34;, width=20, command=self.evaluate).pack(pady=6)&#xA;        ttk.Button(mid, text=&#34;Clear All&#34;, width=20, command=self.clear_all).pack(pady=6)&#xA;        hist_frame = ttk.LabelFrame(mid, text=&#34;History&#34;)&#xA;        hist_frame.pack(fill=&#34;both&#34;, expand=True)&#xA;        self.hist_list = tk.Listbox(hist_frame, height=12, width=30)&#xA;        self.hist_list.pack(side=&#34;left&#34;, fill=&#34;both&#34;, expand=True)&#xA;        ttk.Scrollbar(hist_frame, orient=&#34;vertical&#34;, command=self.hist_list.yview).pack(side=&#34;right&#34;, fill=&#34;y&#34;)&#xA;        self.hist_list.config(yscrollcommand=lambda *args: None)&#xA;        self.hist_list.bind(&#34;&lt;Double-Button-1&gt;&#34;, self.on_history_select)&#xA;&#xA;        right = ttk.Frame(main)&#xA;        right.pack(side=&#34;right&#34;, fill=&#34;both&#34;, expand=True, padx=6, pady=6)&#xA;&#xA;        # Plot 2D&#xA;        plot2 = ttk.LabelFrame(right, text=&#34;Plot 2D: f(x)&#34;)&#xA;        plot2.pack(fill=&#34;x&#34;, pady=4)&#xA;        ttk.Label(plot2, text=&#34;f(x)=&#34;).grid(row=0,column=0, sticky=&#34;w&#34;)&#xA;        ttk.Entry(plot2, textvariable=self.plot_expr, width=40).grid(row=0,column=1,columnspan=3, sticky=&#34;w&#34;)&#xA;        ttk.Label(plot2, text=&#34;xmin&#34;).grid(row=1,column=0, sticky=&#34;w&#34;)&#xA;        self.xmin_var = tk.StringVar(value=&#34;-10&#34;); ttk.Entry(plot2, textvariable=self.xmin_var, width=8).grid(row=1,column=1)&#xA;        ttk.Label(plot2, text=&#34;xmax&#34;).grid(row=1,column=2, sticky=&#34;w&#34;)&#xA;        self.xmax_var = tk.StringVar(value=&#34;10&#34;); ttk.Entry(plot2, textvariable=self.xmax_var, width=8).grid(row=1,column=3)&#xA;        ttk.Label(plot2, text=&#34;samples&#34;).grid(row=2,column=0, sticky=&#34;w&#34;)&#xA;        self.samples_var = tk.IntVar(value=1000); ttk.Entry(plot2, textvariable=self.samples_var, width=8).grid(row=2,column=1)&#xA;        ttk.Button(plot2, text=&#34;Plot 2D&#34;, command=self.plot_2d).grid(row=3,column=0, pady=6)&#xA;        ttk.Button(plot2, text=&#34;Save PNG&#34;, command=self.save_plot).grid(row=3,column=1, pady=6)&#xA;        ttk.Button(plot2, text=&#34;Clear&#34;, command=self.clear_plot).grid(row=3,column=2, pady=6)&#xA;&#xA;        # Plot 3D&#xA;        plot3 = ttk.LabelFrame(right, text=&#34;Plot 3D: z=f(x,y)&#34;)&#xA;        plot3.pack(fill=&#34;x&#34;, pady=4)&#xA;        ttk.Label(plot3, text=&#34;z=&#34;).grid(row=0,column=0, sticky=&#34;w&#34;)&#xA;        ttk.Entry(plot3, textvariable=self.plot3_expr, width=40).grid(row=0,column=1,columnspan=3, sticky=&#34;w&#34;)&#xA;        ttk.Label(plot3, text=&#34;xmin&#34;).grid(row=1,column=0, sticky=&#34;w&#34;)&#xA;        self.x3_min = tk.StringVar(value=&#34;-5&#34;); ttk.Entry(plot3, textvariable=self.x3_min, width=8).grid(row=1,column=1)&#xA;        ttk.Label(plot3, text=&#34;xmax&#34;).grid(row=1,column=2, sticky=&#34;w&#34;)&#xA;        self.x3_max = tk.StringVar(value=&#34;5&#34;); ttk.Entry(plot3, textvariable=self.x3_max, width=8).grid(row=1,column=3)&#xA;        ttk.Label(plot3, text=&#34;ymin&#34;).grid(row=2,column=0, sticky=&#34;w&#34;)&#xA;        self.y3_min = tk.StringVar(value=&#34;-5&#34;); ttk.Entry(plot3, textvariable=self.y3_min, width=8).grid(row=2,column=1)&#xA;        ttk.Label(plot3, text=&#34;ymax&#34;).grid(row=2,column=2, sticky=&#34;w&#34;)&#xA;        self.y3_max = tk.StringVar(value=&#34;5&#34;); ttk.Entry(plot3, textvariable=self.y3_max, width=8).grid(row=2,column=3)&#xA;        ttk.Label(plot3, text=&#34;samples (each axis)&#34;).grid(row=3,column=0, sticky=&#34;w&#34;)&#xA;        self.samples3_var = tk.IntVar(value=200); ttk.Entry(plot3, textvariable=self.samples3_var, width=8).grid(row=3,column=1)&#xA;        ttk.Button(plot3, text=&#34;Plot 3D&#34;, command=self.plot_3d).grid(row=4,column=0, pady=6)&#xA;        ttk.Button(plot3, text=&#34;Save PNG&#34;, command=self.save_plot).grid(row=4,column=1, pady=6)&#xA;&#xA;        # Figure&#xA;        fig_frame = ttk.Frame(right); fig_frame.pack(fill=&#34;both&#34;, expand=True)&#xA;        self.fig = Figure(figsize=(6,5), dpi=110)&#xA;        self.ax = self.fig.add_subplot(111)  # will be replaced with 3D when needed&#xA;        self.canvas = FigureCanvasTkAgg(self.fig, master=fig_frame)&#xA;        self.canvas.get_tk_widget().pack(fill=&#34;both&#34;, expand=True)&#xA;&#xA;        bottom = ttk.Frame(self); bottom.pack(side=&#34;bottom&#34;, fill=&#34;x&#34;, padx=8, pady=6)&#xA;        ttk.Label(bottom, text=&#34;برای توابع برداری از np.sin(x), np.cos(...) یا sin(...) استفاده کنید. برای 3D از متغیرهای x و y استفاده کنید.&#34;).pack(side=&#34;left&#34;)&#xA;&#xA;    # buttons&#xA;    def on_button(self, text):&#xA;        if text == &#34;C&#34;:&#xA;            self.expr_var.set(&#34;&#34;)&#xA;            return&#xA;        if text == &#34;DEL&#34;:&#xA;            s = self.expr_var.get(); self.expr_var.set(s[:-1]); return&#xA;        if text == &#34;ans&#34;:&#xA;            if self.history:&#xA;                last_ans = self.history[-1][1]&#xA;                self.expr_var.set(self.expr_var.get() + str(last_ans))&#xA;            return&#xA;        if text == &#34;pi&#34;:&#xA;            self.expr_var.set(self.expr_var.get() + &#34;pi&#34;); return&#xA;        if text == &#34;e&#34;:&#xA;            self.expr_var.set(self.expr_var.get() + &#34;e&#34;); return&#xA;        if text == &#34;%&#34;:&#xA;            self.expr_var.set(self.expr_var.get() + &#34;/100&#34;); return&#xA;        self.expr_var.set(self.expr_var.get() + text)&#xA;&#xA;    def clear_all(self):&#xA;        self.expr_var.set(&#34;&#34;); self.result_var.set(&#34;&#34;); self.history.clear(); self.hist_list.delete(0,tk.END); self.clear_plot()&#xA;&#xA;    def on_history_select(self, event):&#xA;        sel = self.hist_list.curselection()&#xA;        if not sel: return&#xA;        idx = sel[0]; expr, val = self.history[idx]&#xA;        self.expr_var.set(expr); self.result_var.set(str(val))&#xA;&#xA;    def evaluate(self):&#xA;        expr = self.expr_var.get().strip()&#xA;        if not expr: return&#xA;        try:&#xA;            val = safe_eval(expr)&#xA;            if isinstance(val, float) and abs(val - round(val)) &lt; 1e-12:&#xA;                val = int(round(val))&#xA;            self.result_var.set(str(val))&#xA;            self.history.append((expr, val)); self.hist_list.insert(tk.END, f&#34;{expr} = {val}&#34;)&#xA;        except Exception as e:&#xA;            messagebox.showerror(&#34;Evaluation error&#34;, f&#34;{e}\n\n{traceback.format_exc()}&#34;)&#xA;&#xA;    # plotting 2D&#xA;    def plot_2d(self):&#xA;        expr = self.plot_expr.get().strip()&#xA;        if not expr:&#xA;            messagebox.showwarning(&#34;Warning&#34;, &#34;عبارت تابع خالی است.&#34;); return&#xA;        try:&#xA;            xmin = float(self.xmin_var.get()); xmax = float(self.xmax_var.get())&#xA;            if xmax &lt;= xmin: raise ValueError(&#34;xmax باید بزرگتر از xmin باشد.&#34;)&#xA;            samples = int(self.samples_var.get()); samples = max(20, samples)&#xA;            x = np.linspace(xmin, xmax, samples)&#xA;            ef = expr.replace(&#34;^&#34;, &#34;**&#34;)&#xA;            repl_map = [&#34;sin&#34;,&#34;cos&#34;,&#34;tan&#34;,&#34;arcsin&#34;,&#34;arccos&#34;,&#34;arctan&#34;,&#34;sinh&#34;,&#34;cosh&#34;,&#34;tanh&#34;,&#34;exp&#34;,&#34;log&#34;,&#34;log10&#34;,&#34;sqrt&#34;,&#34;abs&#34;]&#xA;            for fn in repl_map:&#xA;                ef = ef.replace(fn+&#34;(&#34;, &#34;np.&#34;+fn+&#34;(&#34;)&#xA;            local_vars = {&#34;x&#34;: x}&#xA;            try:&#xA;                y = safe_eval(ef, local_vars=local_vars)&#xA;                if np.isscalar(y): y = np.full_like(x, float(y), dtype=float)&#xA;                else: y = np.array(y, dtype=float)&#xA;            except Exception:&#xA;                y = []&#xA;                for xv in x:&#xA;                    try:&#xA;                        yv = safe_eval(expr, local_vars={&#34;x&#34;: float(xv)}); y.append(float(yv))&#xA;                    except Exception:&#xA;                        y.append(np.nan)&#xA;                y = np.array(y, dtype=float)&#xA;&#xA;            self.fig.clf()&#xA;            self.ax = self.fig.add_subplot(111)&#xA;            self.ax.plot(x, y, label=f&#34;f(x)={expr}&#34;)&#xA;            self.ax.set_xlim(xmin, xmax); self.ax.grid(True); self.ax.legend()&#xA;            self.canvas.draw()&#xA;        except Exception as e:&#xA;            messagebox.showerror(&#34;Plot error&#34;, str(e))&#xA;&#xA;    # plotting 3D&#xA;    def plot_3d(self):&#xA;        expr = self.plot3_expr.get().strip()&#xA;        if not expr:&#xA;            messagebox.showwarning(&#34;Warning&#34;, &#34;عبارت تابع خالی است.&#34;); return&#xA;        try:&#xA;            xmin = float(self.x3_min.get()); xmax = float(self.x3_max.get())&#xA;            ymin = float(self.y3_min.get()); ymax = float(self.y3_max.get())&#xA;            if xmax &lt;= xmin or ymax &lt;= ymin:&#xA;                raise ValueError(&#34;حدود x و y نامعتبرند.&#34;)&#xA;            samples = int(self.samples3_var.get()); samples = max(10, min(500, samples))&#xA;            xs = np.linspace(xmin, xmax, samples)&#xA;            ys = np.linspace(ymin, ymax, samples)&#xA;            X, Y = np.meshgrid(xs, ys)&#xA;            # prepare expression for numpy evaluation: replace functions to np.*&#xA;            ef = expr.replace(&#34;^&#34;, &#34;**&#34;)&#xA;            repl_map = [&#34;sin&#34;,&#34;cos&#34;,&#34;tan&#34;,&#34;arcsin&#34;,&#34;arccos&#34;,&#34;arctan&#34;,&#34;sinh&#34;,&#34;cosh&#34;,&#34;tanh&#34;,&#34;exp&#34;,&#34;log&#34;,&#34;log10&#34;,&#34;sqrt&#34;,&#34;abs&#34;]&#xA;            for fn in repl_map:&#xA;                ef = ef.replace(fn+&#34;(&#34;, &#34;np.&#34;+fn+&#34;(&#34;)&#xA;            local_vars = {&#34;x&#34;: X, &#34;y&#34;: Y}&#xA;            try:&#xA;                Z = safe_eval(ef, local_vars=local_vars)&#xA;                Z = np.array(Z, dtype=float)&#xA;            except Exception:&#xA;                # fallback pointwise (slower)&#xA;                Z = np.empty_like(X, dtype=float)&#xA;                rows, cols = X.shape&#xA;                for i in range(rows):&#xA;                    for j in range(cols):&#xA;                        xv = float(X[i,j]); yv = float(Y[i,j])&#xA;                        try:&#xA;                            zv = safe_eval(expr, local_vars={&#34;x&#34;: xv, &#34;y&#34;: yv})&#xA;                            Z[i,j] = float(zv)&#xA;                        except Exception:&#xA;                            Z[i,j] = np.nan&#xA;&#xA;            # plot surface&#xA;            self.fig.clf()&#xA;            self.ax = self.fig.add_subplot(111, projection=&#39;3d&#39;)&#xA;            # choose a colormap and plot_surface&#xA;            surf = self.ax.plot_surface(X, Y, Z, cmap=&#39;viridis&#39;, linewidth=0, antialiased=True)&#xA;            self.fig.colorbar(surf, ax=self.ax, shrink=0.6)&#xA;            self.ax.set_xlabel(&#39;x&#39;); self.ax.set_ylabel(&#39;y&#39;); self.ax.set_zlabel(&#39;z&#39;)&#xA;            self.ax.set_title(f&#34;z = {expr}&#34;)&#xA;            self.canvas.draw()&#xA;        except Exception as e:&#xA;            messagebox.showerror(&#34;3D Plot error&#34;, f&#34;{e}\n\n{traceback.format_exc()}&#34;)&#xA;&#xA;    def save_plot(self):&#xA;        path = filedialog.asksaveasfilename(defaultextension=&#34;.png&#34;, filetypes=[(&#34;PNG&#34;,&#34;*.png&#34;)])&#xA;        if not path: return&#xA;        try:&#xA;            self.fig.savefig(path)&#xA;            messagebox.showinfo(&#34;Saved&#34;, f&#34;Saved plot to {path}&#34;)&#xA;        except Exception as e:&#xA;            messagebox.showerror(&#34;Save error&#34;, str(e))&#xA;&#xA;    def clear_plot(self):&#xA;        self.fig.clf()&#xA;        self.ax = self.fig.add_subplot(111)&#xA;        self.ax.set_title(&#34;Plot&#34;); self.ax.grid(True)&#xA;        self.canvas.draw()&#xA;&#xA;if __name__ == &#34;__main__&#34;:&#xA;    app = ScientificCalculator3D()&#xA;    app.mainloop()&#xA;</description><category>lordtec</category><author>lordtec</author><pubDate>Thu, 30 Oct 2025 22:15:34 +0330</pubDate></item><item><title>بسم الله الرحمن الرحیم</title><link>https://virgool.ir/@sourcecity/بسم-الله-الرحمن-الرحیم-onx7lh78kxcw</link><description>مرجع تخصصی سورس کدهای آماده پایتونبه دنیای بی‌نهایت پایتون خوش آمدید! آیا شما هم از آن دسته توسعه‌دهندگانی هستید که برای پیاده‌سازی ایده‌های بزرگ خود به دنبال یک نقطه شروع قوی و مطمئن می‌گردید؟ وبلاگ سورس سیتی اینجاست تا مسیر کدنویسی را برای شما کوتاه و لذت‌بخش کند.در اینجا، ما باور داریم که زمان باارزش‌ترین دارایی شماست. به همین دلیل، کتابخانه‌ای گسترده و منحصربه‌فرد از سورس کدهای آماده، حرفه‌ای و بهینه‌شده پایتون را گردآوری کرده‌ایم. چرا سورس سیتی؟صرفه‌جویی در زمان: هفته‌ها زمان توسعه را به دقیقه کاهش دهید.کدهای باکیفیت: تمام سورس کدها با بهترین پرکتیس‌ها نوشته شده، کامنت‌گذاری شده و مستندسازی گردیده‌اند.ایده‌های خود را از مرحله تصور به مرحله اجرا درآورید. برای کشف دنیایی از کدهای کاربردی، به بلاگ ما سر بزنید، از آموزش‌های ما بهره ببرید و پروژه بعدی خود را با بهترین سورس کدها کلید بزنید.سورس سیتی: کد بزن، رشد کن، درآمد داشته باش!</description><category>lordtec</category><author>lordtec</author><pubDate>Thu, 09 Oct 2025 17:22:41 +0330</pubDate></item></channel></rss>