HashSet stars = new HashSet(); HashSet stripes = new HashSet(); color USARED = color(224,22,43); color USAWHITE = color(255,255,255); color USABLUE = color(0,82,165); void setup(){ size(400,400); smooth(); frameRate(30); // stars.add(new Star(200,200)); } void draw(){ background(USABLUE); if(mousePressed && frameCount % 2 == 0){ stars.add(new Star(mouseX,mouseY)); } if(mousePressed ){ stripes.add(new Stripe(mouseX,mouseY)); } Iterator stripeIt = stripes.iterator(); while(stripeIt.hasNext()){ Stripe stripe = (Stripe)stripeIt.next(); if(!stripe.move()){ stripeIt.remove();} stripe.draw(); } Iterator starIt = stars.iterator(); while(starIt.hasNext()){ Star star = (Star)starIt.next(); if(!star.move()) starIt.remove(); star.draw(); } } class Stripe{ float x1,y1,x2,y2,xs,ys; float SIZE = random(60,80); color c; Stripe(float x, float y){ float a = random(TWO_PI); x1 = x + SIZE*cos(a); y1 = y + + SIZE*sin(a); x2 = x; y2 = y; xs =( x1-x2 )/ 5; ys = (y1-y2) / 5; if(random(1)< .3333){ c = USAWHITE; } else { c = USARED; } } void draw(){ noFill(); strokeWeight(8); stroke(c); line(x1,y1,x2,y2); } boolean move(){ x1 += xs; x2 += xs; y1 += ys; y2 += ys; return !(bothOffscreenSamway(x1,x2)&&bothOffscreenSamway(y1,y2)); } boolean bothOffscreenSamway(float v1, float v2){ if(v1 < 0 && v2 < 0) return true; if(v1 > width && v2 > width) return true; return false; } } class Star{ float x,y; float xs,ys,as; Star(float x, float y){ this.x = x; this.y = y; as = random(-.8,.8); xs = random(-10,10); ys = random(-10,0); } float SIZE = 20; float angle = HALF_PI; boolean move(){ angle += .1; x = x + xs; y = y + ys; ys += 1; if(y > height + 2*SIZE){ return false; } return true; } void draw(){ noStroke(); fill(255); pushMatrix(); translate(x,y); beginShape(); vertex(cos(angle) * SIZE, sin(angle)*SIZE); vertex(cos(angle + TWO_PI*.4) * SIZE, sin(angle+ TWO_PI*.4)*SIZE); vertex(cos(angle + TWO_PI*.8) * SIZE, sin(angle+ TWO_PI*.8)*SIZE); vertex(cos(angle + TWO_PI*.2) * SIZE, sin(angle+ TWO_PI*.2)*SIZE); vertex(cos(angle + TWO_PI*.6) * SIZE, sin(angle+ TWO_PI*.6)*SIZE); endShape(CLOSE); popMatrix(); } }