LINK TO PROGRAM
[URL="http://www.box.net/shared/z8bi1oqok5"]http://www.box.net/shared/1p38xnxs2j[/URL]
It is zipped. Extract it and then run the html page.
Ok first off don't expect some super awesome 3d spore like galaxy creation system.
This is just a 2d thing but it is still kwl.
As a few people might have noticed i did a java simple drawing program which created shapes pixel by pixel. This was my first time doing such in java and i wanted to test out some functions as well as practice.
Here is the thread.
[URL]http://www.facepunch.com/showthread.php?p=21091905#post21091905[/URL]
Here is a picture. Only linked because it is quite big.
[URL]http://img338.imageshack.us/img338/1481/41513393.png[/URL]
Well i have re-written the code and used what i learnt about modifying pixels to create what i think looks awesome. Below is a picture of it. It is a java applet meaning it works on web pages. Well It creates circles but it gives them shading and stuff. Accidently i made a kwl star looking thing. Then i decided to change some settings and realized that this shit looks awesome. Well below is a picture of what i have made. Also the source code is underneath it. I will try to add an export image function and make it convert it to a jpg and i will also try to find a free hosting site to put this applet on so people can try it out. You can make some awesome stuff.
Here is a link to the java file. It is zipped and it has a html file in it to. Run the html file and it runs the program in a webpage.
[IMG]http://www.box.net/shared/z8bi1oqok5[/IMG][URL="http://www.box.net/shared/z8bi1oqok5"]http://www.box.net/shared/1p38xnxs2j[/URL]
The values on the left are changeable. If you set them to -1 then it generates that value randomly.
[IMG]http://img402.imageshack.us/img402/2405/prett1.png[/IMG]
[code]
import java.awt.image.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.math.*;
import java.lang.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.util.*;
public class Main extends Applet implements ActionListener
{
//Set up the screen
int ScreenX = 800;
int ScreenY = 600;
int ScreenS = 500; //The square size
//Create the pixels array
Color Pixels[][];
//Create the myimage image.
Image MyImage;
//The colors
Color ColorMain = new Color(0,0,0);
Color ColorText = new Color(255,255,255);
Color ColorButton = new Color(60,60,60);
//The font
Font FontButton = new Font("Main", 1, 10);
// Set the debuggin stuff
int RandomColours = 0;
//Variables for showing how many things created. Some of these were from earlier versions.
int TotalPixels = 0;
int TotalDarkCircles = 0;
int TotalLightCircles = 0;
int Total3DBoxes = 0;
int TotalThunders = 0;
int TotalShapes = 0;
int TotalSpirals = 0;
int Shading = 1;// The difference in the shading colour.
//Create the buttons used.
Button ButtonNewPicture = new Button("New Picture");
Button ButtonHideButtons = new Button("Hide Buttons");
Button ButtonBackground = new Button("BG Color");
Button ButtonShading = new Button("Shading: 0ff");
Button ButtonProperties[];
//Create the two labels used.
Label LabelCircles = new Label("Circles");
Label LabelBoxes = new Label("Spirals");
//Create the integers used.
int Values[]; // Values for the buttons
double AntiA = 0; //For the shading. It was doing to be called antialiasing.
int ButtonsHidden = 0; // Whether the buttons are hidden.
String Labels[]; // Label names for the buttons
String Questions[]; // The question it asks the user when they press a button.
//Get the random stuff ready.
Random RandomNumber = new Random(); // randomy number generator function
public void init()
{
setLayout(null);
Print("WELCOME\nThis program was made by Trent Jones, 2010.\nClick on the buttons to change the values for the picture.\nClick on newpicture to display your picture.\nTo see an example press new picture with all the values as -1 (Default).\nThank you for viewing this and expect more soon.","WELCOME!");
//Sets the screen up ready for editing.
setSize(ScreenX,ScreenY);
setBackground(ColorMain);
MyImage = createImage(ScreenX,ScreenY);
//Adds the buttons onto the form
add(ButtonNewPicture); // New picture button
ButtonNewPicture.setBounds(5,5,75,20);
ButtonNewPicture.addActionListener(this);
ButtonNewPicture.setActionCommand("new");
ButtonNewPicture.setBackground(ColorButton);
ButtonNewPicture.setForeground(ColorText);
ButtonNewPicture.setFont(FontButton);
add(ButtonHideButtons); // Hide button
ButtonHideButtons.setBounds(5,30,75,20);
ButtonHideButtons.addActionListener(this);
ButtonHideButtons.setActionCommand("hide");
ButtonHideButtons.setBackground(ColorButton);
ButtonHideButtons.setForeground(ColorText);
ButtonHideButtons.setFont(FontButton);
add(ButtonBackground); // Background button
ButtonBackground.setBounds(85,5,75,20);
ButtonBackground.addActionListener(this);
ButtonBackground.setActionCommand("bg");
ButtonBackground.setBackground(ColorButton);
ButtonBackground.setForeground(ColorText);
ButtonBackground.setFont(FontButton);
add(ButtonShading); // shading button
ButtonShading.setBounds(85,30,75,20);
ButtonShading.addActionListener(this);
ButtonShading.setActionCommand("shading");
ButtonShading.setBackground(ColorButton);
ButtonShading.setForeground(ColorText);
ButtonShading.setFont(FontButton);
ButtonsHidden = 0; //Make it so the buttons arn't hidden.
ButtonProperties = new Button[12]; // Create the button arras.
Values = new int[12]; //Create the valuse array
Labels = new String[12]; //Set the labels for the buttons
Labels[0] = "Amount";
Labels[1] = "Radius";
Labels[2] = "Density";
Labels[3] = "Red";
Labels[4] = "Green";
Labels[5] = "Blue";
Labels[6] = "Amount";
Labels[7] = "Size";
Labels[8] = "Density";
Labels[9] = "Red";
Labels[10] = "Green";
Labels[11] = "Blue";
Questions = new String[12]; // Create the questions for the buttons
Questions[0] = "Type the amount of circles.\nType -1 for a random amount between 1 and 50.";
Questions[1] = "Type the radius of the circles.\nType -1 for the radius to be random.";
Questions[2] = "Type the Density of the object.\nThis is the amount of dots the object has per layer\nType -1 for Density based on the radius.";
Questions[3] = "Type the red colouring.\nType below 0 or above 255 for a random number.";
Questions[4] = "Type the green colouring.\nType below 0 or above 255 for a random number.";
Questions[5] = "Type the blue colouring.\nType below 0 or above 255 for a random number.";
Questions[6] = "Type the amount of spirals.\nType -1 for a random amount between 1 and 50.";
Questions[7] = "Type the size of the spirals.\nType -1 for the size to be random.";
Questions[8] = "Type the density of the spirals..\nType -1 for the density to be based on the size. to be random.";
Questions[9] = "Type the red colouring.\nType below 0 or above 255 for a random number.";
Questions[10] = "Type the green colouring.\nType below 0 or above 255 for a random number.";
Questions[11] = "Type the blue colouring.\nType below 0 or above 255 for a random number.";
//Add the two labels
add(LabelCircles);
LabelCircles.setBounds(5,55,75,20);
LabelCircles.setBackground(ColorMain);
LabelCircles.setForeground(ColorText);
LabelCircles.setFont(FontButton);
add(LabelBoxes);
LabelBoxes.setBounds(5,230,75,20);
LabelBoxes.setBackground(ColorMain);
LabelBoxes.setForeground(ColorText);
LabelBoxes.setFont(FontButton);
//Go through and add the buttons.
for (int i = 0;i< 6;i++)
{
ButtonProperties[i] = new Button(Labels[i] + ": -1");
add(ButtonProperties[i]);
ButtonProperties[i].setBounds(5,30 + (25 * (i + 2)),75,20);
ButtonProperties[i].addActionListener(this);
ButtonProperties[i].setActionCommand("properties"+i);
ButtonProperties[i].setBackground(ColorButton);
ButtonProperties[i].setForeground(ColorText);
ButtonProperties[i].setFont(FontButton);
Values[i] = -1;
}
for (int i = 6;i< 12;i++)
{
ButtonProperties[i] = new Button(Labels[i] + ": -1");
add(ButtonProperties[i]);
ButtonProperties[i].setBounds(5,30 + (25 * (i + 3)),75,20);
ButtonProperties[i].addActionListener(this);
ButtonProperties[i].setActionCommand("properties"+i);
ButtonProperties[i].setBackground(ColorButton);
ButtonProperties[i].setForeground(ColorText);
ButtonProperties[i].setFont(FontButton);
Values[i] = -1;
}
}
public void ToggleHideButtons()//A function the goes through the buttons and makes them visible or hidden.
{
for (int i = 0;i< ButtonProperties.length;i++) // Loop through the buttons
{
if (ButtonsHidden == 1)
{
ButtonHideButtons.setLabel("Hide Buttons");
ButtonProperties[i].setVisible(true);
}
else
{
ButtonHideButtons.setLabel("Show Buttons");
ButtonProperties[i].setVisible(false);
}
}
if (ButtonsHidden == 1) // Change the button hidden value and high or show the labels.
{
ButtonsHidden = 0;
LabelCircles.setVisible(true);
LabelBoxes.setVisible(true);
}
else
{
ButtonsHidden = 1;
LabelBoxes.setVisible(false);
LabelCircles.setVisible(false);
}
}
public void actionPerformed(ActionEvent e) // A function called when a button is pressed.
{
String Arg = e.getActionCommand();
if (Arg == "new") //Create a new picture
{
StartPicture();
}
if (Arg == "hide") // Hide the buttons
{
ToggleHideButtons();
}
if (Arg == "shading")// Toggle the shading
{
String Response = PopUpAskUser("This is the shading amount.\nThis is off by default.\nChoose a number from 0 to 1.\n0 being that the shading colour is no different from the new colour.\n1 is 100% different from the original colour, in other words no shading.","SHADING");
double r = Double.parseDouble(Response);
ButtonShading.setLabel("Shading: "+r);
if (r < 0)
{
r = 0;
ButtonShading.setLabel("Shading: 0");
}
else if (r >= 1)
{
r = 1;
ButtonShading.setLabel("Shading: Off");
}
AntiA = r;
}
if (Arg == "bg") //Change the background color.
{
String Response = PopUpAskUser("Enter the RED color (0 to 255).","BACKGROUND");
int r = Integer.parseInt(Response);
Response = PopUpAskUser("Enter the GREEN color (0 to 255).","BACKGROUND");
int g = Integer.parseInt(Response);
Response = PopUpAskUser("Enter the BLUE color (0 to 255).","BACKGROUND");
int b = Integer.parseInt(Response);
ColorMain = ToColorPercent(r,g,b,0);
LabelBoxes.setBackground (ColorMain);
LabelCircles.setBackground (ColorMain);
Print("Changes will be made when you create a new picture.","WARNING!");
}
/*
Below goes through all of the buttons and checks if it was the one that was pressed. If it was
then display an input box with a question. Whatever the user puts in becomes the value
for the button.
*/
for (int i = 0;i< ButtonProperties.length;i++)
{
if (Arg == ButtonProperties[i].getActionCommand())
{
String response = PopUpAskUser(Questions[i],"PROPERTIES");
int x = Integer.parseInt(response);
Values[i] = Integer.parseInt(response);
ButtonProperties[i].setLabel(Labels[i] + ": "+Values[i]);
}
}
}
public void StartPicture() //Creates the picture
{
//'prep' the image.
Print("Once you press ok the picture will load.\nPlease wait until another box pops up saying the picture is complete.\nThe higher the amount,radius and the Density, the longer it will take to load.\nIf you set the amount, the radius and Density to -1 then it will take less then 10 seconds.","MESSAGE");
Graphics g = MyImage.getGraphics( );
g.setColor(ColorMain);
g.fillRect( ScreenX, ScreenY, 1, 1 );
g.dispose( );
//Creates the array of pixels. (This means i can add to colours that are on the screen).
Pixels = new Color[ScreenX + 1][ScreenY + 1];
for (int x = 0; x < ScreenX;x++)
{
for (int y = 0; y < ScreenY;y++)
{
setPixel(MyImage, x, y, ColorMain);
}
}
//Runs the construct the shapes function.
ConstructShapes();
//Paints it to the screen.
g.drawImage(MyImage,0,0,this);
repaint();
//Format the finishing message.
String str = "";
str = str + "Picture is created!\nSTATS";
str = str + "\nTotal Pixels: "+TotalPixels;
str = str + "\nTotal Light Circles: "+TotalLightCircles;
str = str + "\nTotal Spirals: "+TotalSpirals;
str = str + "\nTotal Shapes: "+TotalShapes;
//Display the finishing message.
Print(str,"DONE!");
}
public double ToRads(double x) // Converts a degrees to radians. Yes i know there is a function for this but at the time i didn't.
{
x = x * ( Math.PI/ 180);
return x;
}
public void paint(Graphics g) // Draws the image.
{
g.drawImage(MyImage,0,0,this);
}
public void ConstructShapes()
{
//Set the default counting variables. Some of these were used in older versions. Just ignore them.
TotalPixels = 0;
TotalDarkCircles = 0;
TotalLightCircles = 0;
Total3DBoxes = 0;
TotalShapes = 0;
TotalThunders = 0;
TotalSpirals = 0;
//Print Formatting
System.out.println("-");
System.out.println("--");
System.out.println("----");
System.out.println("---------");
System.out.println("-------------------");
System.out.println("CONSTRUCTING SHAPES");
System.out.println("-------------------");
System.out.println("\n\n");
//Create the circles and spirals.
CreateCircles();
CreateSpirals();
//Print formatting and Printing the results.
System.out.println("\n\n");
System.out.println("-------------------");
System.out.println("SHAPES CONSTRUCTED");
System.out.println("-------------------");
System.out.println("---------");
System.out.println("----");
System.out.println("--");
System.out.println("-");
System.out.println("\n");
System.out.println("DETAILS:");
System.out.println("\tTotal Pixels : "+TotalPixels);
System.out.println("\tTotal Light Circles : "+TotalLightCircles);
System.out.println("\tTotal Spirals : "+TotalSpirals);
System.out.println("\tTotal Shapes : "+TotalShapes);
}
public void CreateCircles() //Creates all the circles
{
//Center of the screen
int CentX = 0;
int CentY = 0;
CentX = ScreenX / 2;
CentY = ScreenY / 2;
// Below gets the users input data and then sets the stats of the circles accordingly.
//The amount of shapes
int Amount = Values[0];
if (Values[0] < 0)
{
Amount = RandomNumber.nextInt(30) + 25;
}
//Loop through the amount of shapes.
for (int i = 0; i < Amount;i++)
{
//Radius
int Radius = Values[1];
if (Values[1] < 0)
{
Radius = i * 4 ;
}
//Density
int Density = Values[2];
if (Values[2] < 0)
{
Density = Radius;
}
//Red
int ColR = Values[3];
if (Values[3] < 0 || Values[3] > 255)
{
ColR = RandomNumber.nextInt(255);
}
//Green
int ColG = Values[4];
if (Values[4] < 0 || Values[4] > 255)
{
ColG = RandomNumber.nextInt(255);
}
//Blue
int ColB = Values[5];
if (Values[5] < 0 || Values[5] > 255)
{
ColB = RandomNumber.nextInt(255);
}
int PosX = RandomNumber.nextInt(ScreenS) - (ScreenS / 2);//Position from the center.
int PosY = RandomNumber.nextInt(ScreenS) - (ScreenS / 2);//Position from the center.
System.out.println("--Shape--Circle : "+i+", "+Radius+", "+Density); // Print out stuff about the circle to console.
DrawLightCircle(MyImage,CentX + PosX,CentY + PosY,Radius,new Color(ColR, ColG, ColB),Density); //Create the circle.
}
}
public void CreateSpirals() // Creates all the boxes.
{
//Center of the screen
int CentX = 0;
int CentY = 0;
CentX = ScreenX / 2;
CentY = ScreenY / 2;
// Below gets the users input data and then sets the stats of the circles accordingly.
//The amount of shapes
int Amount = Values[6];
if (Values[6] < 0)
{
Amount = RandomNumber.nextInt(25) + 25;
}
//Loop through the amount of shapes.
for (int i = 0; i < Amount;i++)
{
//Radius
int Radius = Values[7];
if (Values[7] < 0)
{
Radius = RandomNumber.nextInt(150)+50;
}
//Density
double Den = (double)(Values[8] + 1) / 100;
if (Values[8] < 0)
{
Den = ((double)((RandomNumber.nextInt(100) + 50)) / 100);
}
//Red
int ColR = Values[9];
if (Values[9] < 0 || Values[9] > 255)
{
ColR = RandomNumber.nextInt(255);
}
//Green
int ColG = Values[10];
if (Values[10] < 0 || Values[10] > 255)
{
ColG = RandomNumber.nextInt(255);
}
//Blue
int ColB = Values[11];
if (Values[11] < 0 || Values[11] > 255)
{
ColB = RandomNumber.nextInt(255);
}
int PosX = RandomNumber.nextInt(ScreenS) - (ScreenS / 2);//Position from the center.
int PosY = RandomNumber.nextInt(ScreenS) - (ScreenS / 2);//Position from the center.
DrawSpiral(MyImage,CentX+ PosX,CentY + PosY,Radius,new Color(ColR, ColG, ColB),Den); // Draws the spiral
System.out.println("--Shape--Spiral : "+i+", "+Radius+", "+Den); // Prints stuff about the spiral to the screen.
}
}
////SHAPE DRAWING
public void DrawLightCircle(Image g,int CentX,int CentY,int SZ,Color color,double density) // Draws a circle that gets lighter towards the center.
{
//Initialize the variables.
int BaseR = color.getRed();
int BaseG = color.getGreen();
int BaseB = color.getBlue();
int X2 = 0;
int Y2 = 0;
double Size= SZ / 2; // Half the size (this is for the radius.
//Loops through the layers of a circle and sets the colours.
for (double Radius = Size; Radius > 0;Radius--)
{
double PercentAmount = Radius / Size; // Calculate the colour percentage
Color Col = ToColorPercent(BaseR,BaseG,BaseB,PercentAmount); // Get the new colour based on the percentage.
for (double i = 0;i < density;i++) // Loop through base on the density of the pixels.
{
double l = ToRads(i * (360 /(density))); // Get the degree of the pixel
X2 = CentX + (int)(Math.sin(l) * Radius); // Calculate the x position of the pixel
Y2 = CentY + (int)(Math.cos(l) * Radius); // Calculate the y position of the pixel
AddPixel(g, X2, Y2, Col,1); // Draw it
}
}
// Add to the total variables.
TotalLightCircles = TotalLightCircles + 1;
TotalShapes = TotalShapes + 1;
}
public void DrawSpiral(Image g,int CentX,int CentY,int SZ,Color color,double den) // Draws a circle that gets lighter towards the center.
{
//Initialize the variables.
int BaseR = color.getRed();
int BaseG = color.getGreen();
int BaseB = color.getBlue();
int X2 = 0;
int Y2 = 0;
double Size= SZ;
//Loops through the layers of a circle and sets the colours.
for (double Radius = Size; Radius > 0;Radius = Radius - (den / 5)) // Loop through the radius decreasing it by the density devided by 5.
{
double PercentAmount = Radius / Size; // Calculate the colour percentage
Color Col = ToColorPercent(BaseR,BaseG,BaseB,PercentAmount); // Get the new colour based on the percentage.
X2 = CentX + (int)(Math.sin(Radius) * Radius); // Calculate the x position of the pixel
Y2 = CentY + (int)(Math.cos(Radius) * Radius); // Calculate the y position of the pixel
AddPixel(g, X2, Y2, Col,1);
}
// Add to the total variables.
TotalSpirals = TotalSpirals + 1;
TotalShapes = TotalShapes + 1;
}
public Color ToColorPercent(int BaseR,int BaseG,int BaseB,double PercentAmount) // Create a colour and change it by a percent amount.
{
int Col[] = new int[3]; //Crete the colour array.
//Modify the colours based on the percentamount
Col[0] = (int) (BaseR - (PercentAmount * BaseR));
Col[1] = (int) (BaseG - (PercentAmount * BaseG));
Col[2] = (int) (BaseB - (PercentAmount * BaseB));
//Check if any of the values are under 0 or over 255. (this means that it would error because they arn't colour values.
for (int i = 0;i <3;i++)
{
if (Col[i] > 255)
{
Col[i] = 255;
}
else if (Col[i] < 0)
{
Col[i] = 0;
}
}
Color color = new Color(Col[0],Col[1],Col[2]); //Create the color
return color; // Return the color.
}
public Color ColorPercent(Color color,double PercentAmount) // Changes the colour based on a percentage that you give it.
{
//Get the colours
int BaseR = color.getRed();
int BaseG = color.getGreen();
int BaseB = color.getBlue();
//Make an array Get the percent of the base colour.
int Col[] = new int[3];
//Modify the colours based on the percentamount
Col[0] = (int) (BaseR - (PercentAmount * BaseR));
Col[1] = (int) (BaseG - (PercentAmount * BaseG));
Col[2] = (int) (BaseB - (PercentAmount * BaseB));
//Check if any of the values are under 0 or over 255. (this means that it would error because they arn't colour values.
for (int i = 0;i <3;i++)
{
if (Col[i] > 255)
{
Col[i] = 255;
}
else if (Col[i] < 0)
{
Col[i] = 0;
}
}
color = new Color(Col[0],Col[1],Col[2]); //Create the color
return color; // Return the color.
}
//Modifyingpixels
public void setPixel(Image image, int x, int y, Color color ) // Set a pixels color.
{
if (x < ScreenX && y < ScreenY && x > 0 && y > 0) //Checks if it is on the screen.
{
Graphics g = image.getGraphics( );
if (RandomColours == 1) // If it is a random colour then make it random.
{
color = new Color(RandomNumber.nextInt(255),RandomNumber.nextInt(255),RandomNumber.nextInt(255));
}
Pixels[x][y] = color; // Set the colour of the pixel
g.setColor( Pixels[x][y] ); // Set the draw colour
g.fillRect( x, y, 1, 1 ); //Draw it
g.dispose( );
TotalPixels = TotalPixels + 1; // Add to the total pixels.
}
}
public void AddPixel(Image image, int x, int y, Color color,int aa ) // Add a color to the color of another pixel.
{
if (x < ScreenX && y < ScreenY && x > 0 && y > 0) //Checks if it is on the screen.
{
Graphics g = image.getGraphics( );
if (RandomColours == 1) // If it is a random colour then make it random.
{
color = new Color(RandomNumber.nextInt(255),RandomNumber.nextInt(255),RandomNumber.nextInt(255));
}
//Initialize the variables.
int ColR,ColG,ColB,oldr,oldb,oldg,NewR,NewG,NewB;
//Get the color from the function
ColR = color.getRed();
ColG = color.getGreen();
ColB = color.getBlue();
//Get the color of the old pixels.
color = Pixels[x][y];
oldr = color.getRed();
oldg = color.getGreen();
oldb = color.getBlue();
//Add the two colours to form the new one.
NewR = ColR + oldr;
NewG = ColG + oldg;
NewB = ColB + oldb;
//Check if the colour values are valid.
if (NewR > 255)
{
NewR = 255;
}
if (NewG > 255)
{
NewG = 255;
}
if (NewB > 255)
{
NewB = 255;
}
//If it allows shading then add shading.
if (AntiA <1 && aa == 1)
{
setAAPixels(image,x,y,color);
}
//Set the color of the pixel and draw it.
Pixels[x][y] = new Color(NewR,NewG,NewB);
g.setColor( Pixels[x][y] );
g.fillRect( x, y, 1, 1 );
g.dispose( );
TotalPixels = TotalPixels + 1; // Add to the total pixels.
}
}
public void setAAPixels(Image image,int x, int y, Color color)//Adds blending to the pixels around an object.
{
color = ColorPercent(color,AntiA); // Set the colour of the new pixels to be .50 of the colour from the function.
AAPixel(image,x+1,y+1,color); // Run the antialiasing function.
AAPixel(image,x-1,y-1,color); // Run the antialiasing function.
AAPixel(image,x-1,y+1,color); // Run the antialiasing function.
AAPixel(image,x+1,y-1,color); // Run the antialiasing function.
}
public void AAPixel(Image image,int x, int y, Color color) // Used by the setAAPixels
{
if (x < ScreenX && y < ScreenY && x > 0 && y > 0)
{
AddPixel(image,x,y,color,0);
}
}
public void blendPixel(Image image, int x, int y, Color color ) // Blends the pixels colour (does not work well with black.)
{
if (x < ScreenX && y < ScreenY && x > 0 && y > 0)
{
Graphics g = image.getGraphics( );
if (RandomColours == 1)
{
color = new Color(RandomNumber.nextInt(255),RandomNumber.nextInt(255),RandomNumber.nextInt(255));
}
//Initialize the variables.
int ColR,ColG,ColB,oldr,oldb,oldg,NewR,NewG,NewB;
//Get the color from the function
ColR = color.getRed();
ColG = color.getGreen();
ColB = color.getBlue();
//Get the color of the old pixels.
color = Pixels[x][y];
oldr = color.getRed();
oldg = color.getGreen();
oldb = color.getBlue();
//Add the two colours then devide by 2 to form the new one.
NewR = (ColR + oldr) / 2;
NewG = (ColG + oldg) / 2;
NewB = (ColB + oldb) / 2;
if (NewR > 255)
{
NewR = 255;
}
if (NewG > 255)
{
NewG = 255;
}
if (NewB > 255)
{
NewB = 255;
}
//If it allows shading then add shading.
Pixels[x][y] = new Color(NewR,NewG,NewB);
//Set the color of the pixel and draw it.
g.setColor( Pixels[x][y] );
g.fillRect( x, y, 1, 1 );
g.dispose( );
TotalPixels = TotalPixels + 1;
}
}
//Other stuff
public void Print(String message,String Type)
{
//A custom method for Printing a string in console and creating a popup message box.
System.out.println(Type + ": "+ message);
JOptionPane.showMessageDialog(null,message,Type,JOptionPane.INFORMATION_MESSAGE);
}
public String PopUpAskUser(String message,String Type)
{
String response = "";
//A custom method for Printing a string in console and creating a popup message box.
response = JOptionPane.showInputDialog(null,message,Type,JOptionPane.INFORMATION_MESSAGE);
return response;
}
public boolean YesNoOption(String message,String Type) // A yes no box that pops up.
{
boolean x = false;
int y = JOptionPane.showConfirmDialog(null,message, Type,JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
if (y == 0)
{
x = true;
}
return x;
}
}
[/code]Here is the boxes thing i added.
[IMG]http://img199.imageshack.us/img199/4716/prett2.png[/IMG]
I have now added a sort of shading thing to it.
It was meant to make it so it didn't look so pixelated. It did it ... sort of. It looks kwl still.
Anyway have a look
[IMG]http://img138.imageshack.us/img138/5522/prett3.png[/IMG]
This version is now in the link now!
Dload and tell me what you think.
I have updated it once again and now i fixed up the gui and i added shaders. If anyone knows how to make it so i can export images in an applet please tell me. It keeps giving me security errors because i am using a save function which the java applet doesn't like.
Anyway here is a picture.
[IMG]http://img265.imageshack.us/img265/5543/prett4.png[/IMG]
OK so i have now added. a few extra things. I have added shading that can be changed and i have also added a background colour option. This creates some pretty weird stuff.
Here is another picture.
Source code and link has been updated.
[IMG]http://img339.imageshack.us/img339/6281/prett7.png[/IMG]
Pretty cool
Thanks i have now added it so you can make boxes to.
[editline]09:26PM[/editline]
I have added boxes now and i put another picture.
I need to work on the gui a bit more.
[IMG]http://img199.imageshack.us/img199/4716/prett2.png[/IMG]
Yeah it's damn cool, but it doesn't look like a galaxy.
Looks like a star developing or dying. Looks awesome.
I have added a sort of shading function. Takes more time to make the picture but looks kwl. It asks you when you click on new picture.
This version is in a box.net link now. If you could test it for me that would be awsome.
Here is a picture
[IMG]http://img138.imageshack.us/img138/5522/prett3.png[/IMG]
What the fudge is with the denCity button...
Lol i spelt it wrong.. Throught the code lol. It is 2:00 here lol. I replaced it in my latest version.
I wouldn't exactly call this a galaxy generator, as it only generates a few dots :)
Reminds me of funky stars.
I have done some extra work on my pixel changer. I fixed up the gui and i also got rid of the boxes. I replaced them with spirals.
Here is a picture and the source code and the download is up to date.
[IMG]http://img265.imageshack.us/img265/5543/prett4.png[/IMG]
Ok so i have now added. a few extra things. I have added shading that can be changed and i have also added a background colour option. This creates some pretty weird stuff.
Here is another picture.
Link is up in top post and so is the source code.
[img]http://img339.imageshack.us/img339/6281/prett7.png[/img]
the file is down, box says This shared file or folder link has been removed.
This shared file or folder
link has been removed.
Im not sure why.. It should be working try now.
Looks more like a PCP trip simulator.
Sorry, you need to Log In to post a reply to this thread.