User Tools

Site Tools


spcs:2015:day5

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
spcs:2015:day5 [2015/07/09 16:14]
ffpaladin [Feedback to class]
spcs:2015:day5 [2015/07/09 20:15]
ffpaladin [Class Assignments]
Line 25: Line 25:
     - You can try to use the art in your simulation or game     - You can try to use the art in your simulation or game
   - **Perler Beads**: Make a sprite with perler beads   - **Perler Beads**: Make a sprite with perler beads
 +  - **FEEDBACK FORM**: Please fill out feedback form...
 +    - https://​docs.google.com/​forms/​d/​1Q-qo1Nt9Jkjn90ldtsMC30zcICHnOf9_Ra-r1M1hKWM/​viewform
 ===== Homework ===== ===== Homework =====
  
Line 42: Line 44:
   * Participate and take more risks   * Participate and take more risks
   * Be more social with the guest speakers   * Be more social with the guest speakers
 +
 +<code java>
 +
 +color c = color(0);
 +float x = 0;
 +float y = 100;
 +float speed = 1;
 +
 +void setup() {
 +  size(200,​200);​
 +}
 +
 +void draw() {
 +  background(255);​
 +  move();
 +  display();
 +}
 +
 +void move() {
 +  x = x + speed;
 +  if (x > width) {
 +    x = 0;
 +  }
 +}
 +
 +void display() {
 +  fill(c);
 +  rect(x,​y,​30,​10);​
 +}
 +
 +</​code>​
 +
 +<code java>
 +
 +
 +// Example: Two Car objects
 +Car myCar1;
 +Car myCar2; // Two objects!
 +
 +void setup() {
 +  size(200,​200);​
 +  // Parameters go inside the parentheses when the object is constructed.
 +  myCar1 = new Car(color(255,​0,​0),​0,​100,​2); ​
 +  myCar2 = new Car(color(0,​0,​255),​0,​10,​1);​
 +}
 +
 +void draw() {
 +  background(255);​
 +  myCar1.drive();​
 +  myCar1.display();​
 +  myCar2.drive();​
 +  myCar2.display();​
 +}
 +
 +// Even though there are multiple objects, we still only need one class. ​
 +// No matter how many cookies we make, only one cookie cutter is needed.
 +class Car { 
 +  color c;
 +  float xpos;
 +  float ypos;
 +  float xspeed;
 +
 +  // The Constructor is defined with arguments.
 +  Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) { 
 +    c = tempC;
 +    xpos = tempXpos;
 +    ypos = tempYpos;
 +    xspeed = tempXspeed;
 +  }
 +
 +  void display() {
 +    stroke(0);
 +    fill(c);
 +    rectMode(CENTER);​
 +    rect(xpos,​ypos,​20,​10);​
 +  }
 +
 +  void drive() {
 +    xpos = xpos + xspeed;
 +    if (xpos > width) {
 +      xpos = 0;
 +    }
 +  }
 +}
 +
 +</​code>​
 +
 +<code java>
 +
 +int x, y;
 +void setup() ​
 +{
 +  size (500,500);
 +}
 +
 +void draw()
 +{
 +  ellipse(x,​y,​20,​20); ​
 +  if ((key == '​d'​) && (keyPressed))
 +  {
 +    x++;
 +  }
 +  else if (key == '​s'​)
 +  {
 +    y++;
 +  }  ​
 +  ​
 +}
 +
 +</​code>​
/soe/sherol/.html/teaching/data/pages/spcs/2015/day5.txt · Last modified: 2015/07/11 01:34 by ffpaladin