Welcome, Guest

Author Topic: Coding  (Read 276135 times)

Hellpotatoe

  • *****
  • Posts: 230
  • JooJ
Re: Python
« Reply #180 on: March 29, 2013, 03:09:40 AM »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #181 on: March 29, 2013, 04:49:40 AM »
wow that's amazing
why did that sound sarcastic

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #182 on: March 29, 2013, 06:14:25 AM »
i'm done.

the image takes a few minutes to generate. (a bit less than 10)

the number of provinces increases the time needed linearly
the map size increases the time quadratically, but changing the map size increases the provinces too which means it's really n^3
« Last Edit: March 29, 2013, 06:25:36 AM by vh »

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #183 on: March 29, 2013, 06:41:31 AM »
wow that's amazing
why did that sound sarcastic
probably because you always percieve my sarcasm as non-sarcastic

because that wasn't sarcasm

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #184 on: March 29, 2013, 06:57:14 AM »
here's an image that was generated and i resized to 10%

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #185 on: March 29, 2013, 07:04:46 AM »
ispythecolorsofbla

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #186 on: March 29, 2013, 07:12:34 AM »
that works

i will work on the file generation this weekend

you might have to remind me, and not today, on saturday please

karakris

  • *****
  • Posts: 162
Re: Python
« Reply #187 on: March 29, 2013, 09:15:57 AM »
Lame Curves

Circular Arcs are just ONE Form of the Lame Curves.

I "Invented" these in 1992 - but found out two weeks back, that they had already been invented
Boo Hoo :( :( :( :(.

To generate ONE Quadrant - where X and Y are both Positive with respect to the "centre" of the figure ( 0,0 ).
And using a "normalised" Figure - 1 Wide, 1 High.

Pythagorus gives us that any point on a Circular sweep will be given by Y = ( 1^2 -  x^2 )^0.5.
Where 1 is the Hypotenuse ( Radius ).

To alter the "normalised" figure to an Oval, the Values of XScale and YScale should be different.
In creasing both Xscale and Yscale by the same amount gives simply a larger figure.   

For X = 0 to 1 Step 0.000001
Y = SQRT ( 1 - X^2 ):
XPlot = X*Xscale: YPlot = Y*YScale:
Plot Xplot, YPlot:
Next X

For the Full Circle, we need to "handle" Negative X and Y Values.

So - we get -

For X = 0 to 1 Step 0.000001
Y = SQRT ( ABS ( 1 - X^2 ):
XPlot = X*Xscale: YPlot = Y*YScale:
Plot Xplot, YPlot:
Next X
For X = 0 to 1 Step 0.000001
Y = SQRT ( ABS ( X^2 - 1 ):
XPlot = X*Xscale: YPlot = Y*-YScale:
Plot Xplot, YPlot:
Next X
For X = 0 to 1 Step 0.000001
Y = SQRT ( ( 1 - X^2 ):
XPlot = X*-Xscale: YPlot = Y*-YScale:
Plot Xplot, YPlot:
Next X
For X = 0 to 1 Step 0.000001
Y = SQRT ( ABS ( X^2 - 1 ):
XPlot = X*-Xscale: YPlot = Y*YScale:
Plot Xplot, YPlot:
Next X

Now - What use is that ??

Well - for a CIRCLE - Not a LOT.

However - the critical change is if we place the Circle in "distorted" 3-D Space.

If instead of SQRT ( Square Root ) and ^2 ( Square ) which are true for a Circle - we substitute
The "Power" of 1/N  and the "Power" of N.
Then strange things happen to our curved figure.

The "program" for the First Quadrant then becomes -

For X = 0 to 1 Step 0.000001
Y = ( 1 - X^N )^1/N:
XPlot = X*Xscale: YPlot = Y*YScale:
Plot Xplot, YPlot:
Next X

As N is reduced to a little less than 2 - the curves start to "flatten" in each Quadrant, although the Rate of Change of Curvature remains consistent.  They also become a little "sharper" at the meeting of Quadrants
As N is increased to a liitle more than 2 - the curves become "sharper"in each Quadrant, although the Rate of change of Curvature remains consistent.  They also become "flatter" at the meeting of Quadrants.

The Lame Curves are ALWAYS Transition Curves - with no points of sudden acceleration or sudden develeration of curvature.
At modest values of N - they could be used to lay out Roads or the curves of Railway Track.

How about bigger changes in the value of N -

At exactly N =1 - we get a diamond shape, a square rotated by 45 degrees.

At truly Massive values of N ( up to 10^30 ) - we get an almost Square, with very slightlty curved sides asnd nearly sharp, curved corners.

At truly Miniscule values of N ( down to 1/10^30 ) - we get an almost cross ( or crux ) - except that the middle is slighty fatter than the intersection of two straight lines, it actually comprises a very slightly curving line in each Quadrant, which turns through 90 degrees in an incredibly tight curve, very near to the centre.

A wide range of these Curves can be used for Transition Curves with different "orders" of Curvature, in a number of applications.

For example - to create a range of "Ship Curves" for laying-out a Scale Drawing of a Ship's Hull - the Values of Xscale ( length ) and YScale ( half beam ) can be set to the desired values for the Drawing.
By changing the values of N through a range of values the - both "convex" and "concave" transition curves or useful Ship Curves can be generated.

Okay - this all sounds like fancy theory.
However - I have tried this, and it does work.

I Ran this as a Program, many times in 1992 on the Mainframe Computer at Thames Polytechnic.
With Step Values as small as 1/10^12 and values of 'N' from 10^40 down to 1/10^40 -
in both directions ( massive and miniscule values of 'N' ).
As I have already implied - Values of 'N' ( the "order" of the Curves ) between 10 and 1/10 are more useful than the more extreme examples.

I have also Run this as a Program on my BBC Microcomputer - although the range of values of 'N' and the maximum number of Steps had to be reduced seriously.

In all cases, the Program worked exactly as Predicted, and as Described above.                 
 


   

 

karakris

  • *****
  • Posts: 162
Re: Python
« Reply #188 on: March 29, 2013, 09:18:45 AM »
Re: A Random Word Generator -

One of those would immensely useful.

I am running a Sci Fi Game - some Human Star Systems, some Alien Star Systems.
The Names of Planets, Continents, Cities all have to be "Invented" in many cases -
a Random Word Generator may help makr my Job easier.   

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #189 on: March 29, 2013, 11:48:50 AM »
cute

the wikipedia page on the curves you described in general is here

http://en.wikipedia.org/wiki/Superellipse

FiahOwl

  • *****
  • Posts: 1234
  • This is, to give a dog and in recompense desire my dog again.
Re: Python
« Reply #190 on: March 29, 2013, 12:08:55 PM »

This message is only viewable with Universe Sandbox Galaxy Edition. Access it and much more with promo-code '102925'.

« Last Edit: March 22, 2021, 01:53:09 AM by FiahOwl »

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #191 on: March 29, 2013, 12:35:10 PM »
don't we all

Darvince

  • *****
  • Posts: 1842
  • 差不多
Re: Python
« Reply #192 on: March 29, 2013, 01:22:04 PM »
TIL god has a sake

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #193 on: March 29, 2013, 02:29:13 PM »
Re: A Random Word Generator -

One of those would immensely useful.

I am running a Sci Fi Game - some Human Star Systems, some Alien Star Systems.
The Names of Planets, Continents, Cities all have to be "Invented" in many cases -
a Random Word Generator may help makr my Job easier.   
kip and I both made different generators but they only generate words based on our conlangs, if you could even call Kip's that

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #194 on: March 31, 2013, 02:50:12 PM »
before

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #195 on: March 31, 2013, 02:50:52 PM »
after

blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #196 on: March 31, 2013, 03:36:51 PM »

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #197 on: April 02, 2013, 09:56:50 PM »
partially finished thing

i will probably do python all week because i do not productive on weekends at all

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #198 on: April 05, 2013, 11:22:03 PM »
i fixed the memory error by splitting the gigabyte list into it's elements and pickling each

you can see all the times when the program crashed here, it's currently running smoothly


blotz

  • Formerly 'bong'
  • *****
  • Posts: 813
  • op pls
Re: Python
« Reply #199 on: April 06, 2013, 01:39:53 AM »
whats up with the red line

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #200 on: April 10, 2013, 10:18:33 AM »
Code: [Select]
import random
import math

all = []

class particle:
x = 0.0
y = 0.0
def __init__(self, x, y):
self.x = x
self.y = y

def distance(x1, x2, y1, y2)
x = math.fabs(x2 - x1)
y = math.fabs(y2 - y1)
math.hypot(x, y)

def interact(obj1, obj2):
force = 1/(distance(obj1.x, obj2.x, obj1.y, obj2.y) ** 2)
#find the direction both objects are going somehow and then make them attract
w = "%s\t%s\t\n" % () #bakjfdsjk
f.write(w)

n = int(raw_input("Number of particles: "))

for x in xrange(0,n):
all.append(particle(random.random()*7, random.random()*7))

i = 0
f = open('data.txt', 'w')
for x in all:
w = "%s\t%s\t%s\t" % (i, x.x, x.y)
f.write(w)
i += 1

f.write("\n")

i = 0
for x in all:
j = 0
for y in all:
if i <= j:
interact(x, y)
else:
pass
j += 1
i += 1

f.close()

print "done"
stupid particle kind of like the stupid other simulator actually i stopped at the same point, finding out which direction the object are going using arccos/sin because that only spans from 0 to pi radians or -pi/2 to pi/2 would i just add pi to get the other object? and then which object is the one's value i am actually getting?

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #201 on: April 10, 2013, 12:15:32 PM »
i'm going to suggest not using trig because that is slow

an example on how i would figure out the force of b acting on a

keep everything in component form vectors
so if you have bodies A and B

Av is the velocity vector of a. something like <0,0>.

force = mass*constant/distance^2
don't actually compute the distance by square rooting because you'll square it anyways in the end
if the position of A is <ax,ay> and the position of B is <bx,by>, then find the offset <bx-ax,by-ay>
then suppose the mass * constant = 8 and distance = 4, so force is 2

multiply the offset <bx-ax,by-ay> by 2 to get the force vector called Bf

force = mass*distance/time^2
divide by mass
acceleration = distance/time^2
multiply by time
velocity = distance/time

use the mass of A, the time is the length of your timestep

so Bf/mass*time = velocity

add the velocity vector to Av which is the velocity vector of object A

for every object you add their velocity vector to the velocity vector of A

then if you end up with the velocity vector <3,-2>, you move A right 3 units and down 2 units




atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #202 on: April 10, 2013, 02:23:40 PM »
I didn't get a chance to read the whole post yet, but I already have the force part down.

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #203 on: April 10, 2013, 03:16:01 PM »
ok thats nice

although i wanted to note that you were finding the distance with math.hypot which uses a square root. since you're going to square the distance afterwards, you should probably not bother with the square root operation which takes a bit of time.

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #204 on: April 10, 2013, 03:28:37 PM »
Ok all the post explained to me was what I already knew about simulating the stuff... and then you throw vectors in the last 3 lines. How do you suggest I do the vectors as I can't figure out the inverse trig functions and how that would work, and you say it'd be slow?

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #205 on: April 10, 2013, 03:59:00 PM »
vector = [thing1,thing2]

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #206 on: April 10, 2013, 04:15:15 PM »
I'm talking about you know, instead of using trig to get an angle and a magnitude (polar coordinates), how else you expect me to calculate where the thing is to move. Start from having the magnitude (distance calculated from acceleration and timestep).

Like... the part you skipped here:

for every object you add their velocity vector to the velocity vector of A

here

then if you end up with the velocity vector <3,-2>, you move A right 3 units and down 2 units

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #207 on: April 10, 2013, 04:18:40 PM »
ok i was mistaken you actually have to calculate the distance

there are objects x and y

object x is at position  with mass 6 and a velocity of 0,5
object y is at position 5,-3 with mass 7 and a velocity of -1,-2
the gravitational constant is 2

calculating the effect
the force is (6+7)*2/((5-2)^2+(3--3)^2) = 0.5777....

the movement of x:
relative to x, object y is at 3, -6 (5-2,-3-3)
the magnitude is sqrt(45) from sqrt(3^2+-6^2), however we want to make it 0.5777 because that is the force
0.577.../sqrt(45) * (3,-6) gives us (0.2583, -0.5168)

pretend the time step is 5 units of time
we multiply by 5 because the force is sustained for that long
(1.2915, -2.583)
then divide by the mass of object x since we are calculating the movement of object x
(0.2152,-0.4305)
by dividing by mass we've converted force to acceleration since
f = ma
f/m = a
now multiply by the lenght of the time step again
(1.076, 2.153)
acceleration = velocity/time (as in meters per second per second)
so (1.076, 2.153) is the velocity of motion that object y causes to object x

since there are no other objects which gravitationally pull x
(0,5) + (1.076, 2.153) = (1.076, 7.153) is the current velocity of object x

add velocity to position (2,3)
(3.076, 10.153)

repeat for y


disclaimer: i haven't taken physics so i have no idea what i'm talking about this all comes from one week of vectors in math

atomic7732

  • Global Moderator
  • *****
  • Posts: 3849
  • caught in the river turning blue
    • Paladin of Storms
Re: Python
« Reply #208 on: April 10, 2013, 04:23:53 PM »
yeah I think I'll just figure out the trig...

vh

  • formerly mudkipz
  • *****
  • Posts: 1140
  • "giving heat meaning"
Re: Python
« Reply #209 on: April 15, 2013, 05:53:43 PM »
i have  dictionaries with the values of the dictionary keys being a list, and the keys are strings

i want to count how many objects i have in the lists combined

strategy 1:
sum = 0
for key in dict:
    sum += len(dict[key])
>gets result of around 120,000

strategy 2:
sum = 0
for key in dict:
    for object in dict[key]:
        sum += 1
>get a result of 76,000

wtf