M1D25 – ITP1

+ will let the console log add the value to the string

console.log("the spots x is" + spotX);

Debug Assignment

var robot_x;
var robot_y;

function setup()
{
	//create a canvas for the robot
	createCanvas(1500, 1500);
	robot_x = 320; //I changed this from -320 //changed this to match the variables
	robot_y = 100;
}

function draw()
{
	background(255);
	strokeWeight(6);

	//robots head
	fill(200);
	rect(robot_x, robot_y, 300, 300, 20);


	//robots antenna
	fill(250, 250, 0);
	ellipse(robot_x + 150, robot_y - 30, 60, 60);

	fill(200, 0, 200);
	rect(robot_x + 110, robot_y - 20, 80, 30);


	//robots eyes
	fill(255);

	ellipse(robot_x + 75, robot_y + 100, 80, 80);//corrected spelling of ellipse
	point(robot_x + 75, robot_y + 100);

	ellipse(robot_x + 225, robot_y + 100, 80, 80);
	point(robot_x + 225, robot_y + 100);


	//robots nose
	fill(255, 0, 0);
	triangle(robot_x + 150, robot_y + 120, //added + operator
		robot_x + 100, robot_y + 200,
		robot_x + 200, robot_y + 200);


	//robots ears
	rect(robot_x - 20, robot_y + 80, 30, 100);

	rect(robot_x + 290, robot_y + 80, 30, 100);

	//robots mouth
	noFill();
	beginShape();

	vertex(robot_x + 75, robot_y + 240);
	vertex(robot_x + 100, robot_y + 270);
	vertex(robot_x + 125, robot_y + 240);
	vertex(robot_x + 150, robot_y + 270);
	vertex(robot_x + 175, robot_y + 240);
	vertex(robot_x + 200, robot_y + 270);
	vertex(robot_x + 225, robot_y + 240);

	endShape();

	//animate the robot
	robot_x += 1; //changed this to robot_x to make the robot move from left to right
}

function keyPressed()
{
	robot_x = -320;
}

https://d.pr/i/opXs3L/e9fpGoEZut

The Elegant Coder

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” – Antoine Saint-Exupery

  1. Elegant code is as simple as it can be.
  2. Readable:
    • Well named variables
    • Good use of objects
    • Logical organization
    • Explanatory comments
  3. Avoid redundancy
    • don’t comment out unused code
    • unused variables
    • draw images that cannot be seen
  4. Follows conventions
    • align brackets
    • indent code
    • when lines go very long, break things into separate lines
    • use comments that have to do some fixed means to plan their work
This entry was posted in Study Notes and tagged , , , . Bookmark the permalink.

Leave a Reply