Skip to content →

icm / week02

This week we learned about some new elements, but mostly about a very important one widely used on the javascript : variables. Name it, initialize it (note to myself: always on setup!!), use it and vary it.
The homework was to gather with one of our fellow colleagues and do our homework, wether on one project or separate projects. I sat with Jason to work and it was really good to share the experience of learning js with someone doing the same thing.
We started talking about what the homework was about, as well as what we had in our minds. We helped each other while doing our homework. For this assignment, I decided I wanted to do some kind of visual abstraction playing with the mouse position, randomness.

So what I did was a drawing canvas in which the color of the stroke would be randomly chosen when I started running the sketch. The stroke (line) size would randomly vary as well as change the random range once you pressed the mouse – it would increase until a certain value and then go back to the initial range. And the stroke, like any drawing canvas, will draw according to the mouse position.

I had some trouble at the beginning to understand the limitations of size i.e. what values would make the sketch only draw within half of the canvas, so I asked Jason some help and it was good to ask him because I really had to read my code and understand what I had coded, so that I could explain to him in proper English. This helped me to understand where I got it wrong and how to fix it. Here’s my final result:



 var pointY1 = 30;
var pointX2 = 30;
var redColor;
var blueColor;
var random1 = 10;
var random2 = 30;

function setup() {
  redColor = random(0,255);
  blueColor = random(0,255);
  print("red ="+redColor);
  print("blue ="+blueColor);

function draw() {
  pointY1 = random(random1,random2);
  pointX2 = random(random1,random2);
function mousePressed(){
    random1 = random1 + 50;
    random2 = random2 - 50;
    if(random1 >=280){
      random1 = random1 = 50;
    if(random2 <=0){
      random2 = random2 + 50;

The best thing is to go, test, review the code, update and test it again. My final result is an experiment but I really like the idea of playing with random numbers - I think Iā€™d like to explore it further on the next exercises.

Published in fall 2015 icm


Leave a Reply

Your email address will not be published. Required fields are marked *