Skip to content

Commit

Permalink
Phoenix Julia and Manowar equations added
Browse files Browse the repository at this point in the history
  • Loading branch information
David Byrne committed Jan 27, 2010
1 parent 9324fc3 commit 00e5947
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 41 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="byrne.fractal"
android:versionCode="5"
android:versionName="1.1.1">
android:versionCode="6"
android:versionName="1.1.2">
<uses-sdk android:minSdkVersion="6"/>
<uses-permission android:name="android.permission.SET_WALLPAPER" />

Expand Down
2 changes: 1 addition & 1 deletion build.properties
Expand Up @@ -15,5 +15,5 @@
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

key.store=/Users/Rhea/Fractoid/android.keystore
key.store=/home/dbyrne/Fractoid/android.keystore
key.alias=android_dev_key
12 changes: 10 additions & 2 deletions res/layout/main_layout.xml
Expand Up @@ -17,7 +17,15 @@
android:layout_alignParentTop="true"
android:layout_marginTop="5px"
android:layout_marginRight="5px"/>



<Button
android:id="@+id/juliaButton"
android:text="Julia Set Mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5px"
android:layout_marginRight="5px"/>

</RelativeLayout>
20 changes: 12 additions & 8 deletions res/menu/options_menu.xml
Expand Up @@ -26,25 +26,29 @@
</group>
</menu>
</item>
<item android:id="@+id/julia_button"
android:title="Julia Set Mode"/>
<item android:id="@+id/equation_button"
android:title="Change Equation">
<menu>
<group android:checkableBehavior="single">
<item android:id="@+id/z2_button"
android:checked="true"
android:title="Z^2 + C"/>
android:title="Mandelbrot: Z(n)^2 + C"/>
<item android:id="@+id/z3_button"
android:title="Z^3 + C"/>
android:title="Cubic Mandelbrot: Z(n)^3 + C"/>
<item android:id="@+id/z4_button"
android:title="Z^4 + C"/>
android:title="Quartic Mandelbrot: Z(n)^4 + C"/>
<item android:id="@+id/z5_button"
android:title="Z^5 + C"/>
android:title="Z(n)^5 + C"/>
<item android:id="@+id/z6_button"
android:title="Z^6 + C"/>
android:title="Z(n)^6 + C"/>
<item android:id="@+id/z4z3z2_button"
android:title="Z^4 - Z^3 - Z^2 + C"/>
android:title="Z(n)^4 - Z(n)^3 - Z(n)^2 + C"/>
<item android:id="@+id/z6z2_button"
android:title="Z(n)^6 - Z(n)^2 + C"/>
<item android:id="@+id/manowar_button"
android:title="Manowar: Z(n)^2 + Z(n-1) + C"/>
<item android:id="@+id/phoenix_button"
android:title="Phoenix Julia: Z(n)^2 + Re(C) + Im(C)*Z(n-1)"/>
</group>
</menu>
</item>
Expand Down
5 changes: 4 additions & 1 deletion src/byrne/fractal/ComplexEquation.java
Expand Up @@ -6,5 +6,8 @@ public enum ComplexEquation {
FOURTH_ORDER,
FIFTH_ORDER,
SIXTH_ORDER,
Z4Z3Z2
Z4Z3Z2,
Z6Z2,
MANOWAR,
PHOENIX
}
42 changes: 36 additions & 6 deletions src/byrne/fractal/FractalView.java
Expand Up @@ -86,6 +86,29 @@ public void setType(FractalType t) {
public Bitmap getFractal() {
return fractalBitmap;
}

public void createPhoenixSet() {
double imagmax = 1.4;
double imagmin = -1.4;

double r_y = Math.abs(imagmax - imagmin);
double realmax = params.getResRatio()*r_y/2;
double realmin = params.getResRatio()*r_y/2*-1;

params.randomizeShiftFactor();
setEquation(ComplexEquation.PHOENIX);
setType(FractalType.JULIA);

params.setEquation(ComplexEquation.PHOENIX);
params.setType(FractalType.JULIA);
params.setCoords(realmin,realmax,imagmin,imagmax);
params.setP(0.56667);
params.setQ(-0.5);
params.setMaxIterations(100);

startFractalTask();
setZoom(true);
}

public void startFractalTask() {
calculationTime = null;
Expand Down Expand Up @@ -126,7 +149,10 @@ protected void resetCoords() {
params.randomizeShiftFactor();
params.setEquation(equation);
params.setCoords(realmin,realmax,imagmin,imagmax);
params.setType(FractalType.MANDELBROT);
if (equation == ComplexEquation.PHOENIX)
params.setType(FractalType.JULIA);
else
params.setType(FractalType.MANDELBROT);
params.resetMaxIterations();

startFractalTask();
Expand Down Expand Up @@ -232,8 +258,12 @@ protected void resetCoords() {
canvas.drawBitmap(fractalBitmap,0,0,null);

Paint p = new Paint();
p.setColor(Color.WHITE);
p.setTextSize(20);
if (params.getColorSet() == ColorSet.BLACK_AND_WHITE) {
p.setColor(Color.BLACK);
} else {
p.setColor(Color.WHITE);
}
p.setTextSize(25);

if (selection != null) {
p.setStyle(Paint.Style.STROKE);
Expand All @@ -243,16 +273,16 @@ protected void resetCoords() {
p.setStyle(Paint.Style.FILL_AND_STROKE);
p.setStrokeWidth(1);
if (zoom) {
canvas.drawText("Drag to zoom",(params.getXRes()/2)-50,params.getYRes()-5,p);
canvas.drawText("Drag to zoom",(params.getXRes()/2)-60,params.getYRes()-5,p);
}
else {
canvas.drawText("Touch Screen to Generate Julia Set",(params.getXRes()/2)-125,params.getYRes()-5,p);
canvas.drawText("Touch Screen to Generate Julia Set",(params.getXRes()/2)-175,params.getYRes()-5,p);
}
String maxIterString = "MaxIter: " + params.getMaxIterations();
canvas.drawText(maxIterString,5,params.getYRes()-5,p);

if (calculationTime != null) {
canvas.drawText(calculationTime,params.getXRes()-120,params.getYRes()-5,p);
canvas.drawText(calculationTime,params.getXRes()-140,params.getYRes()-5,p);
}

} else {
Expand Down
76 changes: 56 additions & 20 deletions src/byrne/fractal/Fractoid.java
Expand Up @@ -23,8 +23,9 @@
public class Fractoid extends Activity {

private FractalView fractalView;
private MenuItem item2, item3, item4, item5, item6, item7;
private MenuItem juliaItem, itemRainbow, itemRed, itemGreen, itemYellow, itemBlackAndWhite;
private MenuItem item2, item3, item4, item5, item6, item7, item8, itemManowar, itemPhoenix;
private MenuItem itemRainbow, itemRed, itemGreen, itemYellow, itemBlackAndWhite;
private Button juliaButton;
private final int MAX_ITERATIONS_DIALOG = 1;

@Override public void onCreate(Bundle savedInstanceState) {
Expand All @@ -33,6 +34,17 @@ public class Fractoid extends Activity {
setContentView(R.layout.main_layout);

fractalView = (FractalView) findViewById(R.id.mFractalView);

juliaButton = (Button) findViewById(R.id.juliaButton);
juliaButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setJuliaButtonEnabled(false);
fractalView.setType(FractalType.JULIA);
fractalView.setZoom(false);
fractalView.postInvalidate();
}
});

final Button zoomOutButton = (Button) findViewById(R.id.zoomOutButton);
zoomOutButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Expand Down Expand Up @@ -74,21 +86,27 @@ public void onClick(View v) {
return dialog;
}

public void setJuliaMenuEnabled(boolean b) {
juliaItem.setVisible(b);
juliaItem.setEnabled(b);
public void setJuliaButtonEnabled(boolean b) {
if (b) {
juliaButton.setVisibility(View.VISIBLE);
} else {
juliaButton.setVisibility(View.INVISIBLE);
}
juliaButton.setEnabled(b);
}

@Override public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
juliaItem = menu.findItem(R.id.julia_button);
item2 = menu.findItem(R.id.z2_button);
item3 = menu.findItem(R.id.z3_button);
item4 = menu.findItem(R.id.z4_button);
item5 = menu.findItem(R.id.z5_button);
item6 = menu.findItem(R.id.z6_button);
item7 = menu.findItem(R.id.z4z3z2_button);
item8 = menu.findItem(R.id.z6z2_button);
itemManowar = menu.findItem(R.id.manowar_button);
itemPhoenix = menu.findItem(R.id.phoenix_button);
itemRainbow = menu.findItem(R.id.rainbow_button);
itemRed = menu.findItem(R.id.red_button);
itemGreen = menu.findItem(R.id.green_button);
Expand All @@ -102,7 +120,8 @@ public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.reset_button:
setJuliaMenuEnabled(true);
if (!itemPhoenix.isChecked())
setJuliaButtonEnabled(true);
fractalView.resetCoords();
return true;

Expand Down Expand Up @@ -134,19 +153,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
fractalView.setColorSet(ColorSet.BLACK_AND_WHITE);
itemBlackAndWhite.setChecked(true);
return true;

case R.id.julia_button:
setJuliaMenuEnabled(false);
fractalView.setType(FractalType.JULIA);
fractalView.setZoom(false);
fractalView.postInvalidate();
return true;

case R.id.z2_button:
if (!item2.isChecked()) {
item2.setChecked(true);
fractalView.setEquation(ComplexEquation.SECOND_ORDER);
setJuliaMenuEnabled(true);
setJuliaButtonEnabled(true);
fractalView.resetCoords();
}
return true;
Expand All @@ -155,7 +167,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (!item3.isChecked()) {
item3.setChecked(true);
fractalView.setEquation(ComplexEquation.THIRD_ORDER);
setJuliaMenuEnabled(true);
setJuliaButtonEnabled(true);
fractalView.resetCoords();
}
return true;
Expand All @@ -164,7 +176,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (!item4.isChecked()) {
item4.setChecked(true);
fractalView.setEquation(ComplexEquation.FOURTH_ORDER);
setJuliaMenuEnabled(true);
setJuliaButtonEnabled(true);
fractalView.resetCoords();
}
return true;
Expand All @@ -173,7 +185,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (!item5.isChecked()) {
item5.setChecked(true);
fractalView.setEquation(ComplexEquation.FIFTH_ORDER);
setJuliaMenuEnabled(true);
setJuliaButtonEnabled(true);
fractalView.resetCoords();
}
return true;
Expand All @@ -182,7 +194,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (!item6.isChecked()) {
item6.setChecked(true);
fractalView.setEquation(ComplexEquation.SIXTH_ORDER);
setJuliaMenuEnabled(true);
setJuliaButtonEnabled(true);
fractalView.resetCoords();
}
return true;
Expand All @@ -191,10 +203,34 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (!item7.isChecked()) {
item7.setChecked(true);
fractalView.setEquation(ComplexEquation.Z4Z3Z2);
setJuliaMenuEnabled(true);
setJuliaButtonEnabled(true);
fractalView.resetCoords();
}
return true;

case R.id.z6z2_button:
if (!item8.isChecked()) {
item8.setChecked(true);
fractalView.setEquation(ComplexEquation.Z6Z2);
setJuliaButtonEnabled(true);
fractalView.resetCoords();
}
return true;

case R.id.manowar_button:
if (!itemManowar.isChecked()) {
itemManowar.setChecked(true);
fractalView.setEquation(ComplexEquation.MANOWAR);
setJuliaButtonEnabled(true);
fractalView.resetCoords();
}

case R.id.phoenix_button:
if (!itemPhoenix.isChecked()) {
itemPhoenix.setChecked(true);
setJuliaButtonEnabled(false);
fractalView.createPhoenixSet();
}

case R.id.save_button:
try {
Expand Down
26 changes: 25 additions & 1 deletion src/byrne/fractal/GenerateFractalTask.java
Expand Up @@ -107,7 +107,7 @@ private Bitmap createBitmap() {

int[] colorIntegers = calculateColors();

double x=-1, y=-1, mu = 1;
double x=-1, y=-1, prev_x = -1, prev_y =-1,tmp_prev_x,tmp_prev_y, mu = 1;
int index;
boolean lessThanMax;

Expand All @@ -132,10 +132,13 @@ private Bitmap createBitmap() {
if (type == FractalType.MANDELBROT) {
P = realmin + col*deltaP;
x = y = 0.0;
prev_x = prev_y = 0.0;
} else if (type == FractalType.JULIA) {

x = realmin + (double)col * deltaP;
y = imagmax - (double)row * deltaQ;
prev_x = x;
prev_y = y;
}
lessThanMax = false;

Expand Down Expand Up @@ -180,6 +183,27 @@ private Bitmap createBitmap() {
case Z4Z3Z2:
xtmp = x*x*x*x - 6*x*x*y*y + y*y*y*y - (x*x*x - 3*x*y*y) - (xsq - ysq) + P;
y = 4*x*x*x*y - 4*x*y*y*y - (-y*y*y + 3*x*x*y) - (2*x*y) + Q;
break;
case Z6Z2:
xtmp = x*x*x*x*x*x-15*x*x*x*x*y*y+15*x*x*y*y*y*y-y*y*y*y*y*y - (xsq - ysq) + P;
y = (6*x*x*x*x*x*y-20*x*x*x*y*y*y+6*x*y*y*y*y*y) - (2*x*y) + Q;
break;
case MANOWAR:
tmp_prev_x = x;
tmp_prev_y = y;
xtmp = (xsq - ysq) + prev_x + P;
y = (2*x*y) + prev_y + Q;
prev_x = tmp_prev_x;
prev_y = tmp_prev_y;
break;
case PHOENIX:
tmp_prev_x = x;
tmp_prev_y = y;
xtmp = (xsq - ysq) + P + Q*prev_x;
y = (2*x*y) + Q*prev_y;
prev_x = tmp_prev_x;
prev_y = tmp_prev_y;
break;
}
x = xtmp;
}
Expand Down

0 comments on commit 00e5947

Please sign in to comment.