Last active
December 1, 2016 15:31
-
-
Save dtb49/9650ef73bf34667ed2f381fefc472227 to your computer and use it in GitHub Desktop.
Random Projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.ungdoodle; | |
//doodler | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.view.Menu; | |
import android.widget.*; | |
import android.content.Context; | |
import android.view.View.OnTouchListener; | |
import android.graphics.*; | |
import android.view.MotionEvent; | |
import android.view.View; | |
import java.util.ArrayList; | |
public class MainActivity extends Activity { | |
LinearLayout ll=null; | |
DoodleView dv=null; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ll=(LinearLayout)findViewById(R.id.base); | |
dv=new DoodleView(this); | |
ll.addView(dv,1); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.main, menu); | |
return true; | |
} | |
} | |
class DoodleView extends TextView implements OnTouchListener{ | |
ArrayList<dot> sketch=new ArrayList<dot>(); | |
Paint myPaint=new Paint(); | |
float[] xvel=new float[1000]; | |
float[] yvel=new float[1000]; | |
public DoodleView(Context myContext){ | |
super(myContext); | |
this.setBackgroundColor(Color.WHITE); | |
this.setHeight(480); | |
this.setFocusable(true); | |
this.setFocusableInTouchMode(true); | |
this.setOnTouchListener(this); | |
myPaint.setColor(Color.BLUE); | |
myPaint.setStyle(Paint.Style.FILL_AND_STROKE); | |
for (int i=0;i<1000;i++) | |
{ | |
xvel[i]=1; | |
yvel[i]=1; | |
} | |
} | |
public void onDraw(Canvas c) { | |
dot last=null; | |
int i=0; | |
for(dot d:sketch){ | |
myPaint.setColor(Color.BLACK); | |
c.drawCircle(d.x, d.y, 4, myPaint); | |
myPaint.setColor(Color.RED); | |
if (last!=null) | |
c.drawLine(last.x, last.y, d.x, d.y, myPaint); | |
last=d; | |
d.x+= xvel[i]; | |
d.y+= yvel[i]; | |
if (d.x>480) xvel[i]=-xvel[i]; | |
if (d.y>480) yvel[i]=-yvel[i]; | |
i++; | |
} | |
} | |
public boolean onTouch(View v, MotionEvent me){ | |
if(me.getAction()==MotionEvent.ACTION_DOWN){} | |
if(me.getAction()==MotionEvent.ACTION_MOVE){ | |
sketch.add(new dot(me.getX(), me.getY())); | |
} | |
if(me.getAction()==MotionEvent.ACTION_UP){} | |
invalidate(); | |
return true; | |
} | |
class dot{ | |
private float x; | |
private float y; | |
public dot(float x, float y){ | |
this.x=x; | |
this.y=y; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title> Dylan's Cool retirement Calculator | |
</title> | |
<script language="javascript"> | |
function calculate(){ | |
var monthly = Number(document.getElementById('monthly').value); | |
var rate = Number(document.getElementById('rate').value); | |
var years = Number(document.getElementById('years').value); | |
var total = 0; | |
// alert ("You're saving $" + monthly + " per month."); | |
for(var x = 0; x< years*12; x++) | |
{ | |
total += monthly + total * rate/100/12; | |
} | |
//alert(total); | |
document.getElementById('output').innerHTML = | |
"Your retirement total will be: <b>$" + total + "</b>"; | |
} | |
</script> | |
</head> | |
<body> | |
<h1>Calculate your retirement courtesy of Dylan: | |
</h1> | |
<form> | |
Monthly Investment Amount:<input type="text" name="monthly" id="monthly" /><br /> | |
Annual Rate of Return (%): | |
<input type="text" name="rate" id="rate" /><br /> | |
Number of Years to Invest: | |
<input type="text" name="years" id="years" onblur="calculate()"/><br /> | |
<input type="button" value="Calculate your Retirement" | |
onclick="calculate()" /> | |
</form> | |
<p id="output">Enter your savings plan above, and you'll see your | |
retirement forcast here.</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment