int i_tnum = 8; tron[] ar_tron = new tron[i_tnum]; void setup(){ size(640,360); for(int i=0; i < i_tnum; i++){ ar_tron[i] = new tron(); } } void loop(){ background(255,255,255); float dx, dy; float dist; float col, cr, cg, cb; color c; tron tr; for(int i=0; i < i_tnum; i++){ ar_tron[i].update(); } for(int y=0; y < height; y+=5){ for(int x=0; x < width; x+=5){ col = 0; for(int t=0; t < i_tnum; t++){ dist = 1200 / sqrt(sq(x-ar_tron[t].f_x) + sq(y-ar_tron[t].f_y)); col += dist; } col = col * col*col * col *col * 0.00000005; c = color(col,col,col); if(col > 80){ c = color(230,230,0); pixels[y*width + x] = c; pixels[y*width + x+1] = c; pixels[y*width + x+2] = c; pixels[y*width + x+3] = c; pixels[(y+1)*width + x] = c; pixels[(y+1)*width + x+1] = c; pixels[(y+1)*width + x+2] = c; pixels[(y+1)*width + x+3] = c; } else if(col > 40){ c = color(100,100,0); pixels[y*width + x] = c; pixels[y*width + x+1] = c; pixels[y*width + x+2] = c; pixels[y*width + x+3] = c; pixels[(y+1)*width + x] = c; pixels[(y+1)*width + x+1] = c; pixels[(y+1)*width + x+2] = c; pixels[(y+1)*width + x+3] = c; } } } } class tron{ float f_x, f_y; float f_vx, f_vy; float f_r, f_g, f_b; tron(){ f_x = random(width); f_y = random(height); f_vx = random(6) - 3; f_vy = random(6) - 3; f_r = random(1) *0.5 + 0.4; f_g = random(1) *0.5 + 0.4; f_b = random(1) *0.5 + 0.4; } void update(){ f_x += f_vx; f_y += f_vy; if (f_x > width){ f_x = width; f_vx = -abs(f_vx); }else if(f_x < 0){ f_x = 0; f_vx = abs(f_vx); } if (f_y > height){ f_y = height; f_vy = -abs(f_vy); }else if(f_y < 0){ f_y = 0; f_vy = abs(f_vy); } } }