Welcome, Guest

Author Topic: Experiences with programming  (Read 3285 times)

vh

  • formerly mudkipz
  • *****
  • Posts: 1084
  • matty406 does not. stowaway does.
Experiences with programming
« on: October 03, 2011, 04:31:43 PM »
After reading the xkcd comic on python

*downloads python*

i read around 5 tutorials which took several hours

good, now i have at least 100 commands down

"hello world"
"1+2*54(4x)=432x+1"
i can change font color to red!

5 minutes of excited discovery

ok wtf can i actually do with this? i can make a bunch of colored letters and a text input calculator...

*gives up*

atomic7732

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 3239
  • live now or wonder where it all went
    • PegasiProgramming
Re: Experiences with programming
« Reply #1 on: October 03, 2011, 04:36:49 PM »
i has good experiences with VB

vh

  • formerly mudkipz
  • *****
  • Posts: 1084
  • matty406 does not. stowaway does.
Re: Experiences with programming
« Reply #2 on: October 03, 2011, 04:39:34 PM »
oh interesting
i'm fine with taking a while to figure anything out

but

can you actually get to the point where you can do something without text-based input?
because that seems extremely limiting to me (when its only text input)

like
pressing buttons? :P

atomic7732

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 3239
  • live now or wonder where it all went
    • PegasiProgramming
Re: Experiences with programming
« Reply #3 on: October 03, 2011, 04:40:22 PM »
It's Visual Basic. Universe Sandbox was made with it. ;D

I'm working on a new hurricane simulator in it. :)

vh

  • formerly mudkipz
  • *****
  • Posts: 1084
  • matty406 does not. stowaway does.
Re: Experiences with programming
« Reply #4 on: October 03, 2011, 04:44:58 PM »
visual basic...

visual basic...

visual basic...

visual

i'll assume its visual then :P

coincidentally, i got some huge visual basic 6 manual at a book sale for $2 :D (big manuals scare me...the boredom!)

atomic7732

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 3239
  • live now or wonder where it all went
    • PegasiProgramming
Re: Experiences with programming
« Reply #5 on: October 03, 2011, 04:46:56 PM »
it's pretty simple actually.

I'm getting Microsoft Visual Basic 2010 sometime soon, for free, cause of the programming class I'm taking. So basically I'm only working on it at school, currently.

Bla

  • Global Moderator
  • *****
  • Posts: 952
  • The stars died so you can live.
Re: Experiences with programming
« Reply #6 on: October 03, 2011, 10:06:39 PM »
I'm learning Java at school. Started after the summer vacation. It's awesome and very easy to understand now. Soon I'm going to make a program which can solve a quadratic equation. That's the first "big" project. I see our book also has chapters about GRAPHICS. ;D On one page it showed how to make a fractal tree as well.

deoxy99

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 868
  • Zaraza Zaraji of the Socialist Republic of Dark Light
    • Typography Newspaper
Re: Experiences with programming
« Reply #7 on: October 03, 2011, 10:09:08 PM »
I know Ruby, Perl, Python and all the website languages.

If only someone had a plugin for Ruby that allowed you to add graphics to it... I'll check on that now...

matty406

  • *****
  • Posts: 76
Re: Experiences with programming
« Reply #8 on: October 04, 2011, 07:05:40 AM »
Not fair, your schools offer programming classes, mine didn't.
I has a sad.

Bla

  • Global Moderator
  • *****
  • Posts: 952
  • The stars died so you can live.
Re: Experiences with programming
« Reply #9 on: October 04, 2011, 08:45:57 AM »
Code: [Select]
System.out.println("Kolkolkol. >:D");
We're also learning a bit of programming in another subject, information technology. We're learning a bit of ActionScript in it for Flash CS5, and some Scratch (mostly an option for those who didn't choose the programming/Java subject). I've had a lot of trouble making ActionScript work together with the graphical objects in Flash, but you can also make games in it.

I'm still most excited about Java. I've also tried Scratch - I began on a project to remake Map War 2 in it, but I've pretty much given up on that after a few days, there simply doesn't seem to be enough options available. I made a background map, some statistics with production, zones etc., a build button going to another menu with a level 1 city, which you can place on the map after clicking it. And I got it to change the statistics and added turns. And then I saw the single border-line I had drawn on the map, and realized how many individual zones I might have to make, how many times I would have to check WHETHER the city was placed on which zone, if there was already a city there, if it wasn't placed in the sea, etc... Not to speak of an AI, if you weren't going to play against yourself. And how I would have to make loads of copies of the cities.

As far as I understand, you can only have one instance of a sprite in Scratch. Amirite? Kol.

deoxy99

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 868
  • Zaraza Zaraji of the Socialist Republic of Dark Light
    • Typography Newspaper
Re: Experiences with programming
« Reply #10 on: October 04, 2011, 09:16:51 AM »
As far as I understand, you can only have one instance of a sprite in Scratch. Amirite? Kol.
No, I thought you were able to make multiple copies of a sprite on a screen.

Bla

  • Global Moderator
  • *****
  • Posts: 952
  • The stars died so you can live.
Re: Experiences with programming
« Reply #11 on: October 04, 2011, 09:29:58 AM »
Yes, but then you copy the instances and they become seperate sprites, right?
I know it keeps all the code and that up to the moment you copy it...

But I would need code which could create multiple instances of the same sprites. I know I didn't state that in my last post. :P

atomic7732

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 3239
  • live now or wonder where it all went
    • PegasiProgramming
Re: Experiences with programming
« Reply #12 on: October 04, 2011, 03:04:02 PM »
It would be a lot of copying.  :-\

vh

  • formerly mudkipz
  • *****
  • Posts: 1084
  • matty406 does not. stowaway does.
Re: Experiences with programming
« Reply #13 on: October 04, 2011, 03:17:47 PM »
ohhh

ai

ai stuff interests me

i don't like the games with crappy ai's that fall for simple tricks/traps.

that is all.

Bla

  • Global Moderator
  • *****
  • Posts: 952
  • The stars died so you can live.
Re: Experiences with programming
« Reply #14 on: December 08, 2011, 11:16:08 AM »
We started on graphics today in the programming class at school. :P
I asked the teacher whether he knew if there was a method which could fill out an area with same-colored pixels bordering each other, without defining the area in the program (like the paintbucket feature in Paint). He said that he didn't think so. :/

So today I made a program which generates an image where you look at the center of a spiral galaxy from somewhere in the galactic plane. The stars have randomly generated positions, but because there are so many (over 9,000, actually over 100,000), you probably won't notice the differencies. Maybe in the foreground stars. :P
And I haven't managed to generate the central bulge yet, I made one which generated a square bulge, but ofc it looked wierd and I made it a comment which I might fix later.

The program is attached below, but be aware that you will have to close it from the task manager. I'm considering if I should add a way to close it, maybe just by crashing it. But I would need a command prompt, and Idk how to add it. It's my first .jar file. :P

And yes, the code was made for the resolution on my laptop. It would be easy to make the code apply to any resolution based on two variables (x and y resolution, ofc), but not easy to make you able to actually type it in and adjust it, with my current knowledge.

Here's the code:
Main class:
Code: [Select]
package grafikprogram1208;
public class Grafikprogram1208
{
    public static void main(String[] args)
    {
        GrafiskVindue vindue = new GrafiskVindue(); //Opretter vinduet.
        vindue.setSize(1250,750); //Sætter vinduets størrelse.
        vindue.setTitle("GrafiskVindue"); //Sætter vinduets titel.
        vindue.setVisible(true); //Viser vinduet.
    }
}

GrafiskVindue class:
Code: [Select]
package grafikprogram1208;
import java.awt.*;
public class GrafiskVindue extends Frame
{
    public void paint(Graphics g)
    {
        //Herunder referer g til et Graphics-objekt, som man kan tegne med.
        g.fillRect(0,0,1250,750);
        g.setColor(Color.darkGray);
        for (int i=0; i<50000; i++) //Generates lower half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(375,(Math.random()))),1,1);
        }
        for (int i=0; i<50000; i++) //Generates upper half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(375,(Math.random()))),1,1);
        }
        g.setColor(Color.gray);
        for (int i=0; i<10000; i++) //Generates lower half of normal stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(375,(Math.random()))),1,1);
        }
        g.setColor(Color.gray);
        for (int i=0; i<10000; i++) //Generates upper half of normal stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(375,(Math.random()))),1,1);
        }
        g.setColor(Color.lightGray);
        for (int i=0; i<5000; i++) //Generates lower half of bright stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(375,(Math.random()))),1,1);
        }
        for (int i=0; i<5000; i++) //Generates upper half of bright stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(375,(Math.random()))),1,1);
        }
        for (int i=0; i<3000; i++) //Generates lower half of bright stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(50,(Math.random()))),1,1);
        }
        for (int i=0; i<3000; i++) //Generates upper half of bright stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(50,(Math.random()))),1,1);
        }
        g.setColor(Color.white);
        for (int i=0; i<2500; i++) //Generates close, bright, scattered foreground stars.
        {
            g.fillRect((int)(Math.random()*1250),(int)(Math.random()*750),1,1);
        }
        for (int i=0; i<1500; i++) //Generates large, close, bright, scattered foreground stars.
        {
            int a, b;
            a = (int)(Math.random()*1250);
            b = (int)(Math.random()*750);
            g.setColor(Color.gray);
            g.fillRect(a,b,2,2);
            g.setColor(Color.white);
            g.fillRect(a,b,1,1);
        }
        for (int i=0; i<3000; i++) //Generates lower half of brightest stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(30,(Math.random()))),1,1);
        }
        for (int i=0; i<3000; i++) //Generates upper half of brightest stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(30,(Math.random()))),1,1);
        }
        /*for (int i=0; i<1000; i++) //Generates the central bulge.
        {
            g.fillRect((int)(Math.random()*300)+475,(int)(Math.random()*300)+225,1,1);
        }*/
    }
}
« Last Edit: December 08, 2011, 12:28:34 PM by Bla »

deoxy99

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 868
  • Zaraza Zaraji of the Socialist Republic of Dark Light
    • Typography Newspaper
Re: Experiences with programming
« Reply #15 on: December 08, 2011, 11:18:34 AM »
AHHHHHHHHHHHH! I DON'T UNDERSTAND!!!! :P

Bla

  • Global Moderator
  • *****
  • Posts: 952
  • The stars died so you can live.
Re: Experiences with programming
« Reply #16 on: December 08, 2011, 11:37:02 AM »
I use a power feature to make progressively more stars towards the central horizontal line in the image.
Look at this:

for (int i=0; i<50000; i++) //Generates lower half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(375,(Math.random()))),1,1);
        }

A for loop which runs 50,000 times, because i is set to 0, then the loop is defined to run while it is below 50,000, and at last "i" is told to increment every time it runs through the loop.

Inside the loop, the { and } tell the program that that is what it has to do inside the loop. It ignores what is after until the loop is broken.

The a method tells it to feel a rectangle. The parameters are inside (), and they are:
(x position, y position, width, height)
(0,0) in Java is the top left corner, not bottom left like on normal coordinate systems. So x's are "inverted".
So by setting the last two numbers to 1, the stars become 1 pixel.
The first parameter (x position) is
(int)(Math.random()*1250)
(int) tells it to convert the number to an integer, because pixel positions must be integers.
This generates the number: (Math.random()*1250)
Math.random() gives a random number from 0 to 1, with a lot of decimals. It is multiplied to 1250, so it becomes a number between 0 and 1250.

This is the y-position parameter:
(int)(374+Math.pow(375,(Math.random())))
Math.pow(a,b) calculates what c would be here: c = ab
So by setting a = 375 and uplifting it in a random number between 0 and 1, I get a number between 0 and 375, but where progressively more numbers will be closer to 0. By adding 374 to that, I get numbers between 0+374 and 375+374.

The result is scattered, dark grey pixels on the lower half of the window, and where they will get increasingly dense towards the center of the screen.
I used 4 colors, starting with dark grey, then going to white at last, and each time I only generate the lower or upper half of the window (in most cases).
« Last Edit: December 09, 2011, 06:29:38 AM by Bla »

FiahOwl

  • *****
  • Posts: 1187
  • pinkyee pie
Re: Experiences with programming
« Reply #17 on: December 08, 2011, 12:04:31 PM »
We started on graphics today in the programming class at school. :P
I asked the teacher whether he knew if there was a method which could fill out an area with same-colored pixels bordering each other, without defining the area in the program (like you probably did in Paint in Map War 2). He said that he didn't think so. :/

So today I made a program which generates an image where you look at the center of a spiral galaxy from somewhere in the galactic plane. The stars have randomly generated positions, but because there are so many (over 9,000, actually over 100,000), you probably won't notice the differencies. Maybe in the foreground stars. :P
And I haven't managed to generate the central bulge yet, I made one which generated a square bulge, but ofc it looked wierd and I made it a comment which I might fix later.

The program is attached below, but be aware that you will have to close it from the task manager. I'm considering if I should add a way to close it, maybe just by crashing it. But I would need a command prompt, and Idk how to add it. It's my first .jar file. :P

And yes, the code was made for the resolution on my laptop. It would be easy to make the code apply to any resolution based on two variables (x and y resolution, ofc), but not easy to make you able to actually type it in and adjust it, with my current knowledge.

Here's the code:
Main class:
Code: [Select]
package grafikprogram1208;
public class Grafikprogram1208
{
    public static void main(String[] args)
    {
        GrafiskVindue vindue = new GrafiskVindue(); //Opretter vinduet.
        vindue.setSize(1250,750); //Sætter vinduets størrelse.
        vindue.setTitle("GrafiskVindue"); //Sætter vinduets titel.
        vindue.setVisible(true); //Viser vinduet.
    }
}

GrafiskVindue class:
Code: [Select]
package grafikprogram1208;
import java.awt.*;
public class GrafiskVindue extends Frame
{
    public void paint(Graphics g)
    {
        //Herunder referer g til et Graphics-objekt, som man kan tegne med.
        g.fillRect(0,0,1250,750);
        g.setColor(Color.darkGray);
        for (int i=0; i<50000; i++) //Generates lower half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(375,(Math.random()))),1,1);
        }
        for (int i=0; i<50000; i++) //Generates upper half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(375,(Math.random()))),1,1);
        }
        g.setColor(Color.gray);
        for (int i=0; i<10000; i++) //Generates lower half of normal stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(375,(Math.random()))),1,1);
        }
        g.setColor(Color.gray);
        for (int i=0; i<10000; i++) //Generates upper half of normal stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(375,(Math.random()))),1,1);
        }
        g.setColor(Color.lightGray);
        for (int i=0; i<5000; i++) //Generates lower half of bright stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(375,(Math.random()))),1,1);
        }
        for (int i=0; i<5000; i++) //Generates upper half of bright stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(375,(Math.random()))),1,1);
        }
        for (int i=0; i<3000; i++) //Generates lower half of bright stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(50,(Math.random()))),1,1);
        }
        for (int i=0; i<3000; i++) //Generates upper half of bright stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(50,(Math.random()))),1,1);
        }
        g.setColor(Color.white);
        for (int i=0; i<2500; i++) //Generates close, bright, scattered foreground stars.
        {
            g.fillRect((int)(Math.random()*1250),(int)(Math.random()*750),1,1);
        }
        for (int i=0; i<1500; i++) //Generates large, close, bright, scattered foreground stars.
        {
            int a, b;
            a = (int)(Math.random()*1250);
            b = (int)(Math.random()*750);
            g.setColor(Color.gray);
            g.fillRect(a,b,2,2);
            g.setColor(Color.white);
            g.fillRect(a,b,1,1);
        }
        for (int i=0; i<3000; i++) //Generates lower half of brightest stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(374+Math.pow(30,(Math.random()))),1,1);
        }
        for (int i=0; i<3000; i++) //Generates upper half of brightest stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*1250),(int)(376-Math.pow(30,(Math.random()))),1,1);
        }
        /*for (int i=0; i<1000; i++) //Generates the central bulge.
        {
            g.fillRect((int)(Math.random()*300)+475,(int)(Math.random()*300)+225,1,1);
        }*/
    }
}

Pretty Cool!

deoxy99

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 868
  • Zaraza Zaraji of the Socialist Republic of Dark Light
    • Typography Newspaper
Re: Experiences with programming
« Reply #18 on: December 08, 2011, 12:06:34 PM »
Is that your response to everything? Cool! Very cool! Cooltastic! Super cool!

FiahOwl

  • *****
  • Posts: 1187
  • pinkyee pie
Re: Experiences with programming
« Reply #19 on: December 08, 2011, 12:19:09 PM »
Is that your response to everything? Cool! Very cool! Cooltastic! Super cool!

Very Cool!

deoxy99

  • Universe Sandbox 1 Beta Team
  • *****
  • Posts: 868
  • Zaraza Zaraji of the Socialist Republic of Dark Light
    • Typography Newspaper
Re: Experiences with programming
« Reply #20 on: December 08, 2011, 12:28:10 PM »
Yes, it sure is cool. Anyways, I love pie. :P

FiahOwl

  • *****
  • Posts: 1187
  • pinkyee pie
Re: Experiences with programming
« Reply #21 on: December 08, 2011, 12:30:09 PM »
Yes, it sure is cool. Anyways, I love pie. :P

Cooltastic!

Bla

  • Global Moderator
  • *****
  • Posts: 952
  • The stars died so you can live.
Re: Experiences with programming
« Reply #22 on: December 08, 2011, 01:19:38 PM »
Thanks. :P
I was board... So updates to the program:
  • Resolution is now easy to set, only 4 variables must be changed, 2 for x resolution and 2 for y. Only wif konsole.
  • The total number of stars can easily be set by editing one single number. Only wif konsole.
  • The ratios of stars being generated is slightly changed.
  • It will now generate 20,000 to 400,000 stars.
  • And mostly for you people... The program now automagically closes 20 seconds after it has finished rendering. :P
  • All comments are now in Engwish. :P
It turned out that the last render had 146,000 stars.

Here's an image with a resolution of 1800x900 and 50,000 stars. On larger resolutions, the star density will be lower if the number of stars isn't increased accordingly. But whatever, you can't do that anyway.

Ooh! Wait, I could make it GENERATE how many stars it should generate! ;D
Brb with a new update. Done. :P
It now generates a different number of stars every time, from 20,000 to 400,000.

But first the new code and the new file.

Main class:
Code: [Select]
package grafikprogram1208;
public class Grafikprogram1208
{
    public static void main(String[] args)
    {
        int xres, yres;
        xres = 1200; //Width of resolution in pixels.
        yres = 600; //Height of resolution in pixels.
       
        GrafiskVindue vindue = new GrafiskVindue(); //Creates the graphics window.
        vindue.setSize(xres,yres); //Sets the size of the window.
        vindue.setTitle("Bla's Spiral Galaxy View Generator which closes automagically 20s after finishing rendering!"); //Sets the title of the window.
        vindue.setVisible(true); //Shows the window.
    }
}

GrafiskVindue class:
Code: [Select]
package grafikprogram1208;
import java.awt.*;
public class GrafiskVindue extends Frame
{
    public void paint(Graphics g)
    {
        int xres, yres, baseStars, stars;
        xres = 1200; //Width of resolution in pixels.
        yres = 600; //Height of resolution in pixels.
        baseStars = 20000; //Base number of stars in the galaxy.
        stars = ((int)((Math.random()*19+1)*baseStars)); //Number of stars in the galaxy. Can be set to a fixed value or a function of baseStars.
       
        //g refers to a Graphics-object, which can be used for drawing.
        g.fillRect(0,0,xres,yres);
        g.setColor(Color.darkGray);
        for (int i=0; i<stars*0.35; i++) //Generates lower half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/2),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.35; i++) //Generates upper half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/2),(Math.random()))),1,1);
        }
        g.setColor(Color.gray);
        for (int i=0; i<stars*0.05; i++) //Generates lower half of normal stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/2),(Math.random()))),1,1);
        }
        g.setColor(Color.gray);
        for (int i=0; i<stars*0.05; i++) //Generates upper half of normal stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/2),(Math.random()))),1,1);
        }
        g.setColor(Color.lightGray);
        for (int i=0; i<stars*0.035; i++) //Generates lower half of bright stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/2),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.035; i++) //Generates upper half of bright stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/2),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates lower half of bright stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/15),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates upper half of bright stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/15),(Math.random()))),1,1);
        }
        g.setColor(Color.white);
        for (int i=0; i<stars*0.03; i++) //Generates close, bright, scattered foreground stars.
        {
            g.fillRect((int)(Math.random()*xres),(int)(Math.random()*yres),1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates large, close, bright, scattered foreground stars.
        {
            int a, b;
            a = (int)(Math.random()*xres);
            b = (int)(Math.random()*yres);
            g.setColor(Color.gray);
            g.fillRect(a,b,2,2);
            g.setColor(Color.white);
            g.fillRect(a,b,1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates lower half of brightest stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/25),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates upper half of brightest stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/25),(Math.random()))),1,1);
        }
        /*for (int i=0; i<1000; i++) //Generates the central bulge. Not updated for resolution and star number variables.
        {
            g.fillRect((int)(Math.random()*300)+475,(int)(Math.random()*300)+225,1,1);
        }*/
        try {Thread.sleep(20000);} catch (Exception e) {}
        System.exit(0);
    }
}
« Last Edit: December 08, 2011, 01:32:10 PM by Bla »

FiahOwl

  • *****
  • Posts: 1187
  • pinkyee pie
Re: Experiences with programming
« Reply #23 on: December 08, 2011, 01:28:00 PM »
Thanks. :P
I was board... So updates to the program:
  • Resolution is now easy to set, only 4 variables must be changed, 2 for x resolution and 2 for y.
  • The total number of stars can easily be set by editing one single number.
  • The ratios of stars being generated is slightly changed.
  • And mostly for you people... The program now automagically closes 20 seconds after it has finished rendering. :P
  • All comments are now in Engwish. :P
It turned out that the last render had 146,000 stars.

Here's an image with a resolution of 1800x900 and 50,000 stars. On larger resolutions, the star density will be lower if the number of stars isn't increased accordingly. But whatever, you can't do that anyway.

Ooh! Wait, I could make it GENERATE how many stars it should generate! ;D
Brb with a new update. :P

But first the new code and the new file.

Main class:
Code: [Select]
package grafikprogram1208;
public class Grafikprogram1208
{
    public static void main(String[] args)
    {
        int xres, yres;
        xres = 1800; //Width of resolution in pixels.
        yres = 900; //Height of resolution in pixels.
       
        GrafiskVindue vindue = new GrafiskVindue(); //Creates the graphics window.
        vindue.setSize(xres,yres); //Sets the size of the window.
        vindue.setTitle("GalaxyWindow"); //Sets the title of the window.
        vindue.setVisible(true); //Shows the window.
    }
}

GrafiskVindue class:
Code: [Select]
package grafikprogram1208;
import java.awt.*;
public class GrafiskVindue extends Frame
{
    public void paint(Graphics g)
    {
        int xres, yres, stars;
        xres = 1800; //Width of resolution in pixels.
        yres = 900; //Height of resolution in pixels.
        stars = 50000; //Number of stars in the galaxy.
       
        //g refers to a Graphics-object, which can be used for drawing.
        g.fillRect(0,0,xres,yres);
        g.setColor(Color.darkGray);
        for (int i=0; i<stars*0.35; i++) //Generates lower half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/2),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.35; i++) //Generates upper half of dim stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/2),(Math.random()))),1,1);
        }
        g.setColor(Color.gray);
        for (int i=0; i<stars*0.05; i++) //Generates lower half of normal stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/2),(Math.random()))),1,1);
        }
        g.setColor(Color.gray);
        for (int i=0; i<stars*0.05; i++) //Generates upper half of normal stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/2),(Math.random()))),1,1);
        }
        g.setColor(Color.lightGray);
        for (int i=0; i<stars*0.035; i++) //Generates lower half of bright stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/2),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.035; i++) //Generates upper half of bright stars in galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/2),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates lower half of bright stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/15),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates upper half of bright stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/15),(Math.random()))),1,1);
        }
        g.setColor(Color.white);
        for (int i=0; i<stars*0.03; i++) //Generates close, bright, scattered foreground stars.
        {
            g.fillRect((int)(Math.random()*xres),(int)(Math.random()*yres),1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates large, close, bright, scattered foreground stars.
        {
            int a, b;
            a = (int)(Math.random()*xres);
            b = (int)(Math.random()*yres);
            g.setColor(Color.gray);
            g.fillRect(a,b,2,2);
            g.setColor(Color.white);
            g.fillRect(a,b,1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates lower half of brightest stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)-1+Math.pow((yres/25),(Math.random()))),1,1);
        }
        for (int i=0; i<stars*0.02; i++) //Generates upper half of brightest stars in central galactic plane.
        {
            g.fillRect((int)(Math.random()*xres),(int)((yres/2)+1-Math.pow((yres/25),(Math.random()))),1,1);
        }
        /*for (int i=0; i<1000; i++) //Generates the central bulge. Not updated for resolution and star number variables.
        {
            g.fillRect((int)(Math.random()*300)+475,(int)(Math.random()*300)+225,1,1);
        }*/
        try {Thread.sleep(20000);} catch (Exception e) {}
        System.exit(0);
    }
}

Nice1

Dan Dixon

  • Creator of Universe Sandbox
  • Developer
  • *****
  • Posts: 2940
    • Personal Site
Re: Experiences with programming
« Reply #24 on: December 08, 2011, 01:57:41 PM »
Well done. That's cool.

If you're interested in trying out some 3D programming, I'd totally recommend Unity.
http://unity3d.com/
It's awesome.

The next major update of Universe Sandbox (to be released next year) will be a complete rewrite in Unity. :)

FiahOwl

  • *****
  • Posts: 1187
  • pinkyee pie
Re: Experiences with programming
« Reply #25 on: December 08, 2011, 02:02:13 PM »
Well done. That's cool.

If you're interested in trying out some 3D programming, I'd totally recommend Unity.
http://unity3d.com/
It's awesome.

The next major update of Universe Sandbox (to be released next year) will be a complete rewrite in Unity. :)

Will it be as easy to mod? And can we mod?

vh

  • formerly mudkipz
  • *****
  • Posts: 1084
  • matty406 does not. stowaway does.
Re: Experiences with programming
« Reply #26 on: December 08, 2011, 02:09:40 PM »
What does Unity do better than whatever programming language Ubox currently uses?

FiahOwl

  • *****
  • Posts: 1187
  • pinkyee pie
Re: Experiences with programming
« Reply #27 on: December 08, 2011, 02:15:00 PM »
What does Unity do better than whatever programming language Ubox currently uses?

Ubox uses xml right now I think.

Dan Dixon

  • Creator of Universe Sandbox
  • Developer
  • *****
  • Posts: 2940
    • Personal Site
Re: Experiences with programming
« Reply #28 on: December 08, 2011, 02:16:12 PM »
Unity makes it easy to deploy the game on multiple platforms. So once the rewrite is complete, we'll have both a PC and a Mac version (and an in-browser version too, although we're not sure how we're going to use that version yet).

That it's in Unity doesn't make it more or less mod-able, that's determined by how the program is setup. We're aiming to make user-generated content (models and textures) easy to work with in the next version.

Unity is also in constant development and keeps releasing new versions with new features. Unfortunately the engine used in legacy (the current version) hasn't released a new update in over a year.

XML is the file save format. Unity can use that too. That really doesn't have anything to do with the language Universe Sandbox is programmed in.

Bla

  • Global Moderator
  • *****
  • Posts: 952
  • The stars died so you can live.
Re: Experiences with programming
« Reply #29 on: December 09, 2011, 04:57:38 AM »
Thanks, I'll try Unity.

*Looks at huge, advanced 3D world as I start up the program for the first time and panics.*
« Last Edit: December 09, 2011, 06:28:47 AM by Bla »