Oldalak 5 / 5
4.óra
több funkciós rajprogram
int festoMod;
void setup()
{
size(600, 400);
background(255, 255, 255);
festoMod = 0;
}
void draw()
{
if (mousePressed == true)
{
if (festoMod == 0)
{
fujj(mouseX, mouseY);
}
if (festoMod == 1)
{
rajzoljEgyArcot(mouseX, mouseY);
}
}
}
void fujj(float x, float y)
{
fill(0);
noStroke();
for (int n = 0; n < 20; n += 1)
{
ellipse(x + random(-10, 10), y + random(-10, 10), 2, 2);
}
}
void rajzoljEgyArcot(int x, int y)
{
noFill();
stroke(0);
ellipse(x, y, 100, 100);
ellipse(x - 30, y - 10, 30, 30);
ellipse(x + 30, y - 10, 30, 30);
ellipse(x, y + 30, 50, 5);
}
void keyPressed()
{
if (key == '1')
{
festoMod = 0;
}
if (key == '2')
{
festoMod = 1;
}
}
Pattogó labda
float x, y, vx, vy;
void setup()
{
size(100, 100);
x = random(0, width);
y = random(0, height);
//vx = random(-1, 1);
//vy = random(-1, 1);
vx = cos( radians(32) );
vy = sin( radians(32) );
}
void draw()
{
background(255, 255, 255);
x += vx;
y += vy;
if (x < 0)
{
vx = -vx;
}
if (x > width)
{
vx = -vx;
}
if (y < 0)
{
vy = -vy;
}
if (y > height)
{
vy = -vy;
}
ellipse(x, y, 2, 2);
}
Tömb használata:
tomb valtozo letrehozasa
float[] tomb;
tomb meretenek meghatarozasa
tomb = new float[hanyDarab];
a tomb elemeire a kapcsos zarojelek koze irt indexszammal lehet hivatkozni
tomb[0] = ertek;
tomb[1] = masikErtek;
println( tomb[0] );
Részecske rendszer létrehozása:
int db;
// egy elem tulajdonsagai
float[] x, y, meret;
color[] szin;
void setup()
{
size(500, 500);
db = 1000; // hany darab elem legyen
// tulajdonsagok inicializalasa
x = new float[db];
y = new float[db];
meret = new float[db];
szin = new color[db];
// kezdoertekek megadasa
for (int i = 0; i < db; i += 1)
{
x[i] = width / 2;
y[i] = height / 2;
meret[i] = random(5, 10);
szin[i] = color( random(255) , 0, 0, random(10, 30));
}
noStroke();
background(255, 255, 255);
}
void draw()
{
for (int i = 0; i < db; i += 1)
{
//elem mozgatasa
x[i] += random(-5, 5);
y[i] += random(-5, 5);
// elem szine
fill( szin[i] );
// elem kirajzolasa
ellipse(x[i], y[i], meret[i], meret[i]);
}
//saveFrame("seq#####.tif");
}
Kép színeinek felhasználása, kép alapú effekt
PImage kep;
void setup()
{
kep = loadImage("hatter.jpg");
size(kep.width, kep.height);
background(0, 0, 0);
noStroke();
}
void draw()
{
float meret = 2 + mouseX / 10.0;
for (int i = 0; i < 100; i++)
{
float x = random(0, width);
float y = random(0, height);
color szin = kep.get(int(x), int(y));
fill( szin );
ellipse(x, y, meret, meret);
}
}
|