How To Create Collaborative Digital Art using #JavaScript

loop / rotate / translate

In this tutorial, we’ll explore the process of building a digital drawing canvas where artists can simultaneously collaborate.

 

Complete Code Sample

To explore building a collaborative digital art canvas, we’ll start with a very simple example. This code is based on the p5 processing js framework. You can download this sample code and other 3D art examples from my github repo. In general, this javascript code needs to setup a connection to my Firebase database, setup a list of colors, setup code to react to drawing events, and give the artist a way to contribute drawing events to the system. In the rest of this blog post, we’ll break this code down.


var database;
var colorOptions;

function setup() {
createCanvas(1024, 768);

// Initialize Firebase
var config = {
apiKey: "...",
authDomain: "changeme.firebaseapp.com",
databaseURL: "https://changeme.firebaseio.com",
storageBucket: "",
};
firebase.initializeApp(config);
database = firebase.database();

//make a list of colors in an array....
colorOptions = new Array();
colorOptions[0] = "#faa916"
colorOptions[1] = "#6d676e"
colorOptions[2] = "#1b1b1e"
colorOptions[3] = "#96031a"

//pull points from firebase and draw them...
var pointRef = firebase.database().ref('points');
pointRef.on('child_added', function(data) {

// So... a new point has been added. Get the data.
var aPoint = data.val();

//set the color based on point
fill(aPoint.color);

//draw the point
ellipse(aPoint.x, aPoint.y, 10, 10);
});

}

function draw() {
if (mouseIsPressed) {
//get current time
var date = new Date();
var m = date.getMinutes();

//select a color option based on the minutes
var i = m % 4;

// make a point capturing location(x,y) and color
var aPoint = {}
aPoint.x = mouseX;
aPoint.y = mouseY;
aPoint.color = colorOptions[i];

//add point to firebase ...
database.ref("points").push(aPoint);
}
}

Setting up our drawing space and Firebase connection

P5 is an easy 2D JavaScript framework for drawing stuff. In the “setup” function, p5 enables programmers to establish their workspace. In our case, we have 3 jobs: create a canvas, connect to our Firebase database, and tell the system how it should handle drawing events. In the following code, we create a drawing surface called a canvas that’s 1024 pixels by 768 pixels. The rest of the code establishes a connection to my firebase instance. Firebase is a real-time database in the Google family of products. From a JavaScript programmers point of view, it provides an easy way to capture data and push that new data to other users of your app or experience. In our case, the moment that one user starts drawing, all other users will see the result instantly with no refreshing. Experienced programmers will also notice that you don’t insert data using SQL, you just ask the system to store JSON.

Make sure to learn more about Google Firebase at https://firebase.google.com/. In my case, I established a database instance that’s writable to the public. This works great for public wikis or collaborative public art. You can also secure your database instance with authentication and login methods. Check out their documentation for details.


createCanvas(1024, 768);

// Initialize Firebase
var config = {
apiKey: "...",
authDomain: "changeme.firebaseapp.com",
databaseURL: "https://changeme.firebaseio.com",
storageBucket: "",
};
firebase.initializeApp(config);
database = firebase.database();

In this tutorial, let’s change the drawing colors of our collaborative canvas with time. In this case, we’ll provide 4 options in the code below.


colorOptions = new Array();
colorOptions[0] = "#faa916"
colorOptions[1] = "#6d676e"
colorOptions[2] = "#1b1b1e"
colorOptions[3] = "#96031a"

Let’s draw something!

In the following code, we get the browser to listen for changes from our Firebase database. When changes occur to our points list, we draw stuff. When a child is added, we grab a single point, set the fill color, and draw a small circle at the location.


var pointRef = firebase.database().ref('points');
pointRef.on('child_added', function(data) {
// So... a new point has been added. Get the data.
var aPoint = data.val();

//set the color based on point
fill(aPoint.color);

//draw the point
ellipse(aPoint.x, aPoint.y, 10, 10);
});

How do users draw?

For our simple collaborative canvas, artists draw on the canvas by simply clicking and dragging their mouse. In the following code, we detect mouse clicks, the location of the mouse click, and pick a color based on time.


function draw() {
if (mouseIsPressed) {
//get current time
var date = new Date();
var m = date.getMinutes();

//select a color option based on the minutes
var i = m % 4;

// make a point capturing location(x,y) and color
var aPoint = {}
aPoint.x = mouseX;
aPoint.y = mouseY;
aPoint.color = colorOptions[i];

//add point to firebase ...
database.ref("points").push(aPoint);
}
}

If you enjoyed this tutorial, you’re going to LOVE the following art and code festival we’re organizing tomorrow. It’s an opportunity for artists, designers, and coders in Middle, GA to connect and invent new crowd-sourced art experiences. It’s going to be a blast! Macon GDG has organized the content and teaching to be accessible to artists and designers interested in growing their coding skills. We’ll be building amazing 3D collaborative art experiences like the following:

This prototype piece was presented by Dr. Allen during our last Open Make night at SparkMacon Makerspace.

I want to give a shout out to our friends at Google Developer Group of Macon and Dr. Robert Allen from Mercer. It was a blast brainstorming and implementing Macon’s first Google DevFest together

  • Google DevFest: A festival for software developers, artists, and creative thinkers.
    Explore CrowdSourced Art using tools like ThreeJS and Firebase.com, an amazing realtime database framework.
  • Learn more at http://devfest.cs.mercer.edu/
  • When: October 22, 2016 – 9 a.m. – 5 p.m.
  • Where: Mercer University Science and Engineering Building

5 Powerful JavaScript Frameworks for 2D and 3D Graphics #javascript

three js

  • https://threejs.org/ – A 3D graphics library for HTML and JavaScript. Make sure to check out sample code here and at https://stemkoski.github.io/Three.js/.   Writing Google Cardboard apps?  Check out https://vr.chromeexperiments.com/.  This link has template code for building a Google Cardboard app using JavaScript.
  • http://p5js.org/ – “…a JavaScript library that starts with the original goal of Processing, to make coding accessible for artists, designers, educators, and beginners, and reinterprets this for today’s web.” This library looks like a great framework for getting started in 2D graphics.  Khan Academy uses a similar framework in their drawing tutorials to computer science.
  • http://www.babylonjs.com/ – 3D graphics library that abstracts the complexities of WebGL. They seem to have a focus of making it simple to get started while making it possible to build complex scenes. For a detailed review of this framework, check this interview from Scott Hanselman.  ( Check out the blog post too )
  • http://paperjs.org/ – “Paper.js is an open source vector graphics scripting framework that runs on top of the HTML5 Canvas. It offers a clean Scene Graph / Document Object Model and a lot of powerful functionality to create and work with vector graphics and bezier curves, all neatly wrapped up in a well designed, consistent and clean programming interface.”
  • http://fabricjs.com/ – Another cool vector graphics library.

 

What’s your favorite JS library for computer graphics?   Let us know in the comments!

 

Make sure Macon’s Google DevFest!

  • Google DevFest: A festival for software developers, artists, and creative thinkers.
    Explore CrowdSourced Art using tools like ThreeJS and Firebase.com, an amazing realtime database framework.
  • Learn more at http://devfest.cs.mercer.edu/
  • When: October 22, 2016 – 9 a.m. – 5 p.m.
  • Where: Mercer University Science and Engineering Building

 

Top Stories

Inspire Curiosity and Creativity in your Young Maker with SparkMacon’s Robotics Workshop

mBot

Through making and tinkering, students learn using their hands, grow their creativity, and become more curious about their world and testing the limits of what is possible. InspiredToEducate.NET and SparkMacon Makerspace have designed a series of workshops to connect students with the essential technology skills of inventing using computer programming, digital fabrication, and robotics.    

Parents and kids are invited to take this workshop together.  It’s a great family activity!

Robotics: This workshop makes a great gift for the young makers in your life to inspire their love of learning and practice their creative skills.   During this hands-on workshop, students will have the opportunity to build robots from scratch using the mBot kit.   Students will love customizing their mBot using puzzle based programming and the easy to assemble construction experience.   You can program and control the robot using a PC, IPad, or mobile phone.    Students take home their mbot to continue the tinkering fun at home.     

Student registration includes a complete mBot robotics kit from Makeblock.cc.

http://www.makeblock.cc/mbot/

  • Workshop length: 3 hours
  • Cost: $95
  • Workshop cost includes a MakeBlock mBlock kit the students take home.
  • This class serves students from age 9 or older.
  • Interested in registering the workshop?  Please register here.
  • Dates
    • Oct 8th from 1pm to 4pm
    • Dec 3rd from 1pm to 4pm

Location for workshops:

Our robotics workshop will be located at SparkMacon Makerspace.

557 Cherry Street, Macon, GA

Funds from these Maker Skills workshops help support the operation of SparkMacon Makerspace.  Parking and location information can be found here.

Hope to see you there!

 

Top Stories

 

MakerFaire Projects To Inspire You

Atlanta Maker Faire 2016

SparkMacon Makerspace invited local makers for an amazing road trip to Atlanta Maker Faire in Decatur, GA on Oct 1st! Maker Faire is a gathering of fascinating, curious people who enjoy learning and who love sharing what they can do. From engineers to artists to scientists to crafters, Maker Faire is a venue to for these “makers” to show hobbies, experiments, projects. 

In organizing this road trip, I hoped that we could grow community and relationships in our SparkMacon community and inspire new ideas, business concepts, and project based learning experiences.  We had a great time!  In this blog post, I wanted to share a few stories and projects we got to observe.

My little boy enjoyed learning how to cut styrofoam pieces using a hot wire cutter from Geekspace Gwinnet.   Using this tool, makers can cut styrofoam to craft structures for cosplay and other projects.   Geekspace did a great job presenting their work ranging from amazing robots, cosplay, and kids activities.

I really appreciate the team from Geekspace Gwinnet sharing some of their experiences in growing and sustaining their makerspace and community too.    The conversation reminded me of the importance of growing, empowering, and serving our maker community.

ATL Maker Faire 2

I know that many of our members enjoyed seeing their first drone race.  Drone pilots fly their creations from a first person perspective through a track on a field.  You can see a team named Cyclone FPV running the course here.

 

I want to thank our SparkMacon road trip team on going to this trip with me.  Creativity is always contagious.   I always enjoy sharing Maker Faire with friends and family.    I want to give a special shout out to my brother Francis Rosario and Ronda Teel who helped take pictures to build the video below.  Hope you enjoy it.

 

Make sure to check out the following link to learn more about Atlanta Maker Faire presenters.

Top Stories

 

Music credit: http://freemusicarchive.org/music/Doctor_Turtle/none_given_2414/peak_beak