Author Topic: Informatik Notizen  (Read 1591 times)

Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Informatik Notizen
« on: 23. October 2014, 13:34:31 »
Bestehende funktionen: setup, draw, car(xPos,yPos), house(xPos,yPos,size)
42,340 to 122,370
global var: carPos, carSpeed, houseSize

Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Re: Informatik Notizen
« Reply #1 on: 23. October 2014, 14:07:32 »
int time = 0;
boolean dusk = true;
int xSize = 800;
int ySize = 640;

void setup(){
  size(xSize,ySize);
}

void draw(){
  background(0,85,255-time);
  sun(xSize,ySize);
  scene(xSize,ySize);
  car(xSize,ySize);
 
  if(dusk == true){
    time = time + 1;
    if(time >= 80) dusk = false;
  } else {
    time = time - 1;
    if(time <= 0) dusk = true;   
  } 
}

void scene(int xSize, int ySize){
  fill(100-time,200-time,0);
  rect(0,ySize/2,xSize,ySize);
  fill(100-time,100-time,100-time);
  beginShape();
  vertex(xSize/4,ySize/2);
  vertex(xSize/4*3,ySize/2);
  vertex(0,ySize);
  vertex(xSize,ySize);
  endShape();
}

void sun(int xSize, int ySize){
  fill(255,255-time,0);
  circle(xSize/4*3,ysize/8+time,ySize/16);
}

void car(int xSize, int ySize){
  fill(255-time,0,255-time);
 
}
« Last Edit: 23. October 2014, 14:35:31 by Vethalon »

Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Re: Informatik Notizen
« Reply #2 on: 30. October 2014, 12:42:14 »
int screenwidth = 1280;
int screenHeight = 1024;
PFont font;

void setup(){
  size(screenwidth,screenHeight);
  frameRate(120);
  font = createFont("Arial",32,true);
}

int wallThick = 50;
int paddleSize = 50;
int xPaddle1Pos = 40;
int yPaddle1Pos = screenHeight/2;
int xPaddle2Pos = screenwidth-40;
int yPaddle2Pos = screenHeight/2;
float xBallPos = screenwidth/2;
float yBallPos = screenHeight/2;
float xBallSpeed = -1.2;
float yBallSpeed = 0;
int points1 = 0;
int points2 = 0;
float q = 0;

void draw(){
  court();
  player1();
  player2();
  ball();
}
void court(){
  background(0,0,0);
  fill(255,255,255);
  //upper wall
  rect(0,0,screenwidth,wallThick);
  //lower wall
  rect(0,screenHeight,screenwidth,-wallThick); 
  //points
  textFont(font,32);
  textAlign(LEFT);
  text("Player 1: "+points1,screenwidth / 4,100);
  textAlign(RIGHT);
  text("Player 2: "+points2,screenwidth / 4 * 3,100);
}

void player1(){
  //movement
  if(keyPressed == true && key == 'w' && (yPaddle1Pos - paddleSize - wallThick) > 0 && xBallSpeed < 0) yPaddle1Pos -= 2;
  if(keyPressed == true && key == 's' && (yPaddle1Pos + paddleSize + wallThick) < screenHeight && xBallSpeed < 0) yPaddle1Pos += 2;
  //paddle
  fill(255,255,255);
  rect(xPaddle1Pos,yPaddle1Pos - paddleSize,-20,paddleSize*2);
}

void player2(){
  //movement
  if(keyPressed == true && key == 'i' && (yPaddle2Pos - paddleSize - wallThick) > 0 && xBallSpeed > 0) yPaddle2Pos -= 2;
  if(keyPressed == true && key == 'k' && (yPaddle2Pos + paddleSize + wallThick) < screenHeight && xBallSpeed > 0) yPaddle2Pos += 2;
  //paddle
  fill(255,255,255);
  rect(xPaddle2Pos,yPaddle2Pos - paddleSize,20,paddleSize*2);
}

void ball(){
  fill(255,255,255);
  ellipse(xBallPos,yBallPos,10,10);
  //player1
  if(xBallPos <= xPaddle1Pos && xBallSpeed < 0){
    if(yBallPos >= yPaddle1Pos-paddleSize && yBallPos <= yPaddle1Pos+paddleSize){
      q = yPaddle1Pos - yBallPos;
      q = q * 100 / paddleSize;
      yBallSpeed = yBallSpeed - q / 100;
      xBallSpeed = xBallSpeed * -1.1;
    } else {
      points2 += 1;
      xBallPos = screenwidth/2;
      yBallPos = screenHeight/2;
      yBallSpeed = 0;
      xBallSpeed = -1.2;
    }
  }
  //player2
    if(xBallPos >= xPaddle2Pos && xBallSpeed > 0){
    if(yBallPos >= yPaddle2Pos-paddleSize && yBallPos <= yPaddle2Pos+paddleSize){
      q = yPaddle2Pos - yBallPos;
      q = q * 100 / paddleSize;
      yBallSpeed = yBallSpeed - q / 100;
      xBallSpeed = xBallSpeed * -1.1;
    } else {
      points1 += 1;
      xBallPos = screenwidth/2;
      yBallPos = screenHeight/2;
      yBallSpeed = 0;
      xBallSpeed = 1.2;
    }
  }
 
 
  if(yBallPos <= wallThick || yBallPos >= screenHeight-wallThick) yBallSpeed *= -1;
  xBallPos += xBallSpeed;
  yBallPos += yBallSpeed;
}
« Last Edit: 30. October 2014, 13:55:14 by Vethalon »

Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Re: Informatik Notizen
« Reply #3 on: 07. November 2014, 10:42:05 »
1. Der Schleifenrumpf wird 8 mal ausgeführt.
2. "theAnswer" hat am ende des Programms den Wert 42 :D

Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Re: Informatik Notizen
« Reply #4 on: 07. November 2014, 11:58:39 »
int screenwidth = 1280;
int screenHeight = 1024;
PFont font;

int wallThick = 50;
int paddleSize = 50;
int xPaddle1Pos = 40;
int yPaddle1Pos = screenHeight/2;
int xPaddle2Pos = screenwidth-40;
int yPaddle2Pos = screenHeight/2;
float xBallPos = screenwidth/2;
float yBallPos = screenHeight/2;
float xBallSpeed = -1.2;
float yBallSpeed = 0;
int points1 = 0;
int points2 = 0;
float q = 0;
int counter = 0;
int numBrick = 8;
int[] yBrick = new int[numBrick];
int[] xBrick = new int[numBrick];
int brickSize = 40;


void setup(){
  size(screenwidth,screenHeight);
  frameRate(120);
  font = createFont("Arial",32,true);
  while(counter < numBrick){
   xBrick[counter] = screenwidth/2;
   yBrick[counter] = screenHeight - 2 * wallThick;
   yBrick[counter] /= numBrick;
   yBrick[counter] *= counter+1; 
   counter++;
  }
}



void draw(){
  court();
  player1();
  player2();
  ball();
  breakOut();
}
void court(){
  background(0,0,0);
  fill(255,255,255);
  //upper wall
  rect(0,0,screenwidth,wallThick);
  //lower wall
  rect(0,screenHeight,screenwidth,-wallThick);
  //points
  textFont(font,32);
  textAlign(LEFT);
  text("Player 1: "+points1,screenwidth / 4,100);
  textAlign(RIGHT);
  text("Player 2: "+points2,screenwidth / 4 * 3,100);
  fill(0,255,0);
  counter = 0;
  while(counter < numBrick){
    rect(xBrick[counter]-10,yBrick[counter]-brickSize,20,brickSize*2);
    counter++;
  }
}

void breakOut(){
  counter = 0;
  while(counter < numBrick){
    if((xBallPos >= xBrick[counter] - 10) && (xBallPos <= xBrick[counter] + 10) && (yBallPos >= yBrick[counter] - brickSize) && (yBallPos <= yBrick[counter] + brickSize)){
      if(xBallSpeed < 0){
        xBrick[counter] -= 20;
      } else {
        xBrick[counter] += 20;
      }
      xBallSpeed *= -1;
    }
    counter++;
  }
}

void player1(){
  //movement
  if(keyPressed == true && key == 'w' && (yPaddle1Pos - paddleSize - wallThick) > 0 && xBallSpeed < 0) yPaddle1Pos -= 2;
  if(keyPressed == true && key == 's' && (yPaddle1Pos + paddleSize + wallThick) < screenHeight && xBallSpeed < 0) yPaddle1Pos += 2;
  //paddle
  fill(255,255,255);
  rect(xPaddle1Pos,yPaddle1Pos - paddleSize,-20,paddleSize*2);
}

void player2(){
  //movement
  if(keyPressed == true && key == 'i' && (yPaddle2Pos - paddleSize - wallThick) > 0 && xBallSpeed > 0) yPaddle2Pos -= 2;
  if(keyPressed == true && key == 'k' && (yPaddle2Pos + paddleSize + wallThick) < screenHeight && xBallSpeed > 0) yPaddle2Pos += 2;
  //paddle
  fill(255,255,255);
  rect(xPaddle2Pos,yPaddle2Pos - paddleSize,20,paddleSize*2);
}

void ball(){
  fill(255,255,255);
  ellipse(xBallPos,yBallPos,10,10);
  //player1
  if(xBallPos <= xPaddle1Pos && xBallSpeed < 0){
    if(yBallPos >= yPaddle1Pos-paddleSize && yBallPos <= yPaddle1Pos+paddleSize){
      q = yPaddle1Pos - yBallPos;
      q = q * 100 / paddleSize;
      yBallSpeed = yBallSpeed - q / 100;
      xBallSpeed = xBallSpeed * -1.1;
    } else {
      points2 += 1;
      xBallPos = screenwidth/2;
      yBallPos = screenHeight/2;
      yBallSpeed = 0;
      xBallSpeed = -1.2;
    }
  }
  //player2
    if(xBallPos >= xPaddle2Pos && xBallSpeed > 0){
    if(yBallPos >= yPaddle2Pos-paddleSize && yBallPos <= yPaddle2Pos+paddleSize){
      q = yPaddle2Pos - yBallPos;
      q = q * 100 / paddleSize;
      yBallSpeed = yBallSpeed - q / 100;
      xBallSpeed = xBallSpeed * -1.1;
    } else {
      points1 += 1;
      xBallPos = screenwidth/2;
      yBallPos = screenHeight/2;
      yBallSpeed = 0;
      xBallSpeed = 1.2;
    }
  }
 
 
  if(yBallPos <= wallThick || yBallPos >= screenHeight-wallThick) yBallSpeed *= -1;
  xBallPos += xBallSpeed;
  yBallPos += yBallSpeed;
}

Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Re: Informatik Notizen
« Reply #5 on: 14. November 2014, 10:58:04 »
void setup(){
   int[] values = new int[]{2,6,4,2,1};
   for(int i = 0; i <= values.length; i++){
      doSomething(values);
   }
}

void doSomething(int value){

}

void setup(){
   int[] values = new int[]{2,6,4,2,1};
   int i = 0;
   while(i <= values.length){
      doSomething(values);
      i++;
   }
}

void doSomething(int value){

}

Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Re: Informatik Notizen
« Reply #6 on: 14. November 2014, 12:10:45 »
String input = "";
boolean trigger = false;
 
void setup() {
  size(1280, 1024);
  textAlign(CENTER);
  textSize(50);
  fill(0,0,0);
}

void keyPressed() {
  if (keyCode == BACKSPACE) {
    if(input.length() > 0) input = input.substring(0, input.length()-1);
  } else if(keyCode == ENTER){
    trigger = true;
    plot(input);
  } else if(keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) input = input+key;
}

void plot(String input){
  background(255,255,255);
  fill(0,0,0);
  for(int i = 0; i <= input.length(); i++){
    rect(width * i / (input.length() + 1), 100, -(width / (input.length() + 1) / 2), input.charAt(i) * 100);
  }
}

void draw() {
  if(trigger == false){
  background(255,255,255);
  text("Input your string of numbers here.", width/2, height/16);
  text(input, width/2, height/8);
  }
}

Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Re: Informatik Notizen
« Reply #7 on: 28. November 2014, 11:28:27 »
(x²-4)(x²-1)(x)
(x+2)(x-2)(x+1)(x-1)(x)


Offline Vethalon

  • Moderator
  • Etablierter Benutzer
  • *
  • Posts: 274
Re: Informatik Notizen
« Reply #8 on: 21. April 2015, 10:33:17 »
a)
   1. Der Ablauf ist nicht deterministisch, da der Algorythmus willkürliche Entscheidungen trifft.
   2. Das Ergebnis ist nicht determiniert, da das Ergebnis von willkürlichen Entscheidungen des Algorythmus abhängt.
   3. Der Algorythmus ist stets terminierend, da kein Item mehrmals bearbeitet wird, es eine endliche Zahl an Items gibt und es für jedes Item eine klare Entscheidung gibt.
   
b)
   1. Der Ablauf ist deterministisch, solange Tudi eine klare Vorstellung hat vieviel Blau/Rot nötig ist und was die Mindestgröße für besonders groß ist.
   2. Das Ergebnis ist determiniert, solange die anforderungen von 1. erfüllt sind.
   3. Der Algorythmus ist stets terminierend, da kein Item mehrmals bearbeitet wird, es eine endliche Zahl an Items gibt und es für jedes Item eine klare Entscheidung gibt.