daftpython
Thursday 16 May 2019
Monitoring Earthquakes Curses
Tuesday 20 October 2015
Reflections On IronPython : Still In Production
A recent reddit thread on IronPython brought back some memories so I thought I would record them in a quick blog post.
I really liked Python when I discovered it 10+ years ago and was delighted when I first heard Microsoft had hired talent to bring Python to dotNet. At the time, I was stuck in VB6 (really) and had recently discovered traditional Python. I joined the mailing list, tried out early builds, reported bugs to Codeplex and the team at Microsoft were a great bunch to interactive with. Microsoft are somewhat Open Source today - at the time this was very unusual. I ended up writing a few GUI programs, even an IronPython editor for some time.
Then Microsoft went through changes, IronPython was dropped along with other interesting products like Mesh. The Open Source version is still around but the mailing list is very quiet. I went back to regular Python and messed around with PyGame. I still use IronPython in production (handy for configuration to have .Net scripting with zero-install for installers) and can't help think Microsoft missed a trick here. It is a much more friendly language than Powershell and theres not really a good .Net scripting language even years later. All is not entirely lost though, they still produce Python Tools for Visual Studio and it is very good.
So IronPython for me was interesting, fun and useful. It was great being involved early on in the development, which probably why I got so caught up diving into the relatively new Dart language from Google.
Friday 10 August 2012
Screenshot Viewer For Minecraft - Now Released
Tuesday 7 August 2012
Minecraft Screenshot Viewer in wxPython - A Preview
But there is no easy way to view the screenshots in the game and it is a bit 'hidden' under .minecraft so what a great excuse for a wxPython program. Not quite ready for the prime-time (needs Linux tested at least) but my eldest was impressed by the demo of it and is keen to get it installed on the main family PC.
Here's a screenshot until I get some SVN sorted out:
Ideas for features welcome - leave a comment!
Friday 27 July 2012
Simple Starfield In PyGame
The next step was to create a graphical display and, of course, stars were the first order of business! I looked around at a few star field examples and ended up coding one for myself. Straightforward 2D scrolling is all I want - needs to be calm for the display. The class is nice and simple whilst the demo shows it off fairly well.
Exercise for the reader - can you make a layered demo? I'll share the code on a follow up post. Happy stargazing!
import random import pygame import sys from pygame.locals import * class starfield(object): def __init__(self, pos , size, max, speed): self.stars = [] self.pos = pos self.size = size self.max = max self.speed = speed self.box = True self.color = (255,255,255) self.bordercolor = Color(255,255,255) self.backgroundcolor = Color(0,0,0) for loop in range(0, max): star = [random.randrange(0, size[0] - 1), random.randrange(0, size[1] - 1)] self.stars.append(star); def draw(self, screen): if self.box: pygame.draw.rect(screen, self.backgroundcolor, Rect(self.pos[0], self.pos[1], self.size[0],self.size[1]), 0) pygame.draw.rect(screen, self.bordercolor, Rect(self.pos[0], self.pos[1], self.size[0],self.size[1]), 1) for loop in range(0, self.max): p = (self.pos[0] + self.stars[loop][0], self.pos[1] + self.stars[loop][1] ) screen.set_at(p, self.color) def update(self): for loop in range(0, self.max): self.stars[loop] = (self.stars[loop][0] + self.speed, self.stars[loop][1]) if self.stars[loop][0]>self.size[0]: self.stars[loop] = (0, self.stars[loop][1]) # DEMO sf = [starfield( (50,50), (550,410), 80, 1 ), starfield( (80,150), (200,200), 33, 2 ), starfield( (380,150), (200,200), 33, 3 ), starfield( (5,5), (80,80), 12, 4 ) ] sf[1].color = (255,0,0) sf[2].color = (0,255,0) sf[3].color = (0,0,255) TIMEREVENT = pygame.USEREVENT UPDATEEVENT = pygame.USEREVENT+1 FPS = 50 pygame.init() window = pygame.display.set_mode((640, 480)) background = None background = pygame.Surface(window.get_size()) background.fill((0, 0, 0)) pygame.time.set_timer(TIMEREVENT, int(1000 / FPS)) pygame.time.set_timer(UPDATEEVENT, 50) while True: for event in pygame.event.get(): if event.type == TIMEREVENT: background.fill((0,0,0)) for s in sf: s.draw(background) window.blit(background, (0, 0)) pygame.display.flip() elif event.type == UPDATEEVENT: for s in sf: s.update() # Move starfield x = sf[3].pos[0] + 2 y = sf[3].pos[1] + 2 if x>640: x=-50 if y>480: y=-40 sf[3].pos = (x,y) elif event.type == pygame.QUIT: sys.exit()
Thursday 12 July 2012
Particles Of Blue
It is not terribly efficient or a good colour for soil but has potential.
Here's the code:
import pygame
import sys
import random
from pygame.event import *
from pygame.locals import *
TIMEREVENT = pygame.USEREVENT
FPS = 50
pygame.init()
window = pygame.display.set_mode((640, 480))
background = None
background = pygame.Surface(window.get_size())
background.fill((0, 0, 0))
pygame.time.set_timer(TIMEREVENT, int(1000 / FPS))
colour3 = Color(0, 0, 255)
ground = Color(0, 255, 0)
y = 100
def DrawText(bg, x, y, text, size=24, color=(255, 255, 255)):
inst1_font = pygame.font.Font(None, size)
inst1_surf = inst1_font.render(text, 1, color)
bg.blit(inst1_surf, [x, y])
class grit(object):
def __init__(self):
self.x = random.randint(0,639)
self.y = random.randint(0,125) - 50
self.width = random.randint(1, 6)
self.height = random.randint(1, 6)
self.color = Color(0, 0, random.randint(119,255))
self.active = True
def init():
gritsL = 1000
agrits = []
while len(agrits)<gritsL:
agrits.append(grit())
return agrits
grits = init()
while True:
for event in pygame.event.get():
if event.type == TIMEREVENT:
background.fill(pygame.Color("black"))
DrawText(background, 25, 120, "Daftspaniel",126)
pygame.draw.rect(background, ground, Rect(0, 450, 640,280), 0)
pygame.draw.rect(background, ground, Rect(300, 250, 340,180), 0)
for g in grits:
pygame.draw.rect(background, g.color, Rect(g.x, g.y, g.width, g.height), 0)
if g.active:
if g.y>-1 and g.y<(480-g.height):
c = background.get_at((g.x, g.y+g.height));
if c.r==0 and c.g==0:
g.y = g.y + 5
else:
g.active = False
if g.y<0:
g.y = g.y + 5
window.blit(background, (0, 0))
pygame.display.flip()
elif event.type == pygame.KEYDOWN:
keystate = pygame.key.get_pressed()
if not keystate[K_w]==1:
grits = init()
elif event.type == pygame.QUIT:
sys.exit()
Any suggested improvements? I would like to use this for a treaure hunt game. Two players digging for gold. Soil lumps might have to be bigger for a game.