• Rob George

Week 7: For Loops + Absolute Value + 25 Dots Parts B,C + Final Translator

Updated: Dec 10, 2020

Task 1: Repeated Circles

A practice using for loops to create repeated circles.




//Task 1


void setup(){

size(400,400);

background(255);

}


void draw(){

for(float diam=0; diam<width; diam=diam+10){

noFill();

ellipse(width/2,height/2,diam,diam);

}

}


Task 2: Animated Repeated Circles

The next task was to use the same for loops but animate it. Every time the program is opened the color changes.


//Task 2


float endDiam=0;

color c;


void setup() {

size(400, 400);

frameRate(200);

c=color(random(255),random(255),random(255));

}


void draw() {


background(255);

for (float diam=0; diam<endDiam; diam=diam+10) {

noFill();

stroke(c);

ellipse(width/2, height/2, diam, diam);

}

if (endDiam>height) {

endDiam=0;

}

endDiam=endDiam+1;

}


Task 3: Gradient Rectangles

This last task was to create a gradient within shapes using abs().

//Task 3


float co;


void setup() {

size(300, 200);

}


void draw() {

background(255);

for (float x=0; x<width; x=x+10) {

fill(co);

co=abs(255-x);

rect(x, 0, x, height);

}

}


Assignment 1: 25 Dots Part B

Continuing with the 25 dots, this assignment required me to create a gradient within the dots on the x axis. Light (left) to dark (right). For this I used "map."

//25 Dots Part B: X Axis Gradient


float c;

float y=120;

float x=120;

float diam=50;


void setup() {

size(720, 720);

}


void draw() {

background(255);

noStroke();

fill(0);


//25 Dots


for (float x=120; x<width; x=x+120) {

fill(c);

c=map(x, width, 0, 0, 255); //figured "x" would be the direction the gradient

ellipse(x, y, diam, diam);

for (float y=120; y<height; y=y+120) {

fill(c);

c=map(x, width, 0, 0, 255); //Had to repeat the c=map down here

ellipse(x, y, diam, diam);

}

}


//MATH:

//To Find x and y:

//1) 5/6 = 0.83 2) 720*0.83 = 597.6 (rounded up to 600) 3) 720-600=120

}


Assignment 2: 25 Dots Part C

This part of the project is just getting a vertical gradient. Same concept as the X axis except I changed it to be for the Y axis. Top (light) to bottom (dark).

//25 Dots Part C : Y axis Gradient


float c;

float y=120;

float x=120;

float diam=50;


void setup() {

size(720, 720);

}


void draw() {

background(255);

noStroke();

fill(0);


//25 Dots


for (float y=120; y<height; y=y+120) { //Had to move the y for loop on top

fill(c);

c=map(y, height, 0, 0, 255); //figured "y" would be the direction

ellipse(x, y, diam, diam);

for (float x=120; x<width; x=x+120) { //"x" for loop is here now

fill(c);

c=map(y, height, 0, 0, 255); //Had to repeat the c=map down here

ellipse(x, y, diam, diam);

}

}


//MATH:

//To Find x and y:

//1) 5/6 = 0.83 2) 720*0.83 = 597.6 (rounded up to 600) 3) 720-600=120

}


Assignment 3: Finalized Translator Program

For my finalized winter translator I added clouds, changed the last button from Greek to Swedish to make the winter effects more logical based on global location, the button colors were changed to a scale from a warmer green to a cooler blue, and finally I added a clear button.

//Final Winter Translator


//Variables


int diam=240; //button diameter


//Buttons

int xENGL=150;

int yENGL=800;

int xSPAN=450;

int ySPAN=800;

int xITAL=750;

int yITAL=800;

int xFREN=1050;

int yFREN=800;

int xSWED=1350; //Changed to Swedish

int ySWED=800; //Changed to Swedish


//Button Booleans

boolean header=true;

boolean btClear=true;

boolean btENGL=false;

boolean btSPAN=false;

boolean btITAL=false;

boolean btFREN=false;

boolean btSWED=false;


//Icicles

//1

float iceX1=170;

float iceY1=130;

float iceX1_2=210;

float iceY1_2=240;

float iceX1_3=180;

float iceY1_3=550;

//2

float iceX2=250;

float iceY2=140;

float iceX2_2=300;

float iceY2_2=340;

float iceX2_3=275;

float iceY2_3=725;

//3

float iceX3=1185;

float iceY3=140;

float iceX3_2=1250;

float iceY3_2=270;

float iceX3_3=1205;

float iceY3_3=840;

//4

float iceX4=570;

float iceY4=500;

float iceX4_2=600;

float iceY4_2=550;

float iceX4_3=585;

float iceY4_3=675;


//Loads

PImage moderateSnow;

PImage heavySnow;

PImage cloud;

PFont font1; //Header

PFont font2; //Word

PFont font3; //Button Text


void setup() {

size(1500, 1000);


font1=loadFont("SegoeUIBlack-50.vlw"); //header font

font2=loadFont("SegoeUI-Semibold-50.vlw"); //Word font

font3=loadFont("SegoeUI-Semibold-50.vlw"); //Button font


moderateSnow=loadImage("Moderate Snow@300x.png"); //Moderate Button Snow

imageMode(CENTER);

moderateSnow.resize(0, 60);

heavySnow=loadImage("Heavy Snow@300x.png"); //Heavy Button Snow

imageMode(CENTER);

heavySnow.resize(0, 100);

cloud=loadImage("Cloud.png");

cloud.resize(700, 0);

}


void draw() {


//Background

background(7, 18, 44);


//Cloud

image(cloud, 100, 20);

image(cloud, 1400, 20);


//Word Display Snowball

float diam2=1200; //Giant Display Snowball

stroke(7, 18, 44);

strokeWeight(10);

fill(255);

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


//Clear Button

if (btClear) {

fill(255);

noStroke();

rectMode(CENTER);

rect(width/2, 500, 170, 70);

textFont(font2, 40);

fill(7, 18, 44);

textAlign(CENTER);

text("Clear", width/2, 510);

}

//Clear Button Rollover

if (mouseX>665 && mouseX<835 && mouseY<570 && mouseY>430) {

noStroke();

fill(7, 18, 44);

rectMode(CENTER);

rect(width/2, 500, 170, 70);

textFont(font2, 40);

fill(255);

textAlign(CENTER);

text("Clear", width/2, 510);

}


//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(xSWED, ySWED, diam, diam);

//Button Text

textFont(font3, 40);

fill(7, 18, 44);

textAlign(CENTER);

text("English", xENGL, 810);

text("Spanish", xSPAN, 810);

text("Italian", xITAL, 810);

text("French", xFREN, 810);

text("Swedish", xSWED, 810);


//TRANSLATIONS


if (btENGL) { //English

fill(37, 193, 119);

noStroke();

ellipse(xENGL, yENGL, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("English", xENGL, 810);

//content

fill(37, 193, 119);

textFont(font2, 80);

textAlign(CENTER);

text("Winter", width/2, 300);

//Header text

fill(37, 193, 119);

textFont(font1, 60);

textAlign(CENTER);

text("My Favorite Season", width/2, 100);

} else if (btSPAN) { //Spanish

fill(37, 193, 153);

noStroke();

ellipse(xSPAN, ySPAN, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("Español", xSPAN, 810);

//content

fill(37, 193, 153);

textFont(font2, 80);

textAlign(CENTER);

text("Invierno", width/2, 300);

//ICICLE //ICICLE

fill(255);

noStroke();

triangle(iceX1, iceY1, iceX1_2, iceY1_2, iceX1_3, iceY1_3);

//Header text

fill(37, 193, 153);

textFont(font1, 60);

textAlign(CENTER);

text("Mi Estación Favorita", width/2, 100);

} else if (btITAL) { //Italian

fill(0, 169, 165);

noStroke();

ellipse(xITAL, yITAL, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("Italiano", xITAL, 810);

//content

fill(0, 169, 165);

textFont(font2, 80);

textAlign(CENTER);

text("Inverno", width/2, 300);

//ICICLES //ICICLES

fill(255);

noStroke();

triangle(iceX1, iceY1, iceX1_2, iceY1_2, iceX1_3, iceY1_3);

triangle(iceX2, iceY2, iceX2_2, iceY2_2, iceX2_3, iceY2_3);

//SNOWING //Light Snowfall

frameRate(2);

noStroke();

fill(255);

ellipse(random(width), random(height), 30, 30);

ellipse(random(width), random(height), 20, 20);

ellipse(random(width), random(height), 40, 40);

//Header text

fill(0, 169, 165);

textFont(font1, 60);

textAlign(CENTER);

text("La Mia Stagione Preferita", width/2, 100);

} else if (btFREN) { //French

fill(7, 144, 180);

noStroke();

ellipse(xFREN, yFREN, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("Français", xFREN, 810);

//content

fill(7, 144, 180);

textFont(font2, 80);

textAlign(CENTER);

text("Hiver", width/2, 300);

//ICICLES //ICICLES

fill(255);

noStroke();

triangle(iceX1, iceY1, iceX1_2, iceY1_2, iceX1_3, iceY1_3);

triangle(iceX2, iceY2, iceX2_2, iceY2_2, iceX2_3, iceY2_3);

triangle(iceX3, iceY3, iceX3_2, iceY3_2, iceX3_3, iceY3_3);

//SNOWING //Moderate Snowfall

frameRate(5);

noStroke();

fill(255);

ellipse(random(width), random(height), 20, 20);

ellipse(random(width), random(height), 30, 30);

ellipse(random(width), random(height), 25, 25);

ellipse(random(width), random(height), 40, 40);

//Moderate Button Snow //Moderate Button Snow

image(moderateSnow, 1050, 700);

//Header text

fill(7, 144, 180);

textFont(font1, 60);

textAlign(CENTER);

text("Ma Saison Préférée", width/2, 100);

} else if (btSWED) { //Swedish

fill(7, 101, 180);

noStroke();

ellipse(xSWED, ySWED, diam, diam);

fill(255);

textSize(40);

textAlign(CENTER);

text("Svensk", xSWED, 810);

//content

fill(7, 101, 180);

textFont(font2, 80);

textAlign(CENTER);

text("Vintertid", width/2, 300);

//ICICLES //ICICLES

fill(255);

noStroke();

triangle(iceX1, iceY1, iceX1_2, iceY1_2, iceX1_3, iceY1_3);

triangle(iceX2, iceY2, iceX2_2, iceY2_2, iceX2_3, iceY2_3);

triangle(iceX3, iceY3, iceX3_2, iceY3_2, iceX3_3, iceY3_3);

triangle(iceX4, iceY4, iceX4_2, iceY4_2, iceX4_3, iceY4_3);

//SNOWING //Blizzard

frameRate(10);

noStroke();

fill(255);

ellipse(random(width), random(height), 20, 20);

ellipse(random(width), random(height), 30, 30);

ellipse(random(width), random(height), 25, 25);

ellipse(random(width), random(height), 35, 35);

ellipse(random(width), random(height), 40, 40);

//Heavy Button Snow //Heavy Button Snow

image(heavySnow, 1350, 700);

//Header text

fill(7, 101, 180);

textFont(font1, 60);

textAlign(CENTER);

text("Min Favorit Säsong", width/2, 100);

} else if (btClear) { //Clear Button

fill(255);

noStroke();

ellipse(xENGL, yENGL, diam, diam);

ellipse(xSPAN, ySPAN, diam, diam);

ellipse(xITAL, yITAL, diam, diam);

ellipse(xFREN, yFREN, diam, diam);

ellipse(xSWED, ySWED, diam, diam);

//Button Text

textFont(font3, 40);

fill(7, 18, 44);

textAlign(CENTER);

text("English", xENGL, 810);

text("Spanish", xSPAN, 810);

text("Italian", xITAL, 810);

text("French", xFREN, 810);

text("Swedish", xSWED, 810);

//Header

textFont(font1, 60);

fill(7, 18, 44);

textAlign(CENTER);

text("My Favorite Season", width/2, 100);

}

}



void mousePressed() {


//when mouse pressed on Clear Button


if ((mouseX>665 && mouseX<835 && mouseY<570 && mouseY>430)) {

btENGL=false;

btSPAN=false;

btITAL=false;

btFREN=false;

btSWED=false;

header=false;

btClear=true;

}


//when mouse pressed on English button


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

btENGL=true;

btSPAN=false;

btITAL=false;

btFREN=false;

btSWED=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;

btSWED=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;

btSWED=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;

btSWED=false;

header=false;

}


//when mouse pressed on Spanish button


if (dist(xSWED, ySWED, mouseX, mouseY)<diam/2) {

btENGL=false;

btSPAN=false;

btITAL=false;

btFREN=false;

btSWED=true;

header=false;

}

}



<Back to Coding Main Page

9 views0 comments