Welcome, Guest

Author Topic: Coding  (Read 182248 times)

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #210 on: April 15, 2013, 06:01:57 PM »
wait actually that wasn't the problem, this is:


sum = 0
for key in dict:
    for object in dict[key]:
        sum += 1
>sum of 120,000

sum = 0
for key in dict:
    for object in dict[key]:
        sum += 1
        if something:
            delete from the list
>sum of 76000


ok i'm suspecting the deleting is screwing with the list

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #211 on: April 15, 2013, 06:07:26 PM »
^it was i've fixed it

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #212 on: April 15, 2013, 06:11:32 PM »
example of problem:
count = 0
derp = range(1000)
import random
for int in derp:
    count +=1
        if random.random() < 0.5:
            derp.remove(int)
print count
>>>667
thats not a thousand ponies, thats 667, and that's a problem >.<

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #213 on: April 17, 2013, 02:18:08 PM »
.

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #214 on: May 06, 2013, 09:37:02 PM »
idk if i posted this here but i need this

Code: [Select]
import math

g = 6.67384
list = []
gravity = []
thetas = []

def calc_grav(m1, m2, r):
f = g*((m1*m2)/r**2)
return f

def calc_rt(x1, y1, x2, y2):
x = x2 - x1
y = y2 - y1
c = math.sqrt(x**2 + y**2)
theta = math.degrees(math.acos(x/c))
return c, theta

class object:
lx = 0
ly = 0
lr = 0
lt = 0
mass = 0
vx = 0
vy = 0
vr = 0
vt = 0
def __init__(self, x, y, r, t, m, vx, vy, vr, vt):
self.lx = x
self.ly = y
self.lr = r
self.lt = t
self.mass = m
self.vx = vx
self.vy = vy
self.vr = vr
self.vt = vt

#generate two test objects
sun = object(0.0, 0.0, 0.0, 0.0, 1000.0, 0.0, 0.0, 0.0, 0.0)
pl1 = object(1000.0, 0.0, 1000.0, 0.0, 10.0, 0.0, 40.0, 40.0, 90.0)
pl2 = object(2000.0, 0.0, 2000.0, 0.0, 15.0, 0.0, 15.0, 15.0, 90.0)

list.append(sun)
list.append(pl1)
list.append(pl2)

#calculate gravitational force
i = 0
for o in list:
j = 0
for p in list:
# print "%s, %s" % (i, j)
if i >= j:
pass
else:
d = calc_rt(o.lx, o.ly, p.lx, p.ly)
gravity.append(calc_grav(o.mass, p.mass, d[0])) #do i really need arrays yet?
# thetas.append(d[1])
j += 1
i += 1

print gravity
#print thetas

#--TO DO--
#calculate magnitude of force ^^^^^^^^^^^^^^^
#calculate direction of force ^
#calculate x, y of the force
#add to initial motion vector (x, y)
#store this final vector so that it can be used next iteration, and multiply the vector by the timestep to get the new location of all objects

#add config file for custom simulations
#add output file

Darvince

  • *****
  • Posts: 1837
  • 差不多
Re: Python
« Reply #215 on: May 06, 2013, 10:14:07 PM »

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #217 on: May 09, 2013, 06:27:45 PM »
1 dimensional fourier transform implementation

Code: [Select]
e = 2.7182818
pi = 3.1415926
i = 1j

def summation(bottom, bign, function, m, x):
    sum = 0
    for n in xrange(0, bign):
        sum = sum + function(m, x, n, bign)
    return sum

def sumfun(m, k, smalln, bign):
    return e**(-i*2*pi*k*smalln/bign)*m[smalln]

def fft(m): #list
    bign = len(m)
    r = [0]*bign
    for x in xrange(0,bign):
        r[x] = summation(0, bign, sumfun, m, x) #xn and k
    return r

m = [3,2,0,1]

print fft(m)/code]

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #218 on: June 12, 2013, 03:10:24 AM »
you need pygame (module) for this

a test game thing

oh wait you need my car file too (put it in the same folder as the script is)

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #219 on: June 12, 2013, 03:36:14 AM »
gneiss

worst name ever though

ok i've figured out how to turn

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #220 on: June 12, 2013, 03:38:51 AM »
you might want directions

up arrow - 'gas'
down arrow - 'brake' (i want to make these function more like them)
left arrow - pivot left
right arrow - pivot right

page up - drive (you start in neutral)
page down - reverse

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #221 on: June 12, 2013, 04:52:52 AM »
solution: play f1 instead

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #222 on: June 12, 2013, 11:47:11 AM »
you might want directions

up arrow - 'gas'
down arrow - 'brake' (i want to make these function more like them)
left arrow - pivot left
right arrow - pivot right

page up - drive (you start in neutral)
page down - reverse


wait whats the difference between the gas pedal and the drive pedal if i just press gas will a pile of gasoline start leaking out

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #223 on: June 12, 2013, 12:07:32 PM »
you can't drive in the neutral gear, so you have to put the car in drive and then you can use the gas to accelerate!

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #224 on: June 12, 2013, 01:41:11 PM »
now add gas and prevent the car from going off screen

and is it just me or is the acceleration constant unused

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #225 on: June 12, 2013, 03:22:20 PM »
it's unused atm

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #226 on: June 26, 2013, 04:12:07 PM »
hashcash generator with size argument and writing to file

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #227 on: June 26, 2013, 07:53:52 PM »
a value of 100,663,296 in hashcash

Code: [Select]
N8qX4e1ZlDRpstt2AxSDYSR7onRKcDdJ3sh8H77ZJqRJbS1tWnp7Qq53GEXuFi6h
GHB4V0bub7cppl3SARH3wCGgzdjCHcg9jSWj116nvAAIJJXnUPkIbZzwXR7EMFjm
Ae0xRoh0q2ciKAh4kl05mwufEgJEFY4RiipD26AwyQq1Hy4MyMVMiGIYTL3KZMGt
cy74uw95TcF5i5mqWpcse0DCO0CEp6LMhzFcwCwMBzHl1Os2KPznysSBt7pMs9vC
6EXhgO4s9W8JWP0JDAljlSjEVviGxzuDcFxTLPPCMFozQAvaZNLmy6FTOxTLulhW
VbioCBvUqlqhzBS6iBa1y5gnL8wXamMRsFvgPCgnytOmG6iDzzvElRm53Kc26aHB

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #228 on: June 29, 2013, 08:43:45 PM »
Code: [Select]
print "1D pressure-gradient force simulation"

dx = 100000 #m
v = 0
j = 0

i = raw_input("Iterations: ")
i.strip('\n')

def calc(v, dx):
a = (-1/1.275) * (500/dx)
preV = a*60 #ms^-2 * s --> ms^-1
v += preV
dx += v*60 #ms^-1 * s --> m | distance moved is ????'d
return v, dx

while j < int(i):
data = calc(v, dx)
v = data[0]
dx = data[1]
print str(v) + " m/s, " + str(dx) + " m\n"
j += 1

#equalizing pressure?

idk if i'm doing this right...

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #229 on: June 30, 2013, 08:42:11 PM »
Code: [Select]
import math

print "Coriolis parameter calculation"

deglat = raw_input('Latitude: ')
lat = int(deglat)*(math.pi/180)

calc = 2*((2*math.pi)/24)*math.sin(lat)

print str(calc) + " (coriolis parameter)"

v = [15, 0] #ve, vn | m/s | chosen default values
a = [v[1]*calc, -v[0]*calc]

print a

I think i'm doing this right but still pressure gradient force looks suspicious

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #230 on: July 04, 2013, 02:17:18 AM »
soo i'm sharing this because the psutil module is pretty neat



here, g is the python27.exe process, and i'm running a cpu heavy script. if i'm trying to play ksp or something, i want the thread to pause so more cpu power can go towards what i'm currently doing. to detect this, i measure if the cpu utilization is high, yet the python utilization of the cpu is lower than 90% of the cpu utilization, then pause it. if the cpu usage decreases afterwards, the process resumes

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #231 on: July 04, 2013, 02:31:53 AM »
this is a better version

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #232 on: July 04, 2013, 12:16:05 PM »
does it do it automatically or did you code something that you didn't post here? :P

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #233 on: July 04, 2013, 01:19:50 PM »
it's automatic :), the while loop just runs the detection forever

if you are pausing a python process though, you have to be careful because there will be two python processes, the script you're running, and the interpreter i have open here

i had to find the process id manually, but it only took a minute, and i'm sure you can automate it if you want

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #234 on: July 04, 2013, 02:02:48 PM »
no i mean actually running it

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #235 on: July 04, 2013, 02:16:39 PM »
huh

yeah that while loop is all the code i used

atomic7732

  • Global Moderator
  • *****
  • Posts: 3829
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #236 on: July 04, 2013, 04:59:55 PM »
how do you run multiple lines in cmd

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #237 on: July 04, 2013, 06:04:19 PM »
huh

this was interpreter
but you can do it on cmd too, just type in 'python' (without quotes) or in my case, python27 because i renamed it, and the cmd turns into an interpreter

vh

  • formerly mudkipz
  • *****
  • Posts: 1138
  • "giving heat meaning"
Re: Python
« Reply #238 on: July 06, 2013, 10:03:03 AM »
the captionator adds captions to all your images quickly and efficiently

tell me if you have any bugs regarding how well the text fits

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #239 on: July 06, 2013, 10:10:14 AM »
what do you have to import