Skip to content

Instantly share code, notes, and snippets.

View horstjens's full-sized avatar
💭
teaching python/pygame to children

Horst JENS horstjens

💭
teaching python/pygame to children
View GitHub Profile
@horstjens
horstjens / asteroid16.py
Last active October 21, 2024 16:54
asteroid16
import pygame
import random
import os.path
W, H = 1280, 720
class TextSprite(pygame.sprite.DirtySprite):
def __init__(self, pos, color, textsize, text, age_max, anchor="center" ):
@horstjens
horstjens / pixel_pos_problem.py
Created October 14, 2024 09:49
vpython label pixel_pos problem
import vpython as vp
import random
#import math
# description: a world with vertical cylinders (axis = vp.vec(0,0,1), base of all cylinders is at world position z=0
# the base of the cylinder has a location label (white text)
# the top of each cylinder has a value label (green text)
# problem: finding out pixel_pos of location labels (at the base of a cylinder) and the value labels( at the top of a cylinder)
# the pixel pos is not the world coordinates, but the coordinate in pixels
@horstjens
horstjens / turtle_chaser_01.py
Created October 10, 2024 12:35
turtle chaser 01
import turtle
# turtle bounces from screen edge
#w, h = 600,400
#turtle.setup(w*2, h*2)
screen = turtle.Screen()
screen.setup(1.0, 0.9)
w, h = screen.window_width()/2, screen.window_height()/2
@horstjens
horstjens / asteroids14.py
Last active October 7, 2024 16:42
asteroids14
import pygame
import random
import os.path
# done: ufo more pretty, triangular windows
# done: ufo change colors
# TODO: impact on asteroid changes speed of asteroid
# TODO: asteroid shall change color to indicate loosing hitpoints
W, H = 1280, 720
@horstjens
horstjens / tictacto.py
Created August 19, 2024 09:23
tictactoe
# tic tac toe spiel für 2 spieler, eingabekontrolle
# sieg ermittlung
# Horst JENS, 2024 08
def gewonnen():
feld = spielfeld.replace("-+-+-\n","")
feld = feld.replace("|","")
feld = feld.replace("\n","")
print(feld)
# 012
@horstjens
horstjens / freesimplegui_pokemon_matplotlib.py
Last active August 2, 2024 07:02
freesimplegui_pokemongui
import FreeSimpleGUI as sg
import random
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
#import numpy as np
import matplotlib.pyplot as plt
# format mini language https://docs.python.org/3/library/string.html#formatspec
class Pokemon:
@horstjens
horstjens / freesimplegui_matplotlib_simple_plot.py
Last active August 1, 2024 07:52
freesimplegui and matplotlib
#https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Matplotlib_Browser.py
# !/usr/bin/env python
import FreeSimpleGUI as sg
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import numpy as np
import matplotlib.pyplot as plt
@horstjens
horstjens / freesimplegui_layout1.py
Created July 30, 2024 07:29
freesimplegui_layout
import FreeSimpleGUI as sg
import FreeSimpleGUI as sg
# Define the window's contents
c_left = sg.Column(layout=[
[sg.Text("erste Zeile links1")],
[sg.Text("beginn links2")],
[sg.Text("links3")],
@horstjens
horstjens / pokemonfight001.py
Last active July 25, 2024 06:37
pokemonfight
# battle between 2 pokemons
import random
class Pokemon:
def __init__(self, name):
self.name = name
self.hp_full = 100
self.hp = 100
@horstjens
horstjens / many_turtles.py
Last active July 23, 2024 07:16
100_turtles
import turtle
import random
W, H = 2000, 1000
turtle.setup(W,H)
screen = turtle.Screen()
screen.setworldcoordinates(0,0,W,H)
screen.tracer(0)
# create turtles
for i in range(50):
t = turtle.Turtle()