Zadania:
- Piksele
- Gradienty
- Obrazek
- Fraktale
//==========================================
//Zadanie 1.
//==========================================
function setup() {
createCanvas(800, 600);
noLoop();
}
function draw() {
// noprotect
background(0);
for(y=0; y<height; y++){
for(x=0; x<width; x++) {
set(x, y, color(255,0,255));
}}
updatePixels();
}
//==========================================
//Zadanie 2.
//==========================================
function setup() {
createCanvas(800, 600);
noLoop();
}
function draw() {
// noprotect
background(0);
for(y=0; y<height; y++){
for(x=0; x<width; x++) {
set(x, y, color((x/width)*256));
}}
updatePixels();
}
//==========================================
//Zadanie 3.
//==========================================
function setup() {
createCanvas(800, 600);
noLoop();
}
function draw() {
// noprotect
background(0);
for(y=0; y<height; y++){
for(x=0; x<width; x++) {
var px = x-(width/2);
var py = y-(height/2);
var d =sqrt(((px)*(px))+((py)*(py)));
set(x, y, color(255-d,d,(((x/width)*255)+((y/(height)*255)))));
}}
updatePixels();
}
//==========================================
//Zadanie 4.
//==========================================
function setup() {
createCanvas(800, 600);
noLoop();
}
function draw() {
// noprotect
background(0);
for(y=0; y<400; y++){
for(x=0; x<width; x++) {
set(x, y, color(0,0,255));
}}
updatePixels();
for(y=400; y<height; y++){
for(x=0; x<width; x++) {
set(x, y, color(0,128,0));
}}
updatePixels();
for(i=0; i<1000;i++){
set(floor(random(0,800)), floor(random(400,600)), color(floor(random(0,255)),floor(random(0,255)),floor(random(0,255))));
}
updatePixels();
for(y=200; y<400; y++){
for(x=200; x<600; x++) {
set(x, y, color(139,69,19));
}}
updatePixels();
for(var y=50,w=400,d=399; y<200; y++,w+=2,d-=2)
for(x=d; x<w; x++){{
set(x, y, color(255,99,71));
}}
updatePixels();
}
//==========================================
//Zadanie 5.
//==========================================
function setup() {
createCanvas(800, 600);
background(0);
}
function draw() {
// noprotect
x1 = 400;
y1 = 100;
x2 = 150;
y2 = 500;
x3 = 700;
y3 = 500;
stroke(255);
point(x1,y1);
point(x2,y2);
point(x3,y3);
cx = x1;
cy = y1;
for(i=0;i<30000;i++){
t = floor(random(0,3));
switch(t){
case 0:
cx=(cx+x1)/2;
cy=(cy+y1)/2;
point(cx, cy);
break;
case 1:
cx=(cx+x2)/2;
cy=(cy+y2)/2;
point(cx, cy);
break;
default:
cx=(cx+x3)/2;
cy=(cy+y3)/2;
point(cx, cy);
break;
}}
updatePixels();
}