top of page
  • Writer's pictureRob George

Week 5: Random + Continued Winter Translator

Updated: Dec 10, 2020

Task 1: Random Horizontal Lines

Made horizontal lines have random y points

//Week 5: Task 1: Random Lines


void setup(){

size(600,600);

}


void draw(){

background(0);

//random lines

stroke(255);

strokeWeight(3);

line(0, random(600), width, random(600));

}


Task 2: Random Bouncing Ball

Made a ball randomly bounce around the screen as well as change size and color.

//Week 5: Task 2: Bouncing Ball


float circleX=0;

float xSpeed=10;

float circleY=0;

float ySpeed=20;

float diam=20;


void setup() {

size(600,600);

}


void draw(){

background(255);

//the circle

ellipse(circleX, circleY, diam,diam);

//bouncing

//circleX

if (circleX>width || circleX<0){

noStroke();

fill(random(255),random(255),random(255));

diam=random(20,50);

xSpeed=-xSpeed;

}

//circleY

if (circleY>height || circleY<0){

noStroke();

fill(random(255),random(255),random(255));

diam=random(20,50);

ySpeed=-ySpeed;

}

//Logic

circleX=circleX+xSpeed;

circleY=circleY+ySpeed;

}


Assignment 1: Winter Translator

Continued working on the translator and added the other buttons. Week 6 will have the final version of this translator.

//Winter Translator


//Variables for the buttons

//Diameter

int diam=240;


//English Button

int xENGL=150;

int yENGL=800;


//Spanish Button

int xSPAN=450;

int ySPAN=800;


//Italian Button

int xITAL=750;

int yITAL=800;


//French Button

int xFREN=1050;

int yFREN=800;


//Greek Button

int xGREK=1350;

int yGREK=800;


//CLEAR Button

int xCLR=750;

int yCLR=615;

int wCLR=110;

int hCLR=60;


//Booleans for all buttons

boolean btENGL=false;

boolean btSPAN=false;

boolean btITAL=false;

boolean btFREN=false;

boolean btGREK=false;


//Making the header translate too

boolean header=true;


void setup() {

size(1500, 1000);

}


void draw() {

background(7, 18, 44);


//Word Display Snowball

noStroke();

fill(255);

ellipse(width/2, 0, 1100, 1100);


//Initial Header text

if (header) {

fill(7, 18, 44);

textSize(90);

textAlign(CENTER);

text("Winter Translator", width/2, 140);

}


//Button Shape

fill(255);

noStroke();

ellipse(xENGL, yENGL, diam, diam);

ellipse(xSPAN, ySPAN, diam, diam);

ellipse(xITAL, yITAL, diam, diam);

ellipse(xFREN, yFREN, diam, diam);

ellipse(xGREK, yGREK, diam, diam);


//Button Text

fill(7, 18, 44);

textSize(40);

textAlign(CENTER);

text("English", xENGL, 810);

text("Spanish", xSPAN, 810);

text("Italian", xITAL, 810);

text("French", xFREN, 810);

text("Greek", xGREK, 810);


//booleans


if (btENGL) {

fill(73, 20, 159);

noStroke();

ellipse(xENGL, yENGL, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("English", xENGL, 810);

//content

fill(73, 20, 159);

textSize(70);

textAlign(CENTER);

text("I love snow!", width/2, 340);

//Header text

fill(7, 18, 44);

textSize(90);

textAlign(CENTER);

text("Winter Translator", width/2, 140);

} else if (btSPAN) {

fill(0, 175, 76);

noStroke();

ellipse(xSPAN, ySPAN, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("Spanish", xSPAN, 810);

//content

fill(0, 175, 76);

textSize(70);

textAlign(CENTER);

text("Me encanta la nieve!", width/2, 340);

//Header text

fill(7, 18, 44);

textSize(90);

textAlign(CENTER);

text("Traductor de invierno", width/2, 140);

} else if (btITAL) {

fill(0, 170, 135);

noStroke();

ellipse(xITAL, yITAL, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("Italian", xITAL, 810);

//content

fill(0, 170, 135);

textSize(70);

textAlign(CENTER);

text("Amo la neve!", width/2, 340);

//Header text

fill(7, 18, 44);

textSize(90);

textAlign(CENTER);

text("Traduttore Invernale", width/2, 140);

} else if (btFREN) {

fill(0, 134, 207);

noStroke();

ellipse(xFREN, yFREN, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("French", xFREN, 810);

//content

fill(0, 134, 207);

textSize(70);

textAlign(CENTER);

text("J'aime la neige!", width/2, 340);

//Header text

fill(7, 18, 44);

textSize(90);

textAlign(CENTER);

text("L'Hiver Traducteur", width/2, 140);

} else if (btGREK) {

fill(0, 93, 144);

noStroke();

ellipse(xGREK, yGREK, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("Greek", xGREK, 810);

//content

fill(0, 93, 144);

textSize(70);

textAlign(CENTER);

text("Λατρεύω το χιόνι!", width/2, 340);

//Header text

fill(7, 18, 44);

textSize(80);

textAlign(CENTER);

text("Χειμώνας Μεταφραστής", width/2, 140);

}


println(mouseX, mouseY);

}


void mousePressed() {


//when mouse pressed on English button


if (dist(xENGL, yENGL, mouseX, mouseY)<diam/2) {

btENGL=true;

btSPAN=false;

btITAL=false;

btFREN=false;

btGREK=false;

header=false;

}


//when mouse pressed on Spanish button


if (dist(xSPAN, ySPAN, mouseX, mouseY)<diam/2) {

btENGL=false;

btSPAN=true;

btITAL=false;

btFREN=false;

btGREK=false;

header=false;

}


//when mouse pressed on Spanish button


if (dist(xITAL, yITAL, mouseX, mouseY)<diam/2) {

btENGL=false;

btSPAN=false;

btITAL=true;

btFREN=false;

btGREK=false;

header=false;

}


//when mouse pressed on Spanish button


if (dist(xFREN, yFREN, mouseX, mouseY)<diam/2) {

btENGL=false;

btSPAN=false;

btITAL=false;

btFREN=true;

btGREK=false;

header=false;

}


//when mouse pressed on Spanish button


if (dist(xGREK, yGREK, mouseX, mouseY)<diam/2) {

btENGL=false;

btSPAN=false;

btITAL=false;

btFREN=false;

btGREK=true;

header=false;

}

}


< Return to Coding Page

2 views0 comments
bottom of page