Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
   <!-- add link to p5js	-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>
		<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
  </head>
  <body>
  </body>
</html>

              
            
!

CSS

              
                /* - reset css - */ 
html,body,div,form,fieldset,legend,label{margin:0;padding:0;}
table{border-collapse:collapse;border-spacing:0;}
th,td{text-align:left;vertical-align:top;}
h1,h2,h3,h4,h5,h6,th,td,caption{font-weight:normal;}
img{border:0;}
canvas{display:block;}


              
            
!

JS

              
                //plan for creative code: 
//the stuff move up from the box and disappear and then different stuff appear, random shapes and colors from the palette
// in practice I designed a range of scale placement and rotation for the shapes, and each run gives a different image.

//================================================//
// ========= | PRELOAD + INITIAL VARS | ========= // 
//================================================//

//-------------- | Parameters

let dropInfo = {};
let torusInfo = {};
let circleInfo = {};
let domeInfo = {};

//-------------- | color palette

var pMagenta = '#D037F5';
var pDarkBlue = '#0A1045';
var pBrightBlue = '#003ACC';
var pLightPurple = '#8098FF';
var pGreen = '#0AF007';
var pWhite = '#fff';

//-------------- | Art colors

var bgFill = pDarkBlue;
var ambiFill = pLightPurple;
circleInfo.fill = pMagenta;
torusInfo.fill = pLightPurple;

var pointR = 10;
var pointG = 240;
var pointB = 7;

var point2R = 255;
var point2G = 255;
var point2B = 255;

//-------------- | fonts

//-------------- | preload building blocks

function preload() {
  dome = loadModel('https://cdn.glitch.me/4976d32d-fd94-4dd4-8b88-2150e673b6a1%2Fdome.obj', true);
	
	hollowCone = loadModel('https://cdn.glitch.me/4976d32d-fd94-4dd4-8b88-2150e673b6a1%2Fcone.obj', true);
	
	drop = loadModel('https://cdn.glitch.me/4976d32d-fd94-4dd4-8b88-2150e673b6a1%2Fdrop.obj', true);
	
	smallTorus = loadModel('https://cdn.glitch.me/4976d32d-fd94-4dd4-8b88-2150e673b6a1%2FsmallTorus.obj', true);
	
	midTorus = loadModel('https://cdn.glitch.me/4976d32d-fd94-4dd4-8b88-2150e673b6a1%2FmidTorus.obj', true);
	
	bigTorus = loadModel('https://cdn.glitch.me/4976d32d-fd94-4dd4-8b88-2150e673b6a1%2FbigTorus.obj', true);
	
		hollowBox = loadModel('https://cdn.glitch.me/4976d32d-fd94-4dd4-8b88-2150e673b6a1%2Fhollowbox.obj', true);
}

//================================================//
// ========== | SETUP + GENERATE ONCE | ========= // 
//================================================//

function setup() {
	createCanvas(500, 500, WEBGL);
  angleMode(DEGREES);
	

}


//================================================//
// ============= | GENERATE CONTINOUS | ========= // 
//================================================//

function draw() {
scale(0.5);
	  // circle parameters
	circleInfo.X = random(-100,100);
	circleInfo.Y = random(-100,100);
	circleInfo.rad = random(10,25);
	circleInfo.scale = random(1,2);
	
	// torus parameters
	torusInfo.X = 0;
	torusInfo.Y = 0;	
	torusInfo.rad = 250;
	torusInfo.tube = 5;

	
	// ------------- | initial style & light
	background(bgFill);
	
	// orbitControl(4);
	ambientLight(ambiFill);
		pointLight(pointR, pointG, pointB, 1000, 1000, 1000);
	pointLight(point2R, point2G, point2B, -1000, 1000, 1000);
	
	// ------------- | grid & guides - comment on & off
	// drawAxis();
	// drawGrid();
// ================ | DRAWING | ================= //
	

// ------------------------- | circle

	push();
	translate(circleInfo.X,circleInfo.Y,0);
	scale(circleInfo.scale);
	fill(circleInfo.fill);
  noStroke();
	sphere(circleInfo.rad);
	pop();
	
// ------------------------- | torus

	push();
	translate(torusInfo.X,torusInfo.Y,0);
	fill(torusInfo.fill);
	noStroke();
  torus(torusInfo.rad, torusInfo.tube, 30, 10);
	pop();

	
}



//================================================//
// ================ | BASE SHAPES | ============= // 
//================================================//
// setting the base shapes to the ideal parameters after loading & before using them

function domeObj(){
		push();
	  noStroke();
		rotateX(-90);
		rotateZ(-91); // to align it perfectly
		translate(-50, 0,0);
		model(dome);
		pop();
}



function dropObj(){
	push();
	noStroke();
	rotateZ(180);
	translate(0,-100,0);
	model(drop);
	pop();
}

function coneObj(){
	push();
	noStroke();
	translate(-7.5,0,-61);//to align
	rotateY(7);//to fix the crooked position
	rotateY(180); // to flip 
	model(hollowCone);
	pop();
}


function sTorusObj(){
	push();
	noStroke();
	rotateX(90);
	model(smallTorus);
	pop();
}

function mTorusObj(){
	push();
	noStroke();
	rotateX(90);
	model(midTorus);
	pop();
}

function boxObj(){
	push();
	noStroke();
	rotateX(180);
	translate(0,-100,0)
	model(hollowBox);
	pop();
}



//================================================//
// =============== | NOTES | ============ // 
//================================================//

// -------------- | Basic stuff I'd want to do with a model

	// push();
	// rotateX();
	// rotateZ();
	// translate();
	// fill(pWhite);
	// domeObj()
	// pop();



	//  rotateZ(map(mouseX, 0, windowWidth, -(Zrot/2),Zrot/2));
	// Xrot, Yrot, Zrot is a degree, preferably not more than 55

  //	translate(0,map(mouseX, 0, windowWidth, 0,Ytran),0);
	// Ytran is a distance, scl is scale 



//================================================//
// =============== | GUIDES & GRID | ============ // 
//================================================//



function drawAxis() {
	push();
	strokeWeight(3);
	stroke(255, 0, 0);
	line(0, 0, 0, 100, 0, 0);
	stroke(0, 255, 0);
	line(0, 0, 0, 0, 100, 0);
	stroke(0, 0, 255);
	line(0, 0, 0, 0, 0, 100);
	pop();
}

function drawGrid() {
	let sz = 1000;
	let num = 10;
	push();
	translate(-sz / 2, -sz / 2, 0);
	stroke(200);
	for (var i = 0; i < num + 1; i++) {
		line((i * sz) / num, 0, 0, (i * sz) / num, sz, 0);
		line(0, (i * sz) / num, 0, sz, (i * sz) / num, 0);
	}
	pop();
}

              
            
!
999px

Console