The prompt for Genuary2023 Day 8 is
"SDF - Signed Distance Fields"
For Today's prompt, the piece is named Splatter Distance Fields
Code aided and borrowed/started by @piterpasma tutorial ( for Genuary to get started with SDFS
Genuary explainer page : https://genuary.art/wtsdf
@Piterpasma Tutorial : https://youtu.be/KRB57wyo8_4
Built upon the P5js code to turn it into layering Splatters
The audio is coded in SonicPi
Poem
In this batter of splatter
The splatters are staggered
Some splatters are slackers
Others are packers
Some act as if they are ladders
While others can’t hold their bladders
P5js
/*
Code aided and borrowed/started by @piterpasma
Link here for that : https://youtu.be/KRB57wyo8_4
Built upon it to do Splatter Distance Field
*/
//redefining the random
let R = (a=1)=> Math.random()*a;
//length of vector
// sqaure root of a ^ 2 + b ^ 2 //
let L = (x,y) => (x*x+y*y)**0.5;
function setup()
{
createCanvas(displayWidth,displayHeight);
background('black')
}
//redefining the circle formula
/*
passing an array as the coordinates in the draw circle
r = radius
c = color
*/
function draw_circle([x,y],r,c)
{
//coordinates going between -1,1 (stretch over screen)
if (second() % 30 > 12)
{
noStroke();
}
i = 0
colors = ['#98fb98', '#b22222', '#f0e68c', '#ff4500', '#008080']
if (second() % 30 < 12)
{
stroke(colors[i])
i += 1
if (i >= colors.length)
{
i = 0
}
}
fill(c); //fill with color
//p5 goes with diameter by default
circle((x+1)*width/1.3,(y+1)*width/1.3,r/2)
circle((x+1)*width/2,(y+1)*width/2,r/2)
circle((x+1)*width/4,(y+1)*width/4,r/2)
circle((x+1)*width/6,(y+1)*width/6,r/2)
circle((x+1)*width/8,(y+1)*width/8,r/2)
}
//center coordinates is cx, cy
function sdf_circle([x,y],[cx,cy], r)
{
x -= cx;
y -= cy;
return L(x,y) - r;
}
//shapes have insted and outside, purpose of sdf is to calcuate between them
//taking the array of coordinates
function sdf([x,y])
{
//inside the shape is negative and outside is positive
// SDF of a circle is Length of Vector - the radius of the circle
// this means this vector is .6 away from the origin
dicey = random(0.4,0.6)
let ball =sdf_circle([x,y],[dicey + (second() % 5)/8,dicey+ (second() % 5)/8], 0.4)
let slope = -x+ 0.4
let slope2 = -y + 0.4
return Math.min(slope,ball)
}
function draw()
{
if (second() % 11 < 5)
{
looping = 5000
}
else
{
looping = 500
}
//draw a point 1000 times
for (let i = 0;i < looping; i++)
{
//random point utilizing the R function from before
pointy(1.5 + (second() % 10)/7,'#f5deb3', '#8b8378', '#191970', '#ff7f50', '#7fffd4')
pointy(2.5 - (second() % 10)/20,'white','pink','red','gold','blanchedalmond')
pointy(0.9,'#3f3fff', '#006400', '#8b008b', '#228b22', '#2f4f4f')
}
}
function pointy (x,coloring,coloring2,coloring3,coloring4,coloring5)
{
let points = [R(x)-1, R(x)-1];
let distance = sdf((points));
let colour = coloring
if (distance < -0.01)
if(second() % 2 == 0)
colour = coloring2
else
colour = coloring4
if (distance > 0.01)
if(second() % 3 == 0)
colour = coloring3
else
colour = coloring5
draw_circle(points,2,colour)
draw_circle(points,4,colour)
draw_circle(points,1,colour)
}
SonicPi Code
def tweet(bpm,synthing,minOrmaj)
live_loop :a do
with_fx [:ixi_techno,:gverb].tick do
use_bpm bpm
use_synth synthing
play chord(dice(bpm *2), minOrmaj)
play chord(dice(bpm *2), minOrmaj)
sample [:misc_crow,:misc_burp,:perc_snap].choose,beat_stretch: dice(3),decay: 4,sustain: 8
sleep [0.25,0.5,1].choose
end
end
end
tweet(5,:piano,:minor)
tweet(9,:organ_tonewheel,:major)
tweet(40,:chipbass,[:major,:minor].choose)
tweet(20,:pretty_bell,[:major,:minor].choose)