Stop
Continue
Go
/* Implicit Line and Circle This example uses an implicit representations of a line and a circle to draw a picture. 3000 blotches are placed at random locations. Points inside a specific circle are colored green. Points above the line are colored red. Points below the line are colored blue. Colors include transparency to give a blending effect. */ /* This function draws a blotch by drawing horizontal lines of random length inside the square from (x-r,y-r) to (x+r,y+r). */ function squareBlotch(x,y,r){ var i; //index and horizontal coordinate for (i=-r;i<=r;i=i+1) line(x-r*random(), y+i, x+r*random(), y+i); } /* This function uses the imlicit definition of a line (y-y1)*(x2-x1)-(x-x1)*(y2-y1)=0 connecting (x1,y1) and (x2,y2). A positive return value puts (x,y) on one side of the line. A negative value puts it on the other. */ function impLine(x,y,x1,y1,x2,y2){ return((y-y1)*(x2-x1)-(x-x1)*(y2-y1)); } /* This function uses the implicit definition of a circle (x-x1)*(x-x1)+(y-y1)*(y-y1)-r*r=0 centered at (x1,y1) with radius r. A positive return value means that (x,y) is outside of the circle. A negative value puts (x,y) inside the circle. */ function impCircle(x,y,x1,y1,r){ return((x-x1)*(x-x1)+(y-y1)*(y-y1)-r*r); } function setup(){ color(0,0,0,0); //this makes the outline of the //circles invisible } function draw(){ var x,y; //coordinates of circle var d; //value from LINE function var e; //value for CIRCLE function var i; //index for for loop //repeat 3000 times for (i=0;i<3000;i=i+1){ //random point x=width*random(); y=height*random(); //we call impLine with the line //connecting (0,300) and (400,100) d=impLine(x,y,0,300,400,100); //call impCircle with circle //at (200,200) with radius 100 e=impCircle(x,y,200,200,100); if (e<0) //inside circle color(0,255,0,0.1) else if (d<0) //above the line color(255,0,0,0.1); else //below or on the line color(0,0,255,0.1); squareBlotch(x,y,10); fill(); } }
default
3024-day
3024-night
ambiance
base16-dark
base16-light
blackboard
cobalt
eclipse
elegant
erlang-dark
lesser-dark
mbo
mdn-like
midnight
monokai
neat
night
paraiso-dark
paraiso-light
pastel-on-dark
rubyblue
solarized dark
solarized light
the-matrix
tomorrow-night-eighties
twilight
vibrant-ink
xq-dark
xq-light