r/programminghelp • • Apr 10 '16

Python, attempting to figure out why my code always rounds down instead of just using the given value.

I'm sorry for including all of the code instead of any tiny relevant bits, but that's probably actually useful. When you run the program and insert the variables, ARMROTS always is rounded down to the nearest whole number.

http://pastebin.com/33XhsvHX

4 Upvotes

23 comments sorted by

0

u/[deleted] Apr 10 '16

[deleted]

1

u/TangleF23 Apr 10 '16 edited Apr 10 '16

Import image is from PIL, which I use instead of PILLOW because this uses it and when I tried to use PILLOW it didn't work even when I changed the module. I learned nearly all of what I know of coding from this, you see...

The rest is from inputting variables.

I think I should've facepalmed at change 3- I knew what int and float meant, but I guess I wasn't going intuitively enough...

By the way, here's what I did from it:

1- Downloaded the original thing from a nonfunctional blog on webarchive.

2- Got all the requirements, including a hard-to-find 64bit PIL (distribution? installation?)

3- Had fun with the variables and looked at how it worked, terrified to mess with the actual star generation

4- Figured out how to make lenticular galaxies (just make the arms very ill-defined)

5- Figured out how to make elliptical galaxies (I had to change the code for this- involved removing all "disk" values and changing HUBRAD to HUBX and HUBY

6- Figured out how to make ring galaxies (Lots of wide spiral arms)

7- Decided it would be a good idea to make a "universal generator" because I was tired of opening it up in brackets or a less-functional program and changing the value every time and accidentally overwriting the original file

8- Grabbed the input code directly from... a program for drawing dragon curves.

9- Separate the original "universal one" (which is only really able to do spirals) into ones meant for Ring, Lenticular, Irregular, and Elliptical galaxies. The Lenticular one uses an easier method than before- a version of the Elliptical script, but only using HUBX. Irregular is not-quite-working at the moment- it currently creates a weird clump at low sizes and a single pixel at larger ones.

I actually asked for help on stackoverflow, about a different problem- I wanted to figure out how to get presets from a file (but I got no responses.)

By the way, about the irregular one- I think the problem stems from not having anything for spacing. Would random.randrange(0, HUBX) work for that? I'll try it right now, actually. Right after I see if spirals work with that code.

1

u/TangleF23 Apr 10 '16 edited Apr 10 '16

Okay, now that I've tried it out- the program you gave results in a failure that, of course, closes the window before I can actually see the error. I'll see if working on some of the formatting in def GenerateStars works.

Edit: Turns out that stuff is in the original file... I'll see if removing the stuff for the filename works.

Edit2: Nope.

0

u/[deleted] Apr 10 '16

[deleted]

1

u/TangleF23 Apr 10 '16

Program is running on Python 2.7 with the 64bit PIL I could find. Python is running on Windows 7.

0

u/[deleted] Apr 10 '16

[deleted]

1

u/TangleF23 Apr 10 '16

Thanks!

0

u/[deleted] Apr 10 '16

[deleted]

1

u/TangleF23 Apr 10 '16

Thank you so much. I like how the spiral arms look like they're about to collapse into a ring, but aren't quite there yet- see Hoag's Object. Also, the elliptical version can technically be used to generate views of the galaxy from the side.

0

u/[deleted] Apr 10 '16

[deleted]

0

u/[deleted] Apr 10 '16

[deleted]

1

u/TangleF23 Apr 10 '16 edited Apr 10 '16

To confirm, the "path" is C:\User\ [USER]\Python27, right? Don't want to install it a third time... (oops, duh, it's later in the install...)

Also, how about I just give the galaxy a random number? Current code for that:

Quick Filename

RAND = random.randrange(0, 999999)

drawToPNG("spiralgalaxy" + str(RAND) + ".png")

Confirmed to work, although with my haphazardly-entered values spiralgalaxy160609 is kinda ugly.

Edit: Restarting now.

0

u/[deleted] Apr 10 '16

[deleted]

1

u/TangleF23 Apr 10 '16

Okay. Virtualenv is incredibly confusing, and I have no idea how to use it at all, especially because I can't open it in the command line. I think the only thing I can actually manage is editing it through brackets. Currently working on updating the Ring, Lenticular, Elliptical, and Irregular code to work the same way as the Spiral generation.

→ More replies (0)