Wednesday, February 26, 2014

More CS106 Learning :)

And this is the code which makes the Target Draw in Java!

import acm.graphics.*;
import java.awt.*;
import acm.program.*;


public class TargetProgram extends GraphicsProgram {

    public void run() {
        drawCircle1();
        drawCircle2();
        drawCircle3();
    }

    private void drawCircle1() {
        GOval c1 = new GOval(240, 80, 215, 215);
        c1.setFilled(true);
        c1.setColor(Color.RED);
        add(c1);
    }
   
    private void drawCircle2() {
        GOval c2 = new GOval(273, 113, 150, 150);
        c2.setFilled(true);
        c2.setColor(Color.WHITE);
        add(c2);
    }
   
    private void drawCircle3() {
        GOval c3 = new GOval(310, 150, 75, 75);
        c3.setFilled(true);
        c3.setColor(Color.RED);
        add(c3);
    }
       
}


Here is the RobotProgram and my robot!
/* RobotProgram.java creates a robot face from the ACM package graphics */

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class RobotProgram extends GraphicsProgram{

    public void run() {
        drawFace();
        drawEyes();
        drawNose();
        drawMouth();
    }
   
    private void drawFace() {
        GRect face = new GRect(220, 40, 250, 350);
        face.setFilled(true);
        face.setColor(Color.LIGHT_GRAY);
        add(face);
    }
   
    private void drawEyes() {
        GOval lEye = new GOval(260, 95, 50, 50);
        GOval rEye = new GOval(380, 95, 50, 50);
        lEye.setFilled(true);
        lEye.setColor(Color.ORANGE);
        rEye.setFilled(true);
        rEye.setColor(Color.ORANGE);
        add(lEye);
        add(rEye);
    }
   
    private void drawNose() {
        GRect nose = new GRect(335, 185, 20, 40);
        nose.setFilled(true);
        nose.setColor(Color.BLACK);
        add(nose);
    }
   
    private void drawMouth() {
        GRect mouth = new GRect(270, 280, 155, 50);
        mouth.setFilled(true);
        mouth.setColor(Color.WHITE);
        add(mouth);
    }
   
}
now on for some reading time to read chapter 3

Sunday, February 23, 2014

More Java Learning Chapter 2 exercises... 1-5 done :)

But first a CUTE picture of LOGAN got to hang with him today, trying to get him and puddi to be good friends so when the new baby comes I can watch him while Charles and Debbie are in the hospital.

Now for the Assignment to draw a house using the functions available in the acm.jar.

it should look like this:
import acm.graphics.*;
import acm.program.*;

public class HouseProgram extends GraphicsProgram{

    /**
     * @param args
     */
    public void run() {
       
        drawRoof();
        drawHouse();
        drawWindows();
        drawDoor();
    }

    private void drawRoof(){
        add(new GLine(80, 100, 235, 20));
        add(new GLine(235, 20, 380, 100));
    }
   
    private void drawHouse() {
        add(new GRect(80, 100, 300, 200));
    }
   
    private void drawWindows() {
        add(new GRect(105, 130, 70, 70));
        add(new GRect(285, 130, 70, 70));
    }
   
    private void drawDoor() {
        add(new GRect(195, 180, 70, 120));
        add(new GOval(245, 230, 10, 10));
    }
}

And then my Robot Face: the robot has orange eyes, a black nose and and a white mouth:

/* RobotProgram.java creates a robot face from the ACM package graphics */

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class RobotProgram extends GraphicsProgram{

    public void run() {
        drawFace();
        drawEyes();
        drawNose();
        drawMouth();
    }
   
    private void drawFace() {
        GRect face = new GRect(220, 40, 250, 350);
        face.setFilled(true);
        face.setColor(Color.LIGHT_GRAY);
        add(face);
    }
   
    private void drawEyes() {
        GOval lEye = new GOval(260, 95, 50, 50);
        GOval rEye = new GOval(380, 95, 50, 50);
        lEye.setFilled(true);
        lEye.setColor(Color.ORANGE);
        rEye.setFilled(true);
        rEye.setColor(Color.ORANGE);
        add(lEye);
        add(rEye);
    }
   
    private void drawNose() {
        GRect nose = new GRect(335, 185, 20, 40);
        nose.setFilled(true);
        nose.setColor(Color.BLACK);
        add(nose);
    }
   
    private void drawMouth() {
        GRect mouth = new GRect(270, 280, 155, 50);
        mouth.setFilled(true);
        mouth.setColor(Color.WHITE);
        add(mouth);
    }   
}

this is all just using the basic functions and making a guess and coordinates so a lot of draw and look type programming.. we will see how it changes when the class teaches to figure out the coordinates so it draws it without the guess work :)

Enjoy

Sunday, February 2, 2014

More Karel sovling problems in his little world... finding the middle...

Ok so if I had to do this in the real world with all syntax and methods available I would probably do something like:
int count = 1
findCount() {
while frontIsClear() {
move();
int count = count + 1
}
turnAround();

int steps = count/2

while steps != 0 {
move():
int steps = steps-1

putBeeper

however the rules of this assignment state that Count and int are not a part of the karel program so you have to do it with logic.

The simplest method I could think of was to fill in the row with Beepers
from farthest point in so go to wall put beeper turn around go to wall or Beeper  stop turn around and put beeper back and forth till Karel is standing in the middle spot
he moves forward one spot and starts picking up the beepers then when he hits a wall turns around and moves till he hits a beeper again (this one is the middle) he moves one more step and picksup the beepers till he hits a wall
then turns around and moves back to the middle by stopping on the beeper.

Final solution with some help with the && statement from Arnos Blog:

* File: MidpointFindingKarel.java
 * -------------------------------
 * When you finish writing it, the MidpointFindingKarel class should
 * leave a beeper on the corner closest to the center of 1st Street
 * (or either of the two central corners if 1st Street has an even
 * number of corners).  Karel can put down additional beepers as it
 * looks for the midpoint, but must pick them up again before it
 * stops.  The world may be of any size, but you are allowed to
 * assume that it is at least as tall as it is wide.
 */

import stanford.karel.*;

public class MidpointFindingKarel extends SuperKarel {

    // You fill in this part

    public void run() {
        findWalls();
        while (noBeepersPresent()){
            fillToMiddle();
        }
        pickUpExtraBeepers();
        keepMiddle();
        pickUpExtraBeepers();
           
    }
    // this method defines the far west and east of Karel's world. 
    // Precondition karel facing east
    // Postcondition karel will be one avenue to the west of farthest wall on the east facing west
    private void findWalls() {
        putBeeper();
        while (frontIsClear()){
            move();
        }
        putBeeper();
        turnAround();
        move();
        }
   
    // this will fill in the row east to west and back till Karel can't move due to beepers or wall
    private void fillToMiddle() {
        while (frontIsClear() && noBeepersPresent()) {
            move();
        }
        turnAround();
        move();
        putBeeper();
        move();
    }
   
    //Karel is standing on a beeper one avenue past the middle
    private void pickUpExtraBeepers() {
        while (frontIsClear()) {
            pickBeeper();
            move();
        }
        pickBeeper();
        turnAround();
        while (noBeepersPresent()) {
            move();
        }
    }
   
    //keepMiddle just moves karel one past the middle beeper so it is kept to the otherside of it.
    private void keepMiddle() {
        move();
    }
}

So that completes my first Assignment... now on the Lecture 4 and delving into actual java.
    

Monday, January 20, 2014

Decided to learn some Computer Programming... Java so let us begin!

Ok so there are some online course from Stanford that  I saw when I had an Ipad and was looking through their ITunes University.

So the beginning of the year I decided to start it up and learn some new information... this is my First post dealing with my Coding Solution for the First Assignment!

First Assignment

The program Karel is a simple programming environment to teach problem solving.
the language and program are simple but still java so you learn a litte about java as you go.

Part 1 CollectNewspaperKarel:
Karel lives in a house and has to go out the door get the newspaper (beeper) and return to his starting position.

The code was pretty simple but they want you to think in breaking down into processes so that was a bit more difficult to do so here is my solution:

 import stanford.karel.*;

public class CollectNewspaperKarel extends SuperKarel {

    // You fill in this part
    public void run(){
        moveToPaper();
        move();
        pickBeeper();
        returnHome();
    }
// this method moves karel to the door to get paper
    // precondition Karel is in house facing east with wall north and west of him.
    private void moveToPaper() {
        moveToWall();
        turnRight();
        move();
        turnLeft();
    }
    // allows karel to move forward as long as there is no wall in front of him.
    private void moveToWall() {
        while (frontIsClear()) {
            move();
        }
    }
// returns Karel back to the point and state he started
// precondition facing east just outside the door where the newspaper beeper was.
    private void returnHome() {
        turnAround();
        move();
        turnRight();
        moveToWall();
        turnLeft();
        moveToWall();
        turnAround();
   
    }
}
Part 2  StoneMasonKarel:
I first had little karel fixing the columns one row at a time and found that only worked in two of the scenario worlds where the columns and ceilings were all the same level
So I had to change the methods to go up and down to account for the varied levels of ceilings since the columns are always 4 moves a part:
/*
 * File: StoneMasonKarel.java
 * --------------------------
 * The StoneMasonKarel subclass as it appears here does nothing.
 * When you finish writing it, it should solve the "repair the quad"
 * problem from Assignment 1.  In addition to editing the program,
 * you should be sure to edit this comment so that it no longer
 * indicates that the program does nothing.
 */

import stanford.karel.*;

public class StoneMasonKarel extends SuperKarel {

    // You fill in this part

    public void run() {
        while (frontIsClear()) {
            fillInColumnUp();
            descendColumn();
            moveToNextColumn();
        }
        fillInColumnUp();
        descendColumn();
    }
    // this method precondition is karel facing east at bottom of world
    // karel will check for empty beepers in the column and replace them
   
    private void fillInColumnUp() {
        turnLeft();
        if (noBeepersPresent()) {
            putBeeper();
        }
            while (frontIsClear()) {
                move();
                if (noBeepersPresent()) {
                    putBeeper();
                }
            }
    }
    // this method precondition is karel has ascended a column and is stuck at the ceiling facing north
    // karel will go back down the newly repaired Column.
   
    private void descendColumn() {
        turnAround();
        while (frontIsClear()) {
            move();
        }
        turnLeft();
    }
    // this method assumes that Karel has just finished going up and down a column and is at the bottom again
    // facing east again, he will make 4 moves to next standard column location.
   
    private void moveToNextColumn() {
        for(int i=0; i<4; i++) {
            move();
        }
    }
}


Part 3 CheckerboardKarel:
I have to admit this one took me a bit once I figure that east and west didn't do exactly the same thing depending on the world you loaded it finally got it.

Here is my solution:
import stanford.karel.*;

public class CheckerboardKarel extends SuperKarel {

    // You fill in this part
   
    public void run() {
        placeBeepersEast();
            while (leftIsClear()) {
                goUpOneRowFaceWest();
                placeBeepersWest();
                    if (rightIsClear()) {
                        goUpOneRowFaceEast();
                        placeBeepersEast();
                    } else {
                        turnAround();
                    }
            }       
    }
// fills everyother spot in a east west row with a beeper (bug on 7*7)
    //Karel is In home position Facing East
   
    private void placeBeepersEast() {
        putBeeper();
            while (frontIsClear()) {
                move();
                    if (frontIsClear()) {
                        move();
                        putBeeper();
                    }
            }
    }
   
    private void placeBeepersWest() {
            while (frontIsClear()) {
                putBeeper();
                move();
                    if (frontIsClear()) {
                        move();
                    }
            }
    }
   
    // moves karel up one east west row and turns him facing West
    // Precondition: Karel facing East facing wall
    private void goUpOneRowFaceWest() {
        if (noBeepersPresent()) {
            turnLeft();
            move();
            turnLeft();
        } else {
            turnLeft();
            move();
            turnLeft();
            if (frontIsClear()) {
                move();
            }
        }
    }
   
    // moves karel up one row and turns him facing East
    // Precondition: Karel facing West facing wall   
    private void goUpOneRowFaceEast() {
        turnRight();
        move();
        turnRight();
    }
}
it works in all the worlds for testing and I was stoked when it worked on the 1x8 world especially.

I still have to perfect Stone Mason Karel so back to the computer programing world of Karel!

Thursday, November 29, 2012

Finishin up November!

Sorry I had to post a month into one little post...
I got my New Refrigerator to match my other appliances!!!
New Black Fridge!!!





It Also SNOWED this month and a good one, it started on a Thursday night and ended on a Saturday Night!
Puddi at Dog Park in the snow
I love snow and to just have so much in a short time took me back to when I was a kid in Colorado Springs and it was a huge Blizzard... the lights were out and my Grandma and Grandpa Williams were there.
For some reason I recall us painting the house that weekend too but that could just be a crazy thought in only my mind.



Puddi and snow nothing better
  Finally I had a great Thanksgiving... I had dinner with Margo and her family, then I went to my friend and previous Boss at Symantec Mark Kendziors house for a visit.  He has two great dogs and a beautiful home with a Theater ROOM!  Here are Mark's dogs:
Bandit

Coach

Finally My Dad decided he wanted a new hip on the other side (he liked his new one so much) that he fell and broke is other hip on the 27th, he had a new one put in at 3 am on the 28th and so far is doing great... But I really want them to move up here close to me so I can take care of them I don't care if its in Springville or Nephi just as long as it is not Fillmore, Beaver, Cedar City or St George :)
See you in December!




Sunday, October 21, 2012

Night of the Running Dead 5k and Wolverine!

This weekend was a great time..

I had Black Belt Class Saturday morning... and then I had some fun going up to see Jax and Trevon!
We had lunch at Jimmy Johns and while we were there we found out the Anime Convention was in Layton.
Well Juanita and Jax had to go see it so I drove through the Parking lot 3 times for them.

I then had to go home so I could get to my volunteer duties at the Running Dead 5k at the South Town Mall area.
I got there and was quick to start handing out packets and while standing there I decided I was going to do the run.. I have not done a 5k since I lived in Manhattan where I used to do a 5k or 10k once a month.  It was my way of staying in shape for my clients in the gyms.  Well I signed up and realized I didn't have shorts on and I wasn't wearing my running shoes nor a sports bra...
so I ran to Old Navy and bought a pair of Ute pajama bottoms to cut into shorts and wear.

I started the race at a good pace (slow and steady) I finished in 42:30 minute which was pathetic if you look at the fact at one time in my life I was doing 4 miles in 34 minutes... LOL
I had fun and completed the race with a little wear and tear on my bod!

Here is a couple of photos for you to see:

Before the 5K
After the 5k 42:30 minutes later






Sunday I got to go see my nephew Logan X and Deliver his Wolverine costume and do our first photo shoot..
Here are some of my favorites of Logan X as Wolverine!
Candy! 

Look Nerds!

Wolverine that is all you need to know.

Trick or Treat

Treat or Trick?

Who is that Wolverine?
Best Wolverine Ever!

Cutie pie

Showing me his nose

Pat A Cake

Pat A Cake Bakers Man

One Happy Wolverine!

Watching Kung Fu Panda after the Photo shoot.
Dad and Wolverine

Logan finds the Candy!
 
Dad and Son

While mom is not watching...
 
Come here my little child I have nice candy for you!

 All in all I had a good weekend....

Quartet's Photo Shoot! 2012

Well its October...

I have had a busy month the Quartet finally had some time to do a photo shoot and a friend of ours Scott Spain took some great photos...
Here are a few of my Favorites:

We took some solo pictures for our Facbook Spread
I am known for making faces when I play


From left to Right Jill Hancey, Dan Chamberland, Margo Watts and Me!

Me, Dan, Jill and Margo

Me, Dan, Jill and Margo

Dan and I

Me and Margo

Me and Jill




 My marimba looks great too.. Scott Spain did a great job!