Created
May 4, 2012 15:17
-
-
Save stimms/2595438 to your computer and use it in GitHub Desktop.
Playing with processing
This file contains hidden or 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
<html> | |
<script src="processing.js"></script> | |
<script type="application/processing" data-processing-target="pjs"> | |
int blobCount = 10; | |
GlowingBlob[] blobs = new GlowingBlob[blobCount]; | |
void setup() { | |
size(500, 500); | |
background(100); | |
stroke(255); | |
for(int i=0; i<blobCount;i++) | |
{ | |
PVector startingLocation = calculateRandomLocationInCircle(new PVector(250,250), 200); | |
blobs[i]=new GlowingBlob(startingLocation, random(0,100)); | |
} | |
} | |
double counter = 0; | |
void draw(){ | |
counter++; | |
fill(0,0,0); | |
rect(0,0,500,500); | |
stroke(230,230,230); | |
//ellipse(250, 250, 400, 400); | |
fill(0,255,0); | |
stroke(0,255,0); | |
arc(250,250,400,400,TWO_PI - (TWO_PI * (counter/1000)),TWO_PI); | |
fill(255,0,0); | |
arc(250,250,400,400,0,TWO_PI - (TWO_PI * (counter/1000))); | |
println(counter); | |
for(int i=0; i<blobCount;i++) | |
{ | |
blobs[i].draw(); | |
} | |
} | |
PVector calculateRandomLocationInCircle(PVector center, int radius) | |
{ | |
int randomDistance = random(0,radius); | |
int randomAngle = random(0,360); | |
double randomX = cos(randomAngle%90) * randomDistance; | |
double randomY = sin(randomAngle%90) * randomDistance; | |
if(randomAngle>90 && randomAngle <=180) | |
{ | |
randomX = randomX * -1; | |
} | |
if(randomAngle>180 && randomAngle <=270) | |
{ | |
randomX = randomX * -1; | |
randomY = randomY * -1; | |
} | |
if(randomAngle>270 && randomAngle <=360) | |
{ | |
randomY = randomY * -1; | |
} | |
return new PVector(randomX+center.x, randomY+center.y); | |
} | |
class GlowingBlob{ | |
int currentSize=0; | |
boolean growing = true; | |
int centerX=0; | |
int centerY=0; | |
GlowingBlob(PVector center) | |
{ | |
centerX=center.x; | |
centerY=center.y; | |
} | |
GlowingBlob(PVector center, int initialSize) | |
{ | |
centerX=center.x; | |
centerY=center.y; | |
currentSize = initialSize; | |
} | |
void draw(){ | |
setSize(); | |
fill(currentSize+40,currentSize+140,currentSize+40); | |
ellipse(centerX,centerY,currentSize,currentSize); | |
} | |
void setSize() | |
{ | |
if(currentSize>100 || currentSize<0) | |
{ | |
growing = ! growing; | |
} | |
if(growing) | |
currentSize++; | |
else | |
currentSize--; | |
} | |
} | |
</script> | |
<body> | |
<canvas width="500" height="500" id="pjs"></canvas> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment