Lunedi' 2 Dicembre 2002 : 15 53 1 - zito da 193.204.188.254

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Vita extends JApplet {
Display disegno;
boolean [][] matrice;
int np = 4;
public void init(){
disegno = new Display();
setContentPane(disegno);
matrice = new boolean[100][100];
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(Math.random()>.5)matrice[i][j]=true;
else matrice[i][j]=false;
}
}
}
class Display extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(new Color(255,0,0));
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(matrice[i][j])g.fillRect(
i*np,j*np,np,np);
}
}



}
}
}
Lunedi' 2 Dicembre 2002 : 16 29 - zito da 193.204.188.254

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Vita extends JApplet
implements ActionListener{
Display disegno;
boolean [][] matrice;
int np = 4;
Timer animazione;
public void start(){
if(animazione==null){
animazione = new Timer(1000,this);
animazione.start();
}
}
public void stop(){
if(animazione!=null){
animazione.stop();
}
}
public void actionPerformed(ActionEvent e){
int nv ;
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
nv = contavicini(i,j);

if( matrice[i][j] &&
(nv==0 || nv==1 ||
nv==4 || nv==5 || nv==6 ||
nv==7 || nv==8))
matrice[i][j]=false;
if(!matrice[i][j]&& nv>=3)
matrice[i][j]=true; }
}
disegno.repaint();
}
int contavicini(int i, int j){
int nv = 0;
int i1,i2,j1,j2;
i1 = i-1;if(i1<0)i1=99;
i2 = i +1;if(i2>99)i2=0;
j1 = j-1;if(j1<0)j1=99;
j2 = j +1;if(j2>99)j2=0;

if(matrice[i1][j])nv=nv+1;
if(matrice[i1][j1])nv=nv+1;
if(matrice[i][j2])nv=nv+1;
if(matrice[i2][j2])nv=nv+1;
if(matrice[i2][j])nv=nv+1;
if(matrice[i2][j1])nv=nv+1;
if(matrice[i][j1])nv=nv+1;
if(matrice[i1][j1])nv=nv+1;
return(nv);
}

public void init(){
disegno = new Display();
setContentPane(disegno);
matrice = new boolean[100][100];
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(Math.random()>.5)matrice[i][j]=true;
else matrice[i][j]=false;
}
}
}
class Display extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(new Color(255,0,0));
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(matrice[i][j])g.fillRect(
i*np,j*np,np,np);
}
}



}
}
}
Lunedi' 2 Dicembre 2002 : 16 50 1 - zito da 193.204.188.254

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Vita extends JApplet
implements ActionListener{
Display disegno;
boolean [][] matrice;
int np = 4;
Timer animazione;
public void start(){
if(animazione==null){
animazione = new Timer(100,this);
animazione.start();
}
}
public void stop(){
if(animazione!=null){
animazione.stop();
}
}
public void actionPerformed(ActionEvent e){
int nv ;
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
nv = contavicini(i,j);

if( matrice[i][j] &&
(nv==0 || nv==1 ||
nv==4 || nv==5 || nv==6 ||
nv==7 || nv==8)){
matrice[i][j]=false;} else {
if(!matrice[i][j]&& nv==3)
matrice[i][j]=true; } }
}
disegno.repaint();
}
int contavicini(int i, int j){
int nv = 0;
int i1,i2,j1,j2;
i1 = i-1;if(i1<0)i1=99;
i2 = i +1;if(i2>99)i2=0;
j1 = j-1;if(j1<0)j1=99;
j2 = j +1;if(j2>99)j2=0;

if(matrice[i1][j])nv=nv+1;//sopra
if(matrice[i1][j2])nv=nv+1;//sopra a destra
if(matrice[i][j2])nv=nv+1;//accanto a destra
if(matrice[i2][j2])nv=nv+1;//sotto a destra
if(matrice[i2][j])nv=nv+1;//sotto
if(matrice[i2][j1])nv=nv+1;//sotto a sinistra
if(matrice[i][j1])nv=nv+1;//accanto a sinistra
if(matrice[i1][j1])nv=nv+1;//sopra a sinistra
return(nv);
}

public void init(){
disegno = new Display();
setContentPane(disegno);
matrice = new boolean[100][100];
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(Math.random()>.05)matrice[i][j]=true;
else matrice[i][j]=false;
}
}
}
class Display extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(new Color(255,0,0));
for (int i = 0; i<100;i++){
for(int j = 0; j<100;j++){
if(matrice[i][j])g.fillRect(
i*np,j*np,np,np);
}
}



}
}
}