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

Auto Save

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

              
                <div class="form">
	<p>Search for a keyword in recent posts from <br /><span id="site-url"></span></p>
	<input type="text" name="keyword" id="myText" value="" />
	<button onclick="checker()">Search</button>
</div>
              
            
!

CSS

              
                body {
	margin: 0;
	font-family: sans-serif;
}

p {
	color: rgba(255,255,255,0.65);
	letter-spacing: 1px;
	font-size: 18px;
	margin-top: 0;
}

.form {
	position: absolute;
	top: 40px;
	left: 40px;
	font-size: 18px;
}

input[type="text"] {
	padding: 7px 10px;
	font-size: 18px;
	display: inline-block;
	height: 20px;
	border: none;
	border-radius: 3px 0 0 3px;
	position: relative;
	top: 0;
}

button {
	font-size: 14px;
	text-transform: uppercase;
	padding: 9px 10px;
	position: relative;
	top: -1px;
	border: none;
	background: #fff;
	margin-left: -5px;
	border-left: 1px solid #ccc;
	border-radius: 0 3px 3px 0;
	display: inline-block;
	height: 34px;
	
	&:hover {
		box-shadow: 0 0 4px rgba(0,0,0,0.4);
		cursor: pointer;
	}
}
              
            
!

JS

              
                // Global variables.
var json;
var url = "https://westmichigan.aiga.org/wp-json/wp/v2/posts?per_page=10";
var keyword;
var words = [];

// Assigning JSON to a variable and preloading all of it up front.
function preload() {
	json = loadJSON(url);
}

// Checking form for keyword and storing it in HTML5 local storage.
function checker() {
	keyword = document.getElementById("myText").value;
	console.log(keyword);
	localStorage.setItem("myText", keyword);
	location.reload(true)
}

// p5.js setup function.
function setup() {
	document.getElementById('site-url').innerHTML = url;
	createCanvas(windowWidth, windowHeight);
	background(32,37,41);
	for (var i = 0; i < json.length; i++) {
		var j = json[i];
		words[i] = new Word(j);
	}
	
	// Showing the entered keyword in the input field.
	document.getElementById("myText").value = localStorage.getItem("myText");
	noStroke();
}

// p5.js draw function.
function draw() {
	// Assigning the number of objects to a variable called 'count'.
	var count = Object.keys(json).length;
	var diameter = 45;
	
	// Looping through the JSON posts.
	for(var i = 0; i <= count; i++) {
		
		// Assigning post content to a variable.
		var content = json[i].content.rendered;
		
		// Searching content of post for specified string.
		// var word_count = (content.match(/diversity/g) || []).length; // This matches a string
		
		// Recalling the value from local storage and counting how many times it appears in each post.
		keyword = localStorage.getItem("myText");
		var word = new RegExp(keyword, 'g');
		var word_count = (content.match(word) || []).length;
		
		// Remapping the x_axis of ellipses
		var x_axis = map(i, 0, count-1, 0 + diameter, width - diameter);
		
		// Display a black ellipse for every post and color posts with specified word blue.
		if (content.indexOf(keyword) > -1) {
			fill(88,200,221); // Blue
		} else {
			fill(0,0,0); 
		}
		noStroke();
		ellipse(x_axis, height/2, diameter + word_count * 10, diameter + word_count * 10);
		
		// Displaying number of times a word is used in post.
		if (content.indexOf(keyword) > -1) {
			fill(255,255,255);
		} else {
			fill(255,255,255, 80);
		}
		textSize(19);
		textAlign(CENTER, CENTER);
		text(word_count, x_axis, height/2);
	}
}

              
            
!
999px

Console