Nilo's Blog

Latest posts.

October 6th 2011
by

Some interesting java code…

Here is some code I wrote in the not to distant past.

Has to be with plotting primes on polar coords. Some interesting results appear.

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

class PolarCoords extends JFrame {

private static final long serialVersionUID = -8203440582994469232L;

int w = 700;
int h = 700;
int cw = w/2;
int ch = h/2;
List primes = null;
int tPrime = 0;
Image img = null;
double paintCount = 22.910;
double stepvalue = 0.00001;

public PolarCoords() {
//super("My Name");
generatePrimes();
setSize(w, h);
this.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {
System.out.println(e.getKeyCode());
if(e.getKeyCode() == 37) {
paintCount-=stepvalue;
repaint();
}
if(e.getKeyCode() == 39) {
paintCount+=stepvalue;
repaint();
}
}
public void keyReleased(KeyEvent e) {}

});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
img = createImage(w, h);
while(true) {
//tPrime = 0;
//try {
// Thread.sleep(1000);
//} catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
//}
repaint();
}
}

public void paint(Graphics g) {
//System.out.println("RePainting");

if(img != null) {
Graphics g2 = img.getGraphics();
g2.setColor(Color.black);
g2.fillRect(0, 0, w, h);

//tPrime = paintCount;

int cwt = cw;
int cht = ch;
//drawPoint(g2, cwt, cht);

double r = 0;
double t = 0;
tPrime = 0;
for(int i = 1; i < 16000; i++) {
r = (i / paintCount) + 1;
t = ((double)((double)(i % paintCount) / paintCount) * 360);
cwt = (int)(r * Math.cos(t));
cht = (int)(r * Math.sin(t));
//System.out.println("X: " + (cwt+cw) + " Y: " + (cht+ch));
drawPoint(g2, cwt+cw, cht+ch);
}
System.out.println("Count: " + paintCount);
}
g.drawImage(img, 0, 0, null);
//System.out.println("Finished Painting");
paintCount+= stepvalue;
}

private void drawPoint(Graphics g, int x, int y) {
Prime p = primes.get(tPrime);
if(p.isPrime) {
g.setColor(Color.white);
g.drawRect(x, y, 1, 1);
} else {
g.setColor(Color.blue);
//g.drawRect(x, y, 1, 1);
}
tPrime++;
}

private void generatePrimes() {
System.out.println("Starting to Gen primes");
primes = new ArrayList();
boolean isPrime = false;
for(int i = 1; i < w*h*2; i++) {
isPrime = true;
for(int j = 2; j <= (int)Math.sqrt(i); j++) {
if((i % j) == 0 && j != i) {
isPrime = false;
break;
}
}
primes.add(new Prime(i, isPrime));

}
System.out.println("Finished Generating Primes");
}

static public void main(String[] args) {
new PolarCoords();
}

}

public class Prime {

int prime = 0;
boolean isPrime = false;

public Prime(int prime, boolean isPrime) {
this.prime = prime;
this.isPrime = isPrime;
}
}

September 14th 2011
by

Pagosa Granola

We have started to sell Granola. Check out Pagosa Granola

July 19th 2011
by

A new hosted billing solution.

So I signed up for Bill4Time which is a good program for tracking consulting work. Check it out. Free Trial of Bill4Time.

June 23rd 2011
by

Fight…

Why has technology turned into a fight. As a solution provider I provide solutions, yet management always has to have the last say, always has to have the last final weird tweek, and ends up causing the solution to be way more brittle then it needs to be.

May 9th 2011
by

Followers…

The thing that frustrates me the most is people that are put into leadership roles that are just followers by nature. They have no clue where they are going in life, but rather just follow someone else or just do what some else says. On the other hand people think that I should be a leader, but the leaders that I have seen are ones that have some far out goal but figure out how to coerce other people to complete their goal for them. I know where I am going in life, if you want to follow great, if not great.

Links

 

Video & Audio Comments are proudly powered by Riffly