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 ,)