Showing posts from June, 2018

back to michigan, a silly snake game in python 2.7 and pygame

I'll be trying to get the forced perspective experiment done in the next couple days.

I'm headed back to Michigan soon. (So long California!)
There's a lot to do before we hit the road so between that and some health problems I don't know if I'll get that experiment done and posted.
If you don't see a post in a while, No worries, I'll be back when I can.

Here's a bit of an old code I wrote in pygame python 2.7.   It's messy, and you'd have to put you're own images in, but it's basically a snake game.

If coding can't be fun, what's the point?
Remember it's from before I really did any real diving into code, so it's not written how I would do it today. 
Have fun! Reak havoc, whoever you are!

# .....I didn't test it.  I know it did work back in 2013
#  .....  all be it badly. 

import sys
import pygame
from pygame.locals import*
from sys import exit
import random
from random import randint

UnicornIntro = pygame.i…

Github links for Wiwa, and pygame experiments

Wiwa:  "whispering wall"

pygame collision demo:

pygame paint project:

Currently dusting off the 3D experiment in pygame to get that showcasing the theory I had about forced perspective.  Will hopefully add it soon.

ubuntu on older CPU freezes _crash_

Update 6-23-18:
I may have been very wrong.  On the suggestion of my sister, I opened up the casing of the alienware and blew out the 5 years of dust collected in it...
So far no crashes.... No fans going nuts... no wierdness... Dust... dust bunnies were most likely  cause of all these issues. Simplest explanation is most likely the right one.

######### original ##########

Ok, so I'm trying to figure out why my computer refuses to shutdown, or recognize the keyboard or mouse if I plug the mouse in after it boots up.

It may or may not have anything to do with the mouse.
It has crashed on me before where I could not shutdown without either pulling the power supply or holding the power button.

Not sure why this stuff keeps happening on my computers other then they are old (in alienware case) or weak(in the laptop case), and the newest Operating systems may not be compatible with them.

I imagine when new operating systems are designed and built, they do not consider older or weaker ma…

playing with trigonometry sin in pygame

Ok I am so far from understanding, so don't take this as any kind of math lesson.
Also, every time I thought I knew what I was doing.... pygame would show me differently. Still a work in progress, but for now, something to play with.
Update: SinWaveTime class added to produce that particular weaving effect
Tinkering with the different sin wave variables:
I wrote this piece separate from my 3D experiment to see how to manipulate the sin wave.
While trying to use time as the factor to move my pygame draw circle on the x-axis, i got this crazy little doo-dad :

I don't think it's drawing two circles at once, but if I figure out what the heck it's doing I'll let you know.  Or hey if you know, drop a comment.  I don't know if my comments are just not working, or no one wants to.

So, here's some pygame code to play with the sin wave.  Alter the different variables to see it in action.

picture of SinWave.move_with_time()
see changes, SinWaveTime class set up to sp…

playing with forced perspective pygame. A start.

update progress 6-15-18:
I'll get the new code into a new post when I'm done with the experiment.

I hope I explain it well,  My plan is to try and incorporate some kind of 3D effect with old fashioned art known as Forced Perspective.

I definitely need some more research to how it's accomplished, I only really know of what I learned in 10th grade art class, and that was back when dinosaurs roamed the earth.  (This works as a reference to when Jurrasic Park came out too!)

It's slightly off center on purpose.

Here's the code:  enjoy, explore, have fun!
As always, drop me a comment, improvements, critiques and hero worship are welcomed.  (Or tell me some python jokes, those are fun)

# -*- coding: utf-8 -*-
import pygame as pg
from sys import exit
from time import sleep

class SkullGlobals(object):
""" class container for globally used variables """
def __init__(self):
        self.WIDTH = 800
        self.HEIGHT = 800

pygame and tkinter used together

I'm still in the exploratory phase.

<insert image of Nellie cackaling like a mad scientest as she whips code into run mode>

But apparently you can use Tkinter and pygame together!
That would make constructing a game, paint, everything smoother, if I can do what I think I can.  Pygame could be solely responsible to draw to screen, Tkinter to modifications, menu's, alterations. 

It's just a start, but here's some code for you:

# -*- coding: utf-8 -*-
import pygame as pg
from sys import exit
from time import sleep
import tkinter as tk

class SkullGlobals(object):
   """ class container for globally used variables """
def __init__(self):
        self.WIDTH = 800
        self.HEIGHT = 800
        self.CENTER_SCREEN_X = 0 + self.WIDTH//12
        self.CENTER_SCREEN_Y = 0 + self.HEIGHT//12
        self.CENTER_SCREEN_H = self.HEIGHT - self.HEIGHT//6
        self.CENTER_SCREEN_W = self.WIDTH - self.WIDTH//6
        self.background_color = (…

resizing a pygame screen

It's a theory I had, so far looking good.
I worked on finding a way to resize the pygame screen, and how the objects inside can scale with it.

Once again, there is probably some package shortcut that does this for you, but this is how I learn best.

Demo Video:


My theory was if I made every image creation, draw, whathave you, scale by the screen's size,  and then change that size, the objects drawn on would size properly with it.  Still working on it, so If I get it all proper, I'll drop it in an update

**NOTE** if you place too many run_screen where they don't belong <like outside an event handler in the while loop> You can stall out the computer.

I did fix it, so it's a freindly warning if you like to experiment like I do.

I didn't have to hard reset, but had to hold the CTRL^C and push CTRL ALT DEL a bit to get it to stop.

It's in progress, but if you're looking for a start like I was:

# -*- coding: utf-8 -*-
import pygame as…

putting globals into a python class and while loop shuffle

I realized today that when I updated the last post, the pygame paint like program, that I didn't leave any explanations or show the major mistakes I made.

Since this blogs intentions are to help fellow learners, it seems really important I explain some things.

First: Putting the globals into their own class

Imagine you have a pile of crayola red crayons, and for some reason the monsters under the bed will not go away until each red crayon is put into it's original box.

Some have labels, some don't.  Some are used, some are not.

Now pythonic is to CAPitilize a global variable, but outside of a class, they can be changed and altered by the whim of another method.
It's true you can alter attributes in an initiated class from a method, but it is a local change.  My class of globals has no function within it to alter the original set attributes.

I made my own crayon box, and every piece inside has a label as to where it came from.

some links supporting how hard it is to get o…