Saturday, February 21, 2015

coding challenge Chess

I tried to make a chess game with vb.net under visual studio 2013.


Info:
I wrote this application in vb.net. As you maybe can see the gui is dynamical generated. I use a lot of panels.
I just needed about 2000 rows for this result. There is one interface called Figure and all the others will extend it.

If you are interested in the source code:
https://github.com/marcin96/Marcins_Chess

If you have questions please write.
Maybe you wonder why I haven't used the standart MVC and didn't separate the model from the gui as usually. My intension wasn't to create a real chess app. I wanted to show how you can code an evealuating system for figures and their possible moves. As you can see I used the hole field as an Array and calculated then with with formules for each group of figures their possibilities at the play time.

Coding challenge Pong

I made a little Pong game, in Java and Slick2D



Info:
A very basic application every programmer knows. Originally developed by a swiss student in the 20th century. I wrote it in java 8 under Netbeans with slick2D a child library of lightweight java game library.

Coding challenge Tetris

I made a little Tetris game in Java and Slick2D




Info
Propably the most famous computer game in the world. Tetris.
I needed about one day to write it.
Heere are my Tipps:

  • Strukturize the background in rows and comlumns with coordinates.
  • Write a class for one Cube. This is necessary, beacause after your figures are at the bottem the app should count only the cubes per row.
  • Use a Timer for the pseudo gravity.
  • To rotate the figures , please remember that you should do it centered.
For me it was a lot of fun, and only about 400 rows of java code. So when you have a fiew minutes, then do it. It will be great.

used: Java 8 and Slick 2D

python to msi ~(Windows Installer)

Info:
When you develop a lot of python applications and you want that your next script is close sourced, then you are right with this article. I explain you have to compile a python application and generate a msi Windows installer. For that i use cx_Freeze.

Built Script:

company_name = 'Marcins Programms'
product_name = 'Sokrates'

bdist_msi_options = {
    'upgrade_code': '{Banana-rama-30403344939493}',
    'add_to_path': False,
    'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % (company_name, product_name),
    }

path = sys.path
build_exe_options = {
"path": path,
"icon": "brain.ico"}

base = None
if sys.platform == "win32":
    base = "Win32GUI"
 
exe = Executable(script='Sokrates__PYMATH.py',
                 base=base,
                 icon='brain.ico',
                )

setup(  name = "Sokrates",
        version = "1.1",
        description = "Powerfull Calculator for all plattforms",
        executables = [exe],
        options = {'bdist_msi': bdist_msi_options})


run this script with a batch file:
py build.py build
py build.py bdist_msi


You need cx_freeze

Monday, January 26, 2015

Tic Tac Toe in python


Info
This Little Script works with python 3.4 and Tkinter.
It is only 37 lines long, but very fast and has a small size.

Code:

from tkinter import *;turn=None
class pButton(Button):
    def setty(self):self.state=None
    def SET(self,what):
        if what in("X","O"):
            self.state=what
            if what=="X":self.config(bg="light green")
            else:self.config(bg="tomato")
            self.config(text=self.state)
        else:print("error")
class Main:
    def __init__(self):
        self.root=Tk();self.root.title("Tic Tac Toe");self.root.geometry("180x180")
        self.b=[None,None,None,None,None,None,None,None,None,None]
        column=0;row=1
        for i in range(0,9):
            self.b[i]=pButton(self.root,text="-")
            self.b[i].setty()
            self.b[i].grid(row=row,column=column,pady=5,padx=5)
            self.b[i].config(width=5,height=2)
            self.b[i].bind("",lambda event, arg=self.b[i]: self.push(event, arg))
            column+=1
            if column>2:column=0;row+=1
        global turn;turn="X"
        self.L=Label(self.root);self.L.grid(row=4,column=1);self.L.config(text="{Turn of X}")
        self.root.mainloop()
    def push(self,event,pButton):
        global turn
        if turn=="X":pButton.SET(turn);turn="O";self.L.config(text="Turn of O")
        elif turn=="O":pButton.SET(turn);turn="X";self.L.config(text="Turn of X")
        self.debug()
    def debug(self):
        for i in ("X","O"):
            for x,y,z in [0,1,2],[3,4,5],[6,7,8],[0,3,6],[0,4,8],[2,4,6],[1,4,7],[2,5,8]:
                if self.b[x].state==i and self.b[y].state==i and self.b[z].state==i:self.L.config(text=i+" wins"),self.L.config(bg="yellow")
            else:pass
main=Main()

Author:Marcin
Language: Python 3.4
Version 0.1
--very easy--

OpenGl in Python

Info:
Everyone knows OpenGl lib. It's often in use with C. But you can also use it with python. Of course it's not the fastest possiblity, but you can do a lot of funny things together with python.

You need PyOpengl for doing this.
This package is free aviable under:https://pypi.python.org/pypi/PyOpenGL/3.0.2


A Little Example:
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import sys
window = 0
rtri = 0.0
rquad = 2.0
speed = 0.1
Wireframe = True

def InitGL(Width, Height):                
    glClearColor(0.3, 0.3, 0.3, 0.0)    
    glClearDepth(1.0)                   
    glDepthFunc(GL_LESS)                
    glEnable(GL_DEPTH_TEST)
    glPolygonMode(GL_FRONT, GL_LINE)    
    glPolygonMode(GL_BACK, GL_LINE)     
    glShadeModel(GL_SMOOTH)                

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()                    
                                        
    gluPerspective(45.0, float(Width)/float(Height), 0.1, 100.0)

    glMatrixMode(GL_MODELVIEW)


def ReSizeGLScene(Width, Height):
    if Height == 0:                       
        Height = 1

    glViewport(0, 0, Width, Height)        
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(45.0, float(Width)/float(Height), 0.1, 100.0)
    glMatrixMode(GL_MODELVIEW)

def DrawGLScene():
    global rtri, rquad ,speed

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)    
    glLoadIdentity()
    glTranslatef(0.0,0.0,-5.0)        
    glRotatef(rquad,speed,speed,speed)
    glBegin(GL_QUADS)                 

    glColor3f(0.0,1.0,0.0)            
    glVertex3f( 1.0, 1.0,-1.0)        
    glVertex3f(-1.0, 1.0,-1.0)        
    glVertex3f(-1.0, 1.0, 1.0)        
    glVertex3f( 1.0, 1.0, 1.0)       

    glColor3f(1.0,0.5,0.0)           
    glVertex3f( 1.0,-1.0, 1.0)        
    glVertex3f(-1.0,-1.0, 1.0)        
    glVertex3f(-1.0,-1.0,-1.0)        
    glVertex3f( 1.0,-1.0,-1.0)        

    glColor3f(1.0,0.0,0.0)           
    glVertex3f( 1.0, 1.0, 1.0)        
    glVertex3f(-1.0, 1.0, 1.0)       
    glVertex3f(-1.0,-1.0, 1.0)       
    glVertex3f( 1.0,-1.0, 1.0)        

    glColor3f(1.0,1.0,0.0)            
    glVertex3f( 1.0,-1.0,-1.0)        
    glVertex3f(-1.0,-1.0,-1.0)        
    glVertex3f(-1.0, 1.0,-1.0)        
    glVertex3f( 1.0, 1.0,-1.0)       

    glColor3f(0.0,0.0,1.0)            
    glVertex3f(-1.0, 1.0, 1.0)        
    glVertex3f(-1.0, 1.0,-1.0)        
    glVertex3f(-1.0,-1.0,-1.0)       
    glVertex3f(-1.0,-1.0, 1.0)        

    glColor3f(1.0,1.0,1.0)            
    glVertex3f( 1.0, 1.0,-1.0)       
    glVertex3f( 1.0, 1.0, 1.0)        
    glVertex3f( 1.0,-1.0, 1.0)        
    glVertex3f( 1.0,-1.0,-1.0)        
    glEnd()                           
    rtri  = rtri + 0.2                  
    rquad = rquad - 0.15                 
    glutSwapBuffers()
def keyPressed(*args):
    global rquad
    if args[0]==b"x":
        global Wireframe
        if Wireframe==False:
            glPolygonMode(GL_FRONT, GL_LINE)    
            glPolygonMode(GL_BACK, GL_LINE)
            Wireframe=True
        elif Wireframe ==True:
            glPolygonMode(GL_FRONT, GL_FILL)
            glPolygonMode(GL_BACK, GL_FILL)
            Wireframe=False
        else:pass
    elif args[0]==b"\x1b":
        exit()
    elif args[0]==b"v":
        rquad=2
        print(rquad)

    print(args[0])

def main():
    global window
    glutInit()
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
    glutInitWindowSize(640, 480)
    glutInitWindowPosition(0, 0)
    window = glutCreateWindow(b"Cube")
    glutDisplayFunc(DrawGLScene)
    glutIdleFunc(DrawGLScene)
    glutReshapeFunc(ReSizeGLScene)
    glutKeyboardFunc(keyPressed)
    InitGL(640, 480)
    glutMainLoop()
print("Press any key to exit")
main()


Sunday, January 25, 2015

Make Windows even faster

10 steps that makes your Windows Pc a lot faster


1.) Disable Icons
2.) Disable Visual Effects
3.) Clean your Pc with ccleaner
4.) Customize Autostart
5.) Defragment your hdd
6.) Customize Graphics
7.) Battery Settings on Laptop
8.) Update your drivers
9.)Set a low background
10.) Make a Partition for your Os with enaught memory and a data partition for Software ect.

Gui in Python

A few possibilities to make a graphical user interface in python

[*]Python has an build in library, it's called tkinter>
     >fast
     >Small
     >Flexible

Screenshot


A good Tutorial is on this Site.
+Simple Video Introduction: https://www.youtube.com/watch?v=RGVcaoaXyNE

[*]Pyside is completely free and has many possibilities to customize a gui of an application.

[*]PyGtk is also completely free and very fast
>Official Site: http://www.pygtk.org/

[*]Kivy is also aviable for mobile development #Android
>Official Site: http://kivy.org/#home

                                                            <--for more-->

Friday, January 23, 2015

Free Ebooks

The best 15 websites with free Ebooks ,)

Send mail python

Python send mail



Python has built in libraries for accessing pop imap or smtp:
import smtplib

From = 'test@python.com'

To = ["test@user.com"]

Subject = "Test_mail"

TEXT = "Hai"

message = "Hai"

server = smtplib.SMTP('myserver')
server.sendmail(FROM, TO, message)
server.quit()

Brute Force in Python

¨
This little script works with python 3.4 64 bit version. The source code is in the description...

Free download videos form the web without any Software.

Free download videos form the web without any Software.


You just need Firefox ,)