Skip to content

Instantly share code, notes, and snippets.

View beotiger's full-sized avatar
💭
Happiness

Andrey Tzar beotiger

💭
Happiness
View GitHub Profile
"""Get the value always between minv and maxv"""
clamp = lambda value, minv, maxv: max(min(value, maxv), minv)
@beotiger
beotiger / vector2d.py
Last active April 11, 2024 10:46
Vector2d class in Python
import math
import random
class Vector:
""" Compact Vector2d class
@2024_03_24_1520-2024_04_11_1345 updated by Beotiger
If no arguments in create given returns null Vector instance
Methods add, sub, mul, div, normalize, mag, magSq, limit,
@beotiger
beotiger / install.bat
Last active April 10, 2024 06:38
Installing with several ways to elevate privileges
@ECHO off
REM @2024_04_09_0912 by Beotiger
REM Installing compiled tkscrsavers.scr to Windows\System32 folder
REM You should run this file as Administrator or it will not work.
REM See README.md for details
REM NET FILE 1>NUL 2>NUL & IF ERRORLEVEL 1 (ECHO You must right-click and select "Run as administrator" to run this batch. & ECHO. & PAUSE & EXIT /B)
@beotiger
beotiger / uac.bat
Last active April 9, 2024 08:49
Windows(tm) elevated command prompt with current directory set (batch file)
@ECHO OFF
::
:: Restart as Admin if not already running as Admin
::
(NET session >nul 2>&1)||(PowerShell start """%~fn0""" -verb RunAs & Exit /B)
REM ... proceed here with admin rights ...
ECHO You are admin!
ECHO.
@beotiger
beotiger / mondrian.py
Last active April 6, 2024 12:59
Mondrian-Inspired Generative Art in Python using sparse matrix
class Block:
def __init__(self, c, main):
self.c = c
self.main = main
self.colRange = self.randomLengthGen(main.cols + 1)
self.rowRange = self.randomLengthGen(main.rows + 1)
self.block = dict(
((i, j), Cell(i * main.wx, j * main.hx, main.wx, main.hx, j)) for i in range(self.colRange[0], self.colRange[1]) for j in range(self.rowRange[0], self.rowRange[1])
)
@beotiger
beotiger / canvas_pixels.py
Created April 5, 2024 18:24
Setting pixels on Tkinter Canvas
# From: https://stackoverflow.com/questions/12284311/python-tkinter-how-to-work-with-pixels
from tkinter import Tk, Canvas, PhotoImage, mainloop
from math import sin
WIDTH, HEIGHT = 640, 480
window = Tk()
canvas = Canvas(window, width=WIDTH, height=HEIGHT, bg="#000000")
canvas.pack()
img = PhotoImage(width=WIDTH, height=HEIGHT)
@beotiger
beotiger / a_demo.pyw
Created April 3, 2024 20:44
Triada wars with triangles
#Import the required libraries
from tkinter import *
import math
WIDTH, HEIGHT = 500, 500
class Vector:
""" Compact but powerful Vector2d class
@2024_03_24_1520 updated by Beotiger """
def __init__(self, x=0.0, y=0.0): self.x = x; self.y = y
@beotiger
beotiger / dnd.py
Created April 3, 2024 20:41
Drag and drop in tkinter Canvas
import tkinter as tk
def drag_start(event):
widget = event.widget
widget._drag_start_x = event.x
widget._drag_start_y = event.y
def drag_motion(event):
widget = event.widget
x = widget.winfo_x() - widget._drag_start_x + event.x
@beotiger
beotiger / linepoints.py
Created April 3, 2024 20:38
crazy lines in Python
#Import the required libraries
from tkinter import *
import math
WIDTH, HEIGHT = 500, 500
class GradientColor:
@staticmethod
def hex_to_RGB(hex):
""" "#FFFFFF" -> [255,255,255] """
@beotiger
beotiger / asteroids.py
Created April 3, 2024 20:37
Triangle with rotation
from tkinter import *
# from ship import *
import math
class Ship:
def centroid(self):
return 1 / 3 * (self.x0 + self.x1 + self.x2), 1 / 3 * (self.y0 + self.y1 + self.y2)
def __init__(self, canvas, x, y, width, height, turnspeed, acceleration=1):