Pages

Thursday, May 8, 2014

thought I'd try a snowflake.

It all makes sense when i put pencil to paper, but then I try and put it into a program, and Epic Fail.


But this is what I got playing with Pygame.

It's just 1/12 of the snowflake.  Just gotta figure out how to rotate it, and mirror it.  Like 11 more times.  then add the prongs to the rest.

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



def run():
    pygame.init()
    screen= pygame.display.set_mode((800, 800))
   
    R = 375  # radius
   
    # Rx = (1.15 * R)  = 431
   
    # Ry =( sqrt((375)**2 + (431)**2))
   
    # Ry = 196
   
   

        # center point (375, 375)  origin line (375, 0)
   
   
    clock = pygame.time.Clock()
   
   
    while True:
   
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
       
        change = randint(2, 175)
        n = 0.222222
        n2 = 0.5
        i = 0.111
        variance = 196
        x = (750)
        y = (750)
        x2 = (375)
        y2 = ( 0)   
        time_passed = clock.tick()
        time_passed_seconds = time_passed/1000

        screen.fill((0, 0, 0))

       
        Rainbow = (randint(0,255), randint(0, 255), randint(0,255))   
        O = randint(0, 375)
                    #   origin   (375, 375), (0, 750)
                    #  origin (375, 375), (750, 375)
        pygame.draw.line(screen, Rainbow, (375, 375), (x2, y2), 5)
        pygame.draw.line(screen, Rainbow, (x2, y* n * 2), (x2 - 270, x2 * n * 2), 6 )
        pygame.draw.line(screen, Rainbow, (x2, y * n ), ( x2 - 180, x2 *n), 5)   
        pygame.draw.line(screen, Rainbow, (x2, y * n * n2), ( x2 - 120, x2 * n * n), 4)
        pygame.draw.line(screen, Rainbow, (x2, y * n *n *n2), ( x2 - 30, x2 * n *n *n ), 3)    
        clock.tick(90)   
       

        pygame.display.update()

if __name__ == "__main__":
    run()

   

Wednesday, May 7, 2014

pygame move formula

It's not working right,  But its a start.


import pygame
from pygame.locals import*

from sys import exit
import math

class MoveObject(object):
    def __init__(self, x1, y1, n, i, w, h, imgw, imgh):
        self.x1 = 0.0
        self.y1 = 0.0
        self.n = n
        self.i = i
        self.w = w
        self.h = h
        self.imgw = imgw
        self.imgh = imgh
       
       

   

    @classmethod
    def object_formula(self, x1, y1, n, i, w, h, imgw, imgh):
        if n * w >1 and n * w < w and i * h > 1 and i * h < h:
           
            return MoveObject(x1 + n * imgw, y1 + i * imgh)
        else:
            return (0 ,0)

def main(MoveObject):
   
    pygame.init()
    screen = pygame.display.set_mode((800, 800), 0, 32)
    UniBrush = pygame.image.load("apoobrush.png")
    unibrush = pygame.transform.scale(UniBrush, (90, 90))
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
       
       
        pressed_keys = pygame.key.get_pressed()
        if pressed_keys[K_LEFT]:
            n = -1.0
            n = n -1
        elif pressed_keys[K_RIGHT]:
            n = +1.0
            n = n + 1
        if pressed_keys[K_DOWN]:
            i = +1.0
            i = i + 1
        elif pressed_keys[K_UP]:
            i = -1.0
            i = i - 1
        else:
            n = 0
            i = 0
       
        (x, y) = MoveObject.object_formula(0, 0, n, i, 800, 800, 90, 90)
       
       
        screen.blit(unibrush, (x, y))
        pygame.display.flip()
       

main(MoveObject)
   
       
       
       
       
       

Monday, May 5, 2014

More on the rectangles.

If we take the Cartesian sum of a set  A and B,
Where A is the number of rects in the width
and B is the number of rects in the height...

(H * W)/ W =number of Width Rects (subtract one for A_max)
(H * W)/ H =number of Height Rects (subtract one for B_max)

Lets say it's a 4 x 5 rectangle.

So our two sets would be:
A = range(0, A_max)
B = range(0, B_max)
A = {(0, 1, 2, 3, 4)}
B = {(0, 1, 2, 3)}

the Cartesian set would be:
{(0,0), (0,1), (0,2), (0,3), (0, 4), (1, 0), (1, 1)....(4, 2), (4, 3)}

Each of these sets can represent the C and I in this formula,

(x + CW, y + IH)

Now how do I put it in a computer program, and how do I get it to save the results of each coordinates into a new list for the individual rects.... 

I want the program to be able to distinguish from the cartesian set and the formula, a set of individual rectangles.   That way all the rectangles in a map can be altered, or manipulated.

Kinda like a simple paint, but I don't want it to create them as we go.  I want them already gridded out, and then alterable from there. 

Lets say we can put an image in there like in photoshop, and alter it based on the individual rectanglular spots in the grid.

I don't know if this is how they do it already,  But just thinking that might be how the whole CGI stuff works.    Map a set of points, alter them as we see fit.

Except I just want a simple large-ish grid that can make simple sprites that are easily manipulated and moved, just like the Vector Class does in pygame,  but we can just click the squares and go.... I want these to move up by a vector of 2, 3,  these by 3, 4....  and so on until I've made my own animator without downloading a bunch of rediculously complicated software,  or maybe that's how it all already works and I just don't know it.

Either way, I want to create one myself...  cause I want to make simple sprites that move by with code,  not by image translation.
Are they the same thing?

Thursday, May 1, 2014

RECTANGLES

Been trying to figure out a formula that would allow me to make a loop which creates a screen filled with individual rectangles.


Here's what I come up with so far,  still have to write a program to fit it.

  x  axis,    width   of rectangles = w
  y axis,   hieght of rectangles = h
change in x = 1 =cx

 cx = cx + 1




   ---------------------------------------------------------------------------------------------------------------------------
  | (x, y)               |    (x +cx*w,  y)  |   ( x + cx*w, y)  |   (x + cx*w, y)   |   ( x + cx *w, y) |
  |______________ |________cx = 1__|______cx = 2_____|_______cx = 3____|______cx = 4____|
  |                                                                                                                                                       |
  | (x , y + h)  |   (x + cx*w, y +h) | (x + cx * w, y + h) |(x + cx*w, y + h) ......                  |
  |______________________________________________________________________________________|
  |                                                                                                                                                       |
  | (x, y + 2h)|  (x + cx*w, y + 2h) | ( x + cx *w, y + 2h)  ...........................................|
  |______________________________________________________________________________________|
  |                                                                                                                                                      |
  | (x, y + 3h) |  (x +cx*w, y + 3h) |( x + cx*w, y + 3h) .............................................|
  |______________________________________________________________________________________|

so for the rectangles within the rectangle.....  the origin, for pygame rect coordinates
would be (0, 0)  or (x, y),  
then every rect in the first column would be  (x, y + (i)*h)  where i would increase by one for each additional rect in the column.  
the next column would be (x +w, y+(i)*h)   and next (x + 2w,  y + (i)h)
and next (x + 3w, y +(i)*h)   the width would in crease by one multiple per column for x.

Or if we did rows,   the x would be the ( + (i)*w) and (y + h) only increasing once per row

Determined to get it to work.  Then have it make a list to keep track of each rectangle so it can be altered and changed. 
Maybe a "append.list[]"  for each rectangle created by the change in (i)