#python

danie10@squeet.me

HP-1973 is a Python simulator app for the retro HP-45 calculator and 5 other HP ROMs, written by Sarah K. Marr

Exploded diagram showing explanations for the different parts off tye calculator simulator e.g. the display shows the calculator type, ROM version, the stack, simulator settings, internal values, etc.
The app was written in Python and started out for the HP-45 (ROM is included) but finally included also the HP-35 and the HP-80, as well as three others. For macOS and Windows you could just run the included executables, or with the Python code, this will run fine on Linux if you have Python installed. Nice thing is that you can also modify or tweak the Python code if you wish.

As she states, this is not a “how to learn HP or RPN” but there is a lot of included online help, and the original HP manuals are available online.

What an amazing resource for anyone wanting to learn more about the inner workings of these legendary calculators.

See https://sarahkmarr.com/retrohp1973.html
#Blog, #HP1973, #HP45, #opensource, #python, #technology

mkwadee@diasp.eu

The other day, a non-technical colleague said to me, "You're a #Python expert, aren't you?" I felt I had to correct him since I have only dabbled with the #language and I said that I'm more accustomed to scientific programming in #C or #Fortran. He looked a bit bemused, in hindsight, I'm not surprised as I've never talked to him about computing before. He then said "No, I meant #MontyPython." Well, modesty aside, I said that I'm probably the most expert person there and so our conversation continued on a more humorous subject.

tord_dellsen@diasp.eu

#JustForFun i created these Sierpinski triangles using #Python's #turtle module | #maths #math #programming #fractals #recursion

import logging
import turtle
import time

SPEED_INT = 5  # 1-10 where 0 is as fast as possible
logging.basicConfig(level=logging.DEBUG)

DISPLAY_WIDTH = 1620
# Turtle setup
screen = turtle.getscreen()
t = turtle.getturtle()
turtle.title("Sierpinski Triangle (using turtle)")
t.shape("turtle")
t.speed(SPEED_INT)
turtle.setheading(0)
# ..set start position
t.penup()
turtle.setx(-DISPLAY_WIDTH // 2)
turtle.sety(-450)
t.pendown()
start_pos = t.pos()

time.sleep(1)


def draw_recursive(i_level: int, i_direction: int):
    """Level 1 is the starting i_starting_level (0 doesn't exist)"""
    logging.debug(f"{i_level * '-'} draw_recursive called with level {i_level}")
    if i_level == 1:
        t.forward(distance)
        return
    draw_recursive(i_level - 1, -i_direction)
    t.left(i_direction * 60)
    draw_recursive(i_level - 1, i_direction)
    t.left(i_direction * 60)
    draw_recursive(i_level - 1, -i_direction)


distance = 0


def draw_(i_starting_level: int, i_pen_color_channel: float = 0.0):
    logging.debug(f"==== draw_ called with starting level {i_starting_level} ====")
    t.penup()
    t.setpos(start_pos)
    t.setheading(0)
    t.pendown()

    global distance
    distance = 1024 / (2 ** (i_starting_level - 1))
    distance = min(100, distance)

    pen_size = distance // 2
    if pen_size < 1:
        raise Exception("Pen size is smaller than one")
    t.pensize(distance // 2)

    t.pencolor((i_pen_color_channel,) * 3)

    if i_starting_level % 2 == 0:
        direction = 1
    else:
        direction = -1
    draw_recursive(i_starting_level, direction)


# draw_(9)

pen_color_channel = 0.8
for i_starting_level in range(5, 8):
    if pen_color_channel < 0:
        raise Exception("Pen color channel smaller than zero")
    draw_(i_starting_level, pen_color_channel)
    pen_color_channel -= 0.2

t.hideturtle()
turtle.done()
tord_dellsen@diasp.eu

#JustForFun i created these #KochSnowflake/s using #Python's #turtle module | #maths #math #programming #fractals #recursion

import logging
import turtle
import time

SPEED_INT = 4  # 1-10 where 0 is as fast as possible
logging.basicConfig(level=logging.DEBUG)

DISPLAY_WIDTH = 1620
# Turtle setup
screen = turtle.getscreen()
t = turtle.getturtle()
turtle.title("Koch Snowflake")
t.shape("turtle")
t.speed(SPEED_INT)
turtle.setheading(0)
# ..set start position
t.penup()
turtle.setx(-DISPLAY_WIDTH // 2)
turtle.sety(-400)
t.pendown()
start_pos = t.pos()

time.sleep(1)


def draw_recursive(i_level: int):
    """Level 1 is the starting level (0 doesn't exist)
    , i_unit_distance: int
    """
    if i_level == 1:
        t.forward(distance)
        return
    draw_recursive(i_level - 1)
    t.left(60)
    draw_recursive(i_level - 1)
    t.right(120)
    draw_recursive(i_level - 1)
    t.left(60)
    draw_recursive(i_level - 1)


def get_distance(i_levels_to_draw):
    distance_ = DISPLAY_WIDTH / (3 ** (i_levels_to_draw - 1))
    return distance_


pen_color_channel = 0.9
pen_size = 16

for i in range(2, 7):
    t.penup()
    t.setpos(start_pos)
    t.pendown()

    levels_to_draw = i
    distance = get_distance(levels_to_draw)
    if pen_size < 1:
        raise Exception("Pen size smaller than one")
    t.pensize(pen_size)
    pen_size = pen_size // 2
    if pen_color_channel < 0:
        raise Exception("Pen color channel smaller than zero")
    t.pencolor((pen_color_channel,) * 3)
    pen_color_channel -= 0.2

    draw_recursive(levels_to_draw)

t.hideturtle()
turtle.done()

tord_dellsen@diasp.eu

#JustForFun i created this Hilbert space-filling curve using #Python's #turtle module | #maths #math #programming

import logging
import random
import turtle
import time

SPEED_INT = 5  # 1-10 where 0 is as fast as possible
UNIT_DISTANCE = 30
logging.basicConfig(level=logging.DEBUG)

# Turtle setup
screen = turtle.getscreen()
t = turtle.getturtle()
turtle.title("Hilbert Space-filling Curve")
t.shape("turtle")
t.speed(SPEED_INT)
t.pensize(5)
t.pencolor((0, 0, 0))
t.penup()
turtle.setx(-500)
turtle.sety(-450)
t.pendown()
start_pos = t.pos()

time.sleep(1)

CW = 1
CCW = -1


def get_angle():
    fuzzyness = random.choice(range(0, 2))
    # degrees = 90 + fuzzyness
    degrees = 90
    return degrees


color_ = (0, 0, 0)

DIRECTION_UP = True
DIRECTION_DOWN = False

color_change_direction = (DIRECTION_UP, DIRECTION_UP, DIRECTION_UP)


def change_color():
    global color_
    global color_change_direction
    index_to_change = random.choice(range(0, 3))
    channel = color_[index_to_change]
    if color_change_direction:
        channel += 0.05
    else:
        channel -= 0.05
    if channel > 1.0:
        color_change_direction = not color_change_direction
        channel = 1.0
    elif channel < 0.0:
        color_change_direction = not color_change_direction
        channel = 0.0
    new_color = turtle.pencolor()
    new_color_list = list(new_color)
    new_color_list[index_to_change] = channel
    color_ = tuple(new_color_list)
    turtle.pencolor(color_)


def draw_recursive(i_direction: int, i_level: int):
    """Level 1 is the starting level (0 doesn't exist)"""
    if i_level == 1:
        change_color()

    def right_forward():
        t.right(i_direction * get_angle())
        t.forward(UNIT_DISTANCE)

    def forward_right():
        t.forward(UNIT_DISTANCE)
        t.right(i_direction * get_angle())

    if i_level > 1: draw_recursive(-i_direction, i_level - 1)
    if i_level % 2 == 0:
        right_forward()
    else:
        forward_right()
    if i_level > 1: draw_recursive(i_direction, i_level - 1)
    if i_level % 2 == 0:
        t.right(-i_direction * get_angle())
        t.forward(UNIT_DISTANCE)
        t.right(-i_direction * get_angle())
    else:
        t.forward(UNIT_DISTANCE)
    if i_level > 1: draw_recursive(i_direction, i_level - 1)
    if i_level % 2 == 0:
        forward_right()
    else:
        right_forward()
    if i_level > 1: draw_recursive(-i_direction, i_level - 1)


turtle.setheading(90)
draw_recursive(CW, 5)

t.hideturtle()
turtle.done()

tord_dellsen@diasp.eu

#JustForFun i created this #fibonacci spiral using #Python's #turtle module

import logging
import turtle
import time

SPEED_INT = 10  # 1-10 where 0 is as fast as possible
DEFAULT_HEADING = 180
DEFAULT_SCALE = 2.5
START_X = -480
START_Y = -230
logging.basicConfig(level=logging.DEBUG)

# Turtle setup
screen = turtle.getscreen()
# screen.screensize(1900, 1000)
t = turtle.getturtle()
turtle.title("Fibonacci spiral")
t.shape("turtle")
t.speed(SPEED_INT)
t.pensize(3)
center_pos = t.pos()

turtle.setheading(DEFAULT_HEADING)
t.penup()
turtle.setx(START_X)
turtle.sety(START_Y)
t.pendown()
start_pos = t.pos()

time.sleep(1)


def fibonacci(n):
    if n < 0:  Exception("Fibonacci function cannot take negative numbers")
    if n == 0: return 0
    if n == 1: return 1
    return fibonacci(n - 1) + fibonacci(n - 2)


def draw_fib_spiral(
        i_scale: float = DEFAULT_SCALE,
        i_color: str = "black",
        i_nr_of_circles: int = 5,
        i_write_fib_nr: bool = True):
    t.pencolor(i_color)
    t.penup()
    t.setpos(start_pos)
    turtle.setheading(DEFAULT_HEADING)
    t.pendown()
    for i in range(0, 4 * i_nr_of_circles):
        fibonacci_number = fibonacci(2 + i)
        radius = fibonacci_number * i_scale
        old_pos = t.pos()
        t.circle(radius, -90)
        new_pos = t.pos()

        old_pen_size = t.pensize()
        t.pensize(1)
        t.setpos(new_pos[0], old_pos[1])
        t.setpos(old_pos)
        t.setpos(old_pos[0], new_pos[1])
        t.setpos(new_pos)
        t.pensize(old_pen_size)
        delta_x = new_pos[0] - old_pos[0]
        delta_y = new_pos[1] - old_pos[1]

        if i_write_fib_nr:
            font_size = int(4 + i ** 1.7)
            font = ("Arial", font_size, "normal")
            t.pencolor((0, 0.7, 0))
            old_pos = t.pos()
            t.penup()
            t.setpos(old_pos[0] - delta_x / 2, old_pos[1] - delta_y / 2 - font_size / 2)
            t.write(fibonacci_number, font=font, align="center")
            t.setpos(old_pos)
            t.pendown()
            t.pencolor(i_color)


"""
COLOR_LIST = [
    (0, 0, 0),
    (1.0, 0, 0), (0, 1.0, 0), (0, 0, 1.0),
    (1.0, 0, 1.0), (1.0, 1.0, 0), (0, 1.0, 1.0),
    (0.5, 0, 0), (0, 0.5, 0), "pink"
]
for i in range(0, 9):
    ratio = 1 - 0.1 * i
    draw_fib_spiral(i_scale=ratio, i_color=COLOR_LIST[i])
"""
draw_fib_spiral(i_color="black", i_write_fib_nr=True)

t.hideturtle()
turtle.done()
danie10@squeet.me

In praise of Reverse Polish Notation (RPN) with Python or C

Bild/Foto
For whatever reason, RPN didn’t really succeed in the general marketplace, and you might wonder why it was ever a thing. The biggest reason is that RPN is very easy to implement compared to working through proper algebraic, or infix, notation. In addition, in the early years of computers and calculators, you didn’t have much to work with, and people were used to using slide rules, so having something that didn’t take a lot of code that matched how users worked anyway was a win-win.

With RPN, there is no ambiguity depending on secret rules or parentheses, nor is there any reason to remember things unnecessarily. Processing RPN, on the other hand, is easy. If you see a number, push it on the value stack. If you see an operator, pop off enough stuff from the stack, do the operation, and put the result back on the stack.

See https://hackaday.com/2023/06/21/in-praise-of-rpn-with-python-or-c/
#Blog, #math, #python, #RPN, #technology

california@diaspora.permutationsofchaos.com

Finding #Nicknames With #Sherlock

Identifying and tracing a person’s footprints across the #internet usually involves researching nicknames across a wide variety of different platforms. On the one hand you can use the tool to find a nickname that is still available on all platforms and on the other hand to identify the probably same user across platforms. So if you value your privacy, remember how easy it is to find anything on the Internet with the right tools.

github: https://github.com/sherlock-project/sherlock

enter image description here

#tool #utility #search #find #nickname #python #terminal #opensource #privacy

danie10@squeet.me

20 of the best Python courses you can take online for free: Kickstart a new career in coding without spending a penny

Bild/Foto
Why is Python such a popular choice for programming beginners? Well, Python has a relatively simple syntax, making it a perfect option for anyone who is just starting out in the field of programming. Python is also very versatile, meaning that you can use it for a wide range of tasks in multiple industries.

You can find a wide range of beginner-friendly Python courses for free on Udemy. Mashable has lined up a selection of standout options to help you pursue your passion, kickstart a new career, or simply have fun learning something new.

I’d stopped programming a good 20 or 25 years ago, and was working in other languages, but I managed to pick up Python really quickly. It is an easy and fun language to learn.

See https://mashable.com/uk/deals/free-python-programming-courses
#Blog, #education, #freecourses, #programming, #python, #technology