Created
January 14, 2009 05:25
-
-
Save masaakif/46796 to your computer and use it in GitHub Desktop.
Processing - Draw Square - Debug
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
int MAX = 500; | |
int idx = 0; | |
RectDrawer[] rd; | |
int prevMouseX, prevMouseY; | |
color cl1 = color(255,0,0); | |
void setup() { | |
rd = new RectDrawer[MAX]; | |
size(500, 500); | |
noStroke(); | |
randomSeed(0); | |
// noLoop(); | |
frameRate(30); | |
for (int i = 0; i < MAX; i++) { | |
rd[i] = null; | |
} | |
prevMouseX = 0; prevMouseY = 0; | |
} | |
void draw() { | |
background(128,128,128); | |
if (mouseX != prevMouseX || mouseY != prevMouseY) { | |
if (rd[idx] == null) { | |
// println(idx + " x:" + mouseX + " y:" + mouseY); | |
rd[idx] = new RectDrawer(idx, mouseX, mouseY, 15, getColor()); | |
idx++; | |
prevMouseX = mouseX; | |
prevMouseY = mouseY; | |
} | |
} | |
if (495 < idx) idx = 0; | |
// println("----"); | |
for (int i = 0; i < MAX; i++) | |
{ | |
if (rd[i] == null) continue; | |
if (rd[i].isLiving() == true) { | |
rd[i].drawRect(); | |
} | |
else { | |
rd[i] = null; | |
} | |
} | |
} | |
color getColor() | |
{ | |
float fr = red(cl1) - 5; | |
if (fr < 10) fr = 255; | |
cl1 = color(fr, 0,0); | |
return cl1; | |
} | |
class RectDrawer { | |
int life = 50; | |
float xpos, ypos, rectsize; | |
color cl; | |
color prevcl; | |
int m_idx; | |
RectDrawer(int i, float x, float y, float s, color c) { | |
m_idx = i; | |
xpos = x; ypos = y; rectsize = s; cl = c; | |
prevcl = cl; | |
} | |
public boolean isLiving() { | |
if (-20 < life) return true; | |
return false; | |
} | |
void drawRect() { | |
rect(xpos, ypos, rectsize, rectsize); | |
fill(cl); | |
//print("i:" + m_idx + "\tx:" + xpos + "\ty:" + ypos + "\tc:" + cl + "<RET>"); | |
onetick(); | |
} | |
void onetick() | |
{ | |
life -= 5; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment