Skip to content

Instantly share code, notes, and snippets.

@mafshin
mafshin / nicegui-charts.py
Created March 16, 2024 18:28
NiceGUI Highcharts Sample
from nicegui import ui
def update():
chart.options['chart']['type'] = chart_type.value
chart.update()
chart_type = ui.radio(['line', 'area', 'bar', 'column'], value='column', on_change=update).props('inline')
grades = {'Ali': [12, 16, 18, 20],
'Maryam': [19, 20, 18, 15],
@mafshin
mafshin / p40-solution-visualization-animation.py
Created December 25, 2023 11:18
Interactive Solution Drawing of Problem 40 with NiceGUI
from enum import Enum
from nicegui import ui
from nicegui.elements.html import Html
from nicegui.functions.timer import Timer
Direction = Enum('Direction', ['Up', 'Down', 'Right', 'Left'])
class Position():
def __init__ (self, x, y):
@mafshin
mafshin / p40-draw-solution-nicegui.py
Created December 24, 2023 20:25
Draw Solution of Problem 40 with NiceGUI
from enum import Enum
from nicegui import ui
Direction = Enum('Direction', ['Up', 'Down', 'Right', 'Left'])
def build_svg(grid_size, cell_size) -> str:
width = cell_size * grid_size + 1
height = cell_size * grid_size + 1
@mafshin
mafshin / nicegui-3d-scene-road-car.py
Created November 12, 2023 14:00
3D Scene NiceGUI Move Car in Road
import math
from nicegui import app, ui
class SceneState():
def __init__(self) -> None:
self.stage = ''
self.road_parts = []
self.light_poles = []
self.car = None
self.refresh_rate = 20
@mafshin
mafshin / nicegui-3d-scene-movement.py
Created November 11, 2023 10:59
3D Scene Move Camera and Objects in NiceGUI
from nicegui import app, ui
refresh_rate = 60
def play():
timer.active = not timer.active
def update_scene():
movement = 1
delta = movement / refresh_rate
@mafshin
mafshin / nicegui-3d-scene.py
Created November 4, 2023 13:55
3D Scene with boxes with NiceGUI
import random
from nicegui import events, ui
from nicegui.events import KeyEventArguments
def handle_click(e: events.SceneClickEventArguments):
hit = e.hits[0]
name = hit.object_name or hit.object_id
notify(f'You clicked on the {name} at ({hit.x:.2f}, {hit.y:.2f}, {hit.z:.2f})')
clicked_box = next(filter(lambda x: x.name == name, scene_state.boxes), None)
if clicked_box:
@mafshin
mafshin / draw-dolly.py
Created December 29, 2022 18:15
Draw Dolly with Strawberry
import math
from graphics import *
from typing import List
def main(size):
win = GraphWin("My Circle", size, size)
center = size / 2
radius = 100
@mafshin
mafshin / earthquake-wave-analysis.cs
Last active December 10, 2022 08:02
Earthquake waves analysis by Chat GPT
/// Question:
/// Write a C# code to analysis the multiple waves of an earthquake signal
/// Chat GPT Answer:
using System;
using System.Collections.Generic;
namespace EarthquakeAnalysis
@mafshin
mafshin / OrderBook.cs
Created December 10, 2022 07:15
Order Book Implementation by Chat GPT
using System;
using System.Collections.Generic;
using System.Linq;
namespace Trading
{
// A class representing a single order in the order book
public class Order
{
public int Id { get; set; }
@mafshin
mafshin / Parser.py
Created December 10, 2022 05:55
A simple parser in Python by Chat GPT
import operator
# Define a dictionary of supported operations and their corresponding
# functions from the operator module
operators = {
"+": operator.add,
"-": operator.sub,
"*": operator.mul,
"/": operator.truediv,
}