0% found this document useful (0 votes)
34 views1 page

Java Demo Patrate

Uploaded by

gigiberlogea
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Java Demo Patrate

Uploaded by

gigiberlogea
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.applet.Applet; import java.awt.*; import java.util.

Random; public class Patrate4 extends Applet { static Graphics G; static mark A[]; class mark { Color c; int x,y; int w=1,h=1; Random generator = new Random(); mark() { x=generator.nextInt(350); y=generator.nextInt(200); float r float g float b c = new } mark(int a,int b){ x = a; y=b; c = new Color(255, 0, 0); w=10;h=10; } double distanta(mark a){ return Math.sqrt( (this.x-a.x)*(this.x-a.x) + (this.y-a.y)*(this.y-a.y)); } void neighbour(double d){ for(mark m:A){ if(distanta(m)<=d) m.c =this.c; } } } public static void display(){ for(mark m:A){ G.setColor(m.c); G.fillRect(m.x, m.y, m.w, m.h); } } @Override public void paint(Graphics g) { G = g; display(); } @Override public void init() { // TODO start asynchronous download of heavy resources A = new mark[60000]; for(int i=0;i<A.length;i++)A[i]=new mark(); mark x = new mark(200,100); x.neighbour(34.5); } // TODO overwrite start(), stop() and destroy() methods } = generator.nextFloat(); = generator.nextFloat(); = generator.nextFloat(); Color(r, g, b);

You might also like