www.main.lv

Don't think just code it

Menu

  • Projects
    • Robatik
    • ArpSni
  • Samples
    • FreeBSD Asm
    • Linux Asm
    • PyGame Tutorial
    • UNIX programming
    • PSP programming
    • AVR
    • Math
  • Contact

Tags

algo (1)asm (19)attractor (2)avr (2)blender (3)bug (1)c (25)coalision (2)debug (3)editor (1)elf (1)fractals (2)freebsd (3)game (3)generator (1)gimp (1)int80h (22)map (1)math (5)mit (1)nano (1)net (2)opengl (1)plugin (1)post (2)povray (1)psp (3)pygame (19)python (28)robatik (2)sdl (3)skype (2)sql (1)towers (2)tutorial (7)voronoi (1)wudu (1)

Archive

  • 2010 august (1)
  • 2010 july (2)
  • 2010 june (1)
  • 2010 april (2)
  • 2010 march (2)
  • 2010 february (2)
  • 2010 january (2)
  • 2009 december (3)
  • 2009 november (8)
  • 2009 october (3)
  • 2009 september (5)
  • 2009 august (1)
  • 2009 july (1)
  • 2009 june (1)
  • 2009 may (1)
  • 2009 april (3)
  • 2009 march (1)
  • 2009 february (2)
  • 2009 january (1)
  • 2008 october (2)
  • 2008 september (4)

2009-09-23 Python Pygame Tutorial Randomnes

All boxes moving with same speed in same directions and all boxes have same size and color
Make changes step by step to see result

self.dx = randint(1,BOX_SPEED)
self.dy = randint(1,BOX_SPEED)
and boxes now moving all seperatly at diferent directions.
self.boxes.append( Box( i*2 , i*2 , randint(BOX_MIN_SIZE,BOX_MAX_SIZE) ,
(i,0,0) )
now boxes have diferent sizes

Tutorial source


2009-09-23 Python Pygame Tutorial Boxes Move

New class boxes handles many boxes. Number of boxes depends on cpnstant MAX_BOXES.

MAX_BOXES = 100

and all class Boxes methods is the same only diference is that it handles many boxes.

Tutorial Source


2009-09-23 PyGame Lorenz attractor

Here is Lorenz attractor whery popular attractor i have used basic coloring tehnique.

Script

PovRay source


2009-09-15 Python Pygame Tutorial Box Move

added constants that helps controlling screen size

SCREEN_X = 500
SCREEN_Y = 500
BOX_SIZE = 20
BOX_SPEED = 1
box have speed by axis
self.dx = BOX_SPEED
self.dy = BOX_SPEE
detecting if given rect is inside screen borders or not if not then change it direction
def move( self ):
        if self.rect.left+BOX_SIZE > SCREEN_X:
            self.dx = -BOX_SPEED
        if self.rect.left < 0:
            self.dx = BOX_SPEED
        if self.rect.top+BOX_SIZE > SCREEN_Y:
            self.dy = -BOX_SPEED
        if self.rect.top < 0:
            self.dy = BOX_SPEED
        self.rect.left += self.dx
        self.rect.top += self.dy
after few line of code where added box move inside given screen and coalide with screen borders

Tutorial Source


2009-09-04 FreeBSD assembler open file

Here code for opening file, reading from it and close it. At beginig i have thinked taht it will be complicated. But it was easy and interesting as C. Here is both C and asm code.

openfile.asm

;/usr/include/sys/syscall.h
;#define SYS_read        3
;#define SYS_write       4
;#define SYS_open        5
;#define SYS_close       6
 
sys_read equ 3
sys_write equ 4
sys_open equ 5
sys_close equ 6
o_rdonly equ 0
 
format ELF
section '.text' executable
public _start
_start:
    ;int fid = open("file.txt",O_RDONLY);
    push o_rdonly
    push f
    mov  eax, sys_open 
    push eax
    int  0x80
    add  esp, 4*3   ; clear stack after interupt	
    mov dword [f_id], eax
 
    ;read( fid , &buf[0] , 12 );
    push f_buf_len
    push f_buf
    push eax
    mov eax, sys_read
    push eax
    int 0x80
    add esp, 4*4
 
    ;write( 1 , &buf[0] , 12 );
    push f_buf_len   
    push f_buf     
    push 1         
    mov  eax, sys_write     
    push eax
    int  0x80
    add  esp,4*3
 
    ;close( fid );
    push dword [f_id]
    mov eax, sys_close
    push eax
    int 0x80
    add esp, 4*2
 
    ;exit from programm
    xor eax, eax	;eax = 0
    push eax
    inc eax			;eax = 1, sys_exit
    int 80h			;system interupt
 
section '.data' writeable
	f db "file.txt",0
	f_len = $-f
	f_buf db 12 dup 0
	f_buf_len = $-f_buf
	f_id dd 0


fasm openfile.asm openfile.o

ld openfile.o -o openfile



c.c
#include <fcntl.h>
 
int main()
{
	int fid = open("file.txt",O_RDONLY);
	char buf[12];
	read( fid , &buf[0] , 12 );
	write( 1 , &buf[0] , 12 );
	close( fid );
	return 0;
}


gcc c.c -o c

file.txt
Only text!!!




© 2010