Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Forks of this sketch will become the forks of "fideos 2".
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
A fork of fideos 2 by garabatospr
CC Attribution NonCommercial ShareAlike
fideos 2
Wiebenga
xxxxxxxxxx
// color palette
//var colors = ["#ff0000","#feb30f","#0aa4f7","#000000","#ffffff"];
let colors = ['#f0101c', '#f05697', '#0b469b', '#32b6c3', '#f78000', '#fddf0e', '#9fe063', '#315423', '#16141b', '#ffffff'];
// set weights for each color
var weights = [1, 2, 2, 1, 0, 1];
// scale of the vector field
// smaller values => bigger structures
// bigger values ==> smaller structures
var myScale = 2;
// number of drawing agents
var nAgents = 700;
let agent = [];
// set spinning direction (plus or minus)
var direction = 1;
var par = 0;
let border = 150;
function setup() {
createCanvas(800, 800);
colorMode(HSB, 360, 100, 100);
rectMode(CENTER);
strokeCap(SQUARE);
background(100);
//let mySize = 100;
for (let i = 0; i < nAgents; i++) {
agent.push(new Agent());
}
//noLoop();
smooth(8);
}
function draw() {
for (let i = 0; i < agent.length; i++)
{
agent[i].update();
}
}
// select random colors with weights from palette
function myRandom(colors, weights) {
let tt = 0;
let sum = 0;
for (let i = 0; i < colors.length; i++) {
sum += weights[i];
}
let rr = random(0, sum);
for (let j = 0; j < weights.length; j++) {
if (weights[j] >= rr) {
return colors[j];
}
rr -= weights[j];
}
return tt;
}
// paintining agent
class Agent {
constructor() {
this.p = createVector(random(border, width - border), random(border, height - border));
this.pOld = createVector(this.p.x, this.p.y);
this.step = 0.25;
this.rad = 30;
let temp = myRandom(colors, weights);
this.color = generateColor();
this.color2 = generateColor();
if (random(0, 1) > 0.5) {
this.direction = 1;
} else {
this.direction = -1;
}
this.myrand = random(0,1);
this.strokeWidth = 0.5;
}
getRad()
{
return this.rad;
}
update() {
if (random(0, 1) < 1.0e-4) {
this.direction *= -1;
}
this.p.x += direction * vector_field(this.p.x, this.p.y).x * this.step ;
this.p.y += direction * vector_field(this.p.x, this.p.y).y * this.step ;
strokeWeight(this.strokeWidth);
stroke(this.color);
fill(100);
if (this.rad > 1)
{
if(this.myrand < 0.5)
{
//noStroke();
//fill(this.color);
ellipse(this.p.x, this.p.y, this.rad,this.rad);
this.rad -= 0.1;
}
}else
{
//fill(this.color2);
//stroke(100);
//strokeWeight(1);
//ellipse(this.p.x, this.p.y, this.rad*2,this.rad*2);
stroke(0);
noFill();
strokeWeight(50);
rect(width/2,height/2,width,height)
//noLoop();
}
this.pOld.set(this.p);
//this.isOutside = false;
}
}
// vector field function
// the painting agents follow the flow defined
// by this function
function vector_field(x, y) {
//myScale = map(-10,10,x,0,width);
x = map(x, 0, width, 0, myScale);
y = map(y, 0, height, 0, myScale);
//let k1 = 5;
let k1 = map(x,-myScale,myScale,-10,10);
//let k2 = 3;
let k2 = map(y,-myScale,myScale,-10,10);
let u = sin(k1 * y) + cos(k2 * y);
let v = sin(k2 * x) - cos(k1 * x);
//let v = cos(k2*x);
return createVector(u, v);
}
function vector_field2(x,y) {
x = map(x,0,width,0,myScale);
y = map(y,0,height,0,myScale);
let u = -4.0*(floor(y) % 2);
let v = -4.0*(floor(x) % 2);
return createVector(u,v);
}
// function to select
function myRandom(colors, weights) {
let tt = 0;
let sum = 0;
for (let i = 0; i < colors.length; i++) {
sum += weights[i];
}
let rr = random(0, sum);
for (let j = 0; j < weights.length; j++) {
if (weights[j] >= rr) {
return colors[j];
}
rr -= weights[j];
}
return tt;
}
function generateColor() {
let temp = color(colors[floor(random(0, 10))]);
myColor = color(hue(temp) + randomGaussian() * 10,
saturation(temp) + randomGaussian() * 10,
brightness(temp) * 0.75,
random(99,100));
return myColor;
}
See More Shortcuts
Please verify your email to comment
Verify Email