Earlab Home | Home | Getting Started | Projects | Tutorials | Topics | Community | Links |

Tutorials for Processing

Table of Contents

PVector

Το πρότυπο PVector αποτελεί ένα πολύ χρήσιμο εργαλείο στον προγραμματισμό με την Processing. Περιγράδφει το διδιάστατο ή το τριδιάστατο διάνυσμα. Συνηθίζεται να χρησιμοποιείται για ορισμό της θέσης της ταχύτητας και της επιτάχυνσης.

/**
PVector study
Aris Bezas Thu, 14 July 2011, 12:35
*/

import processing.opengl.*;

PVector thesi;

void setup()  {
  size(600,600,OPENGL);
  thesi = new PVector();
  thesi.x = 0;
  thesi.y = height/2;
  
  noFill();
  stroke(255);
}

void draw()  {
  background(0);
  thesi.x += sin(frameCount*0.005);
  thesi.y += cos(frameCount*0.005);
  translate(thesi.x,thesi.y);
  box(40);
}

Για περαιτέρω διάβασμα http://dev.processing.org/reference/core/javadoc/processing/core/PVector.html

kinetics

/**
kinetics study
Aris Bezas Fri, 15 July 2011, 10:14
*/

import processing.opengl.*;

PVector thesi;
PVector peristrofi;

void setup()  {
  size(600,600,OPENGL);
  background(0);
  thesi = new PVector();
  peristrofi = new PVector(1,2,3);
  thesi.x = 0;
  thesi.y = height/2;
  
  noFill();
  stroke(255);
  
  
}

void draw()  {
  background(0);
  thesi.x = thesi.x + sin(frameCount*0.005);
  peristrofi.x = peristrofi.x + sin(frameCount*0.05);  
  peristrofi.y = peristrofi.y + sin(frameCount*0.0005);    
  thesi.y += cos(frameCount*0.005);
  translate(100,0);  
  translate(thesi.x,thesi.y);
  //box(40);
  sphere(7);
  rotateX(0.05*peristrofi.x);
  rotateY(0.5*peristrofi.y);
  line(0,0,0,40,40,40);
  sphere(5);
  translate(40,40,40);
  sphere(11);
  line(0,0,0,40,-40,-40);
  translate(40,-40,-40);
  rotateX(0.2*peristrofi.x);  
  sphere(6);
  line(0,0,0,40,-40,40);
  translate(40,-40,40);
  sphere(2);
  
}

void mousePressed()  {
  background(0);
}

Class study

Το παράδειγμα που ακολουθεί αποτελέι ένα σασι με το συντακτικό για την δημιουργεία προτύπων (classes) στην Processing. Το πρότυπο που δημιουργείται ονομάζεται Protypo και τα αντικείμενα (διάνυσμα αντικειμένων) ονομάζονται antikeimeno.

/**
Class study
Aris Bezas Thu, 14 July 2011, 11:35
*/

Protypo[] antikeimeno = new Protypo[100];

void setup()  {
  size(600,600);
  for (int i=0; i<antikeimeno.length; i++)  {
    antikeimeno[i] = new Protypo(1.90,93,31);
    antikeimeno[i].init();
  }
  
}

void draw()  {
  for (int i=0; i<antikeimeno.length; i++)  {
    antikeimeno[i].update();
    antikeimeno[i].draw();    
  }
}

void mousePressed() {
  
}

class Protypo  {
  
  float ypsos, varos, hlikia;
  Protypo(float ypsosVar, float varosVar, float hlikiaVar)  {
    ypsos = ypsosVar;
    varos = varosVar;
    hlikia = hlikiaVar;
  }
  
  void init()  {
  }
  void update()  {
  }
  void draw()  {
  }
}

Author: Ioannis Zannos & Aris Bezas

Date: <2011-07-14 Thu>

HTML generated by org-mode 7.4 in emacs 23