Lorgan
Retired Randomizer Mod Developer
2011 Haxxy Award Winner
Online
Posts: 2967
check my new game in new projects k thx bye
|
 |
« on: March 17, 2012, 02:14:46 pm » |
|
This is a thread where everyone who programmed something (doesn't have to be a game) can post their creations. I have 2 things i want to show off :3
Sticky please?
|
|
|
|
« Last Edit: March 18, 2012, 09:30:07 am by Lorgan »
|
Logged
|
Unfortunately, turning a section into a communist oppressive regime is not against the forum rules, so there is really nothing we can do. 21:08 - Hullusorsa: lorgan, when will you buy us the keys? 21:09 - Lorgan: i'm waiting for greece to collapse so the value of the euro drops 21:09 - Lorgan: not even joking
|
|
|
Orpheon
2011 Haxxy Award Winner
Offline
Posts: 5818
Developer
|
 |
« Reply #1 on: March 17, 2012, 02:23:16 pm » |
|
Not as cool as the above, but I want to deposit my IRC (chat)bot somewhere, in fear of a disk crash or something. IRC bot downloadThe script is MyBotv4.py. The "words" file is a list of all english words + a few smilies, the bot only learns what it finds in there. "data" is the current memory of the bot, delete or rename to refresh it. I also added "Framework.py" which contains the IRC handling part, and lets you easily create your own bot.
|
|
|
|
« Last Edit: March 17, 2012, 02:24:55 pm by Orpheon »
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
Orpheon
2011 Haxxy Award Winner
Offline
Posts: 5818
Developer
|
 |
« Reply #2 on: March 18, 2012, 05:15:28 am » |
|
I've been fooling around with 4D stuff. I even made a small "renderer" that projects a 4D scene to two 3d scenes, and then those two into 1 2d picture each with colors to indicate depth.  This is supposed to be the 3D surface of a 4D sphere. The colors are two different kinds of depth (depth as negative x in one color, and depth as w in another) If someone knows some good fomulas to make shapes, I can try building more of them. Here's the script: from __future__ import division, print_function
from vector import Vector_2D, Vector_3D, Vector_4D from PIL import Image
global PICTURE_WIDTH, PICTURE_HEIGHT, RESOLUTION PICTURE_WIDTH, PICTURE_HEIGHT = 500, 500 RESOLUTION = 20
def project_4D_3D(orig_vec): # Using a Vector_4D to store the depth of the last component too point1 = Vector_4D() point1.setcoord((orig_vec.coord[0], orig_vec.coord[1], orig_vec.coord[2], orig_vec.coord[3]))
point2 = Vector_4D() point2.setcoord((orig_vec.coord[0], orig_vec.coord[1], orig_vec.coord[3], orig_vec.coord[2]))
return point1, point2
def project_3D_2D(orig_vec): # Input is a 3d vector which is hidden as a 4d one (x, y, z, depth) point1 = Vector_4D() point1.setcoord((orig_vec.coord[1], orig_vec.coord[2], orig_vec.coord[0], orig_vec.coord[3]))
return point1
pic1 = {} point = Vector_4D() for x in [i * 1/RESOLUTION for i in range(-RESOLUTION, RESOLUTION)]: for y in [i * 1/RESOLUTION for i in range(-RESOLUTION, RESOLUTION)]: for z in [i * 1/RESOLUTION for i in range(-RESOLUTION, RESOLUTION)]: for w in [i * 1/RESOLUTION for i in range(-RESOLUTION, RESOLUTION)]: point.setcoord((x, y, z, w)) point.normalize()
vec_3d, a = project_4D_3D(point)
vec_2d = project_3D_2D(vec_3d)
color = (0, int(255-(1+vec_2d.coord[2])*255/2), int(255-(1+vec_2d.coord[3])*255/2)) pic1[(int(((1+vec_2d.coord[0])/2)*PICTURE_WIDTH), int(((1+vec_2d.coord[1])/2)*PICTURE_HEIGHT))] = color
print((x+1)*100/2 + (y+1)*100/(4*RESOLUTION), "%")
print("Finished generating image 1, now printing")
image = Image.new("RGB", (PICTURE_WIDTH, PICTURE_HEIGHT))
for x in range(PICTURE_WIDTH): for y in range(PICTURE_HEIGHT): try: color = pic1[(x, y)] image.putpixel((x, y), color) except: pass
image.save("image_1.png")
print("Finished printing image 1")
pic2 = {} for x in [i * 1/RESOLUTION for i in range(-RESOLUTION, RESOLUTION)]: for y in [i * 1/RESOLUTION for i in range(-RESOLUTION, RESOLUTION)]: for w in [i * 1/RESOLUTION for i in range(-RESOLUTION, RESOLUTION)]: for z in [i * 1/RESOLUTION for i in range(-RESOLUTION, RESOLUTION)]: point.setcoord((x, y, z, w)) point.normalize()
a, vec_3d = project_4D_3D(point)
vec_2d = project_3D_2D(vec_3d) color = (0, int(255-(1+vec_2d.coord[2])*255/2), int(255-(1+vec_2d.coord[3])*255/2)) pic2[(int(((1+vec_2d.coord[0])/2)*PICTURE_WIDTH), int(((1+vec_2d.coord[1])/2)*PICTURE_HEIGHT))] = color print((x+1)*100/2 + (y+1)*100/(4*RESOLUTION), "%")
print("Finished generating image 2, now printing")
image = Image.new("RGB", (PICTURE_WIDTH, PICTURE_HEIGHT))
for x in range(PICTURE_WIDTH): for y in range(PICTURE_HEIGHT): try: color = pic1[(x, y)] image.putpixel((x, y), color) except: pass
image.save("image_2.png")
print("Done") Requires another file called "Vector.py" containing this: from __future__ import division
import math
class Vector_2D(object): def __init__(self, (x, y)=(0, 0)): self.coord = (x, y) self.length = math.sqrt(x**2 + y**2) if x == 0: if y < 0: self.angle = 270 else: self.angle = 90 else: self.angle = math.atan(y/x)
def normalize(self, newlength=1): if self.length == 0: return
self.coord = (self.coord[0]*newlength/self.length, self.coord[1]*newlength/self.length) self.length = newlength
def setangle(self, newangle=0): self.angle = newangle x = self.length*math.cos(self.angle) y = self.length*math.sin(self.angle) self.coord = (x, y)
def setcoord(self, (x, y)=(0, 0)): self.coord = (x, y) self.angle = math.atan(y/x) self.length = math.sqrt(x**2 + y**2)
def dotproduct(self, othervector): return self.coord[0]*othervector.coord[0] + self.coord[1]*othervector.coord[1]
def add(self, othervector): return Vector_2D((self.coord[0]+othervector.coord[0], self.coord[1]+othervector.coord[1]))
def subtract(self, othervector): return Vector_2D((self.coord[0]-othervector.coord[0], self.coord[1]-othervector.coord[1]))
class Vector_3D(object): def __init__(self, (x, y, z)=(0, 0, 0)): self.coord = (x, y, z) self.length = math.sqrt(x**2 + y**2 + z**2)
def normalize(self, newlength=1): if self.length == 0: return
self.coord = (self.coord[0]*newlength/self.length, self.coord[1]*newlength/self.length, self.coord[2]*newlength/self.length) self.length = newlength
def setcoord(self, (x, y, z)=(0, 0, 0)): self.coord = (x, y, z) self.length = math.sqrt(x**2 + y**2 + z**2)
def dotproduct(self, othervector): return self.coord[0]*othervector.coord[0] + self.coord[1]*othervector.coord[1] + self.coord[2]*othervector.coord[2]
def add(self, othervector): return Vector_3D((self.coord[0]+othervector.coord[0], self.coord[1]+othervector.coord[1], self.coord[2]+othervector.coord[2]))
def subtract(self, othervector): return Vector_3D((self.coord[0]-othervector.coord[0], self.coord[1]-othervector.coord[1], self.coord[2]-othervector.coord[2]))
class Vector_4D(object): def __init__(self, (x, y, z, w)=(0, 0, 0, 0)): self.coord = (x, y, z, w) self.length = math.sqrt(x**2 + y**2 + z**2 + w**2)
def normalize(self, newlength=1): if self.length == 0: return
self.coord = (self.coord[0]*newlength/self.length, self.coord[1]*newlength/self.length, self.coord[2]*newlength/self.length, self.coord[3]*newlength/self.length) self.length = newlength
def setcoord(self, (x, y, z, w)=(0, 0, 0, 0)): self.coord = (x, y, z, w) self.length = math.sqrt(x**2 + y**2 + z**2 + w**2)
def dotproduct(self, othervector): return self.coord[0]*othervector.coord[0] + self.coord[1]*othervector.coord[1] + self.coord[2]*othervector.coord[2] + self.coord[3]*othervector.coord[3]
def add(self, othervector): return Vector_4D((self.coord[0]+othervector.coord[0], self.coord[1]+othervector.coord[1], self.coord[2]+othervector.coord[2], self.coord[3]+othervector.coord[3]))
def subtract(self, othervector): return Vector_4D((self.coord[0]-othervector.coord[0], self.coord[1]-othervector.coord[1], self.coord[2]-othervector.coord[2], self.coord[3]-othervector.coord[3]))
|
|
|
|
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
MTK5012
2011 Haxxy Finalist
Offline
Posts: 738
I was Gangsterman
|
 |
« Reply #3 on: March 18, 2012, 06:19:46 am » |
|
4D sphere render in 3D in a 2D screen that draw by 1D lines and 0D dots? 
|
|
|
|
|
Logged
|
|
|
|
Orpheon
2011 Haxxy Award Winner
Offline
Posts: 5818
Developer
|
 |
« Reply #4 on: March 18, 2012, 07:27:09 am » |
|
4D sphere render in 3D in a 2D screen that draw by 1D lines and 0D dots?  No 1d involved, this does pure 4D-3D-2D dot-wise. Also, I only uploaded one image because in this case, they are identical. There would be two normally.
|
|
|
|
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
Lorgan
Retired Randomizer Mod Developer
2011 Haxxy Award Winner
Online
Posts: 2967
check my new game in new projects k thx bye
|
 |
« Reply #5 on: March 18, 2012, 09:24:26 am » |
|
Wait what's the difference between 4D and 3D? Also, i found the flaw in my code  (And the background also becomes lighter when it took longer for the computer to figure out if the point was valid or not)
|
|
|
|
|
Logged
|
Unfortunately, turning a section into a communist oppressive regime is not against the forum rules, so there is really nothing we can do. 21:08 - Hullusorsa: lorgan, when will you buy us the keys? 21:09 - Lorgan: i'm waiting for greece to collapse so the value of the euro drops 21:09 - Lorgan: not even joking
|
|
|
Orpheon
2011 Haxxy Award Winner
Offline
Posts: 5818
Developer
|
 |
« Reply #6 on: March 18, 2012, 10:08:43 am » |
|
Wait what's the difference between 4D and 3D?
3D has 3 axes that are all perpendicular to each other (x, y and z). 4D has 4 axes that are all perpendicular to each other (x, y, z and w) Also, nice fractals. Code?
|
|
|
|
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
Lorgan
Retired Randomizer Mod Developer
2011 Haxxy Award Winner
Online
Posts: 2967
check my new game in new projects k thx bye
|
 |
« Reply #7 on: March 18, 2012, 11:01:21 am » |
|
Wait what's the difference between 4D and 3D?
3D has 3 axes that are all perpendicular to each other (x, y and z). 4D has 4 axes that are all perpendicular to each other (x, y, z and w) Also, nice fractals. Code? i still don't get how 4D looks lol Messy and probably inefficient code but anyways: import sys, pygame pygame.init() from pygame.locals import * size = width, height = 800,800 white = 255,255,255 pygame.display.set_caption("Fracal thingy")
#seed thing print("enter c") re=input("real part: ") im=input("complex part: ") attractor=[]
#calculating whether the number is infinite or not def init(): i=0 a=0 b=0 last=[] while i < 400: a1=a**2-b**2+re b=(2*a*b)+im a=a1 if i > 390: last.append((round(a,3),round(b,3))) i+=1 if a > 100 or b > 100: return -1 for coord in last: if not coord in attractor: attractor.append(coord) return 0 def check(a,b): i=0 while 1: a1=a**2-b**2+re b=2*a*b+im a=a1 i+=1 if a > 2 or b > 2 or i > 400: return -i elif (round(a,3),round(b,3)) in attractor: return i return -i
if init() == -1: print "Overflow error! Try something smaller." else: screen = pygame.display.set_mode(size) #draw the background first screen.fill(white) pygame.display.update() print(attractor) a= -2 while a < 2: b = -2 while b < 2: test = check(a,b) if test < 0: pygame.draw.rect(screen,(min(-test*3+50,255),min(-test*3+50,255),min(-test*3+50,255)),((a*200+400,b*200+400),(1,1)),1) else: pygame.draw.rect(screen,(max(255-test,0),min(test,255),0),((a*200+400,b*200+400),(1,1)),1) b+=0.005; #update the screen after every generated column pygame.display.update() a+=0.005; pygame.image.save(screen,"fractal("+str(re)+"+"+str(im)+"i).png") print "saved!"
as soon as you enter the constant, don't touch anything until it's done rendering, it's somewhat buggy. Just wait for it to be done calculating and then look at the picture it saved. Also the constant has to be really small for it to work (-0.7+0.1i for example)
|
|
|
|
|
Logged
|
Unfortunately, turning a section into a communist oppressive regime is not against the forum rules, so there is really nothing we can do. 21:08 - Hullusorsa: lorgan, when will you buy us the keys? 21:09 - Lorgan: i'm waiting for greece to collapse so the value of the euro drops 21:09 - Lorgan: not even joking
|
|
|
Orpheon
2011 Haxxy Award Winner
Offline
Posts: 5818
Developer
|
 |
« Reply #8 on: March 18, 2012, 12:00:14 pm » |
|
Wait what's the difference between 4D and 3D?
3D has 3 axes that are all perpendicular to each other (x, y and z). 4D has 4 axes that are all perpendicular to each other (x, y, z and w) Also, nice fractals. Code? i still don't get how 4D looks lol Messy and probably inefficient code but anyways: import sys, pygame pygame.init() from pygame.locals import * size = width, height = 800,800 white = 255,255,255 pygame.display.set_caption("Fracal thingy")
#seed thing print("enter c") re=input("real part: ") im=input("complex part: ") attractor=[]
#calculating whether the number is infinite or not def init(): i=0 a=0 b=0 last=[] while i < 400: a1=a**2-b**2+re b=(2*a*b)+im a=a1 if i > 390: last.append((round(a,3),round(b,3))) i+=1 if a > 100 or b > 100: return -1 for coord in last: if not coord in attractor: attractor.append(coord) return 0 def check(a,b): i=0 while 1: a1=a**2-b**2+re b=2*a*b+im a=a1 i+=1 if a > 2 or b > 2 or i > 400: return -i elif (round(a,3),round(b,3)) in attractor: return i return -i
if init() == -1: print "Overflow error! Try something smaller." else: screen = pygame.display.set_mode(size) #draw the background first screen.fill(white) pygame.display.update() print(attractor) a= -2 while a < 2: b = -2 while b < 2: test = check(a,b) if test < 0: pygame.draw.rect(screen,(min(-test*3+50,255),min(-test*3+50,255),min(-test*3+50,255)),((a*200+400,b*200+400),(1,1)),1) else: pygame.draw.rect(screen,(max(255-test,0),min(test,255),0),((a*200+400,b*200+400),(1,1)),1) b+=0.005; #update the screen after every generated column pygame.display.update() a+=0.005; pygame.image.save(screen,"fractal("+str(re)+"+"+str(im)+"i).png") print "saved!"
as soon as you enter the constant, don't touch anything until it's done rendering, it's somewhat buggy. Just wait for it to be done calculating and then look at the picture it saved. Also the constant has to be really small for it to work (-0.7+0.1i for example) Interesting. What's the algorithm? Also, I'm seeing this a+=0.005 ;Please don't do that. Not in Python. For making images, pygame is good, but maybe you'd want to use PIL (Python Image Library). It lets you create an image directly, and write the individual pixel values. from PIL import Image
global PICTURE_WIDTH, PICTURE_HEIGHT PICTURE_WIDTH, PICTURE_HEIGHT = 500, 500
image = Image.new("RGB", (PICTURE_WIDTH, PICTURE_HEIGHT))
for x in range(PICTURE_WIDTH): for y in range(PICTURE_HEIGHT): color = (255, 0, 0) # Red image.putpixel((x, y), color) image.save("image.png") Idk if it's better. And about 4D, it's probably impossible for a human being to visualize 4D stuff, our brains are simply not wired for it. But maths can still describe it. It's basically a space where you need 4 coordinates to represent a point. Where there are infinite lines that are perpendicular to 2 lines, and even more (lol) that are perpendicular to 1. PS: One last thing, if you add from __future__ import division this will happen 1/2 = 0.5 and not this 1/2 = 1 # integer division-->rounding
|
|
|
|
« Last Edit: March 18, 2012, 12:01:54 pm by Orpheon »
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
|
BassieEnAdriaan
|
 |
« Reply #9 on: March 18, 2012, 02:29:10 pm » |
|
Totally against the boards rules, however I'll allow it to see how it turns out. If it turns out  I'll make it all sticky.
|
|
|
|
|
Logged
|
If you find any offensive posts in strategy and tactics or the new projects section, don't use the report post button, but PM me instead. That way I can respond faster since I don't frequently check my email. 
|
|
|
|
Dusty
|
 |
« Reply #10 on: March 18, 2012, 02:35:12 pm » |
|
I don't see how this is against the rules.
|
|
|
|
|
Logged
|
|
|
|
Orpheon
2011 Haxxy Award Winner
Offline
Posts: 5818
Developer
|
 |
« Reply #11 on: March 18, 2012, 02:55:42 pm » |
|
Oh also, Lorgan, tried making a real-time thing where you can zoom in?
|
|
|
|
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
|
BassieEnAdriaan
|
 |
« Reply #12 on: March 18, 2012, 03:09:17 pm » |
|
I don't see how this is against the rules.
As the board rules state you can brainstorm for your projects in here (ideas thread) and game development. This thread is just a bin full of little games.
|
|
|
|
|
Logged
|
If you find any offensive posts in strategy and tactics or the new projects section, don't use the report post button, but PM me instead. That way I can respond faster since I don't frequently check my email. 
|
|
|
|
Dusty
|
 |
« Reply #13 on: March 18, 2012, 03:20:57 pm » |
|
I looked at the rules, there's no specific thing saying that we can't have a thread like this, nor a rule saying that brainstorming has to be in the Ideas Thread.
|
|
|
|
|
Logged
|
|
|
|
Lorgan
Retired Randomizer Mod Developer
2011 Haxxy Award Winner
Online
Posts: 2967
check my new game in new projects k thx bye
|
 |
« Reply #14 on: March 18, 2012, 03:30:17 pm » |
|
Interesting. What's the algorithm? uhhhh... you mean this? f(Z)=Z^2+c f(Z)=(x1+y1i)^2+x2+y2i f(Z)=x1^2+2*x1*y1i-y^2+x2+y2i => x=x1^2-y1^2+x2 => yi=2*x1*y1i+y2i
And then it uses x and yi as x1 and y1i in the next loop. When z0 = (0,0) you will keep getting the same output after looping a few times (the attractor list). Then the script checks every z from (-2,-2) to (2,2). if it has the same output as z0, if it has it will get a color, if not it will be gray.
Also, I'm seeing this a+=0.005 ;Please don't do that. Not in Python. Hehe, i'm so used to doing that that i do it without knowing i guess.For making images, pygame is good, but maybe you'd want to use PIL (Python Image Library). It lets you create an image directly, and write the individual pixel values. from PIL import Image
global PICTURE_WIDTH, PICTURE_HEIGHT PICTURE_WIDTH, PICTURE_HEIGHT = 500, 500
image = Image.new("RGB", (PICTURE_WIDTH, PICTURE_HEIGHT))
for x in range(PICTURE_WIDTH): for y in range(PICTURE_HEIGHT): color = (255, 0, 0) # Red image.putpixel((x, y), color) image.save("image.png") Idk if it's better. does that also draw the image on the screen?And about 4D, it's probably impossible for a human being to visualize 4D stuff, our brains are simply not wired for it. But maths can still describe it. It's basically a space where you need 4 coordinates to represent a point. Where there are infinite lines that are perpendicular to 2 lines, and even more (lol) that are perpendicular to 1. okayPS: One last thing, if you add from __future__ import division this will happen 1/2 = 0.5 and not this 1/2 = 1 # integer division-->rounding what do you mean with this and why do you mention it? Do i need that somewhere? Also what is __future__?Oh also, Lorgan, tried making a real-time thing where you can zoom in?
my script currently needs about a minute for every image, how could i make this real-time lol I don't see how this is against the rules.
As the board rules state you can brainstorm for your projects in here (ideas thread) and game development. This thread is just a bin full of little games. Okay but this seemed the best place to post it...
|
|
|
|
|
Logged
|
Unfortunately, turning a section into a communist oppressive regime is not against the forum rules, so there is really nothing we can do. 21:08 - Hullusorsa: lorgan, when will you buy us the keys? 21:09 - Lorgan: i'm waiting for greece to collapse so the value of the euro drops 21:09 - Lorgan: not even joking
|
|
|
|