Stop
Continue
Go
/* Implicit Line and Circle This example uses an implicit representations of a line and a circle to draw a picture. 5000 circles 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 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 5000 times for (i=0;i<5000;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 fillcolor(0,255,0,0.1) else if (d<0) //above the line fillcolor(255,0,0,0.1); else //below or on the line fillcolor(0,0,255,0.1); circle(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