/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.cNPPMYksxYU/rev.149
*
* authors:
* Ari Prasetyo
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// t untuk animasi
float t = 0;
/**
* Bagian setup
*/
void setup() {
size(400, 400); // Set ukuran 400x400
smooth(); // Set agar pinggiran halus
colorMode(HSB, TWO_PI, 1.0, 1.0, 1.0); // Set mode warna menjadi HSB
frameRate(20); // Dalam 1 detik, akan ada 20 frame
background(0, 0, 1.0); // Background warna putih
}
/**
* Bagian draw
*/
void draw() {
// Memang dikosongkan, karena belum perlu
// melakukan apa pun
}
/**
* Kuas adalah untuk menggambar garis dari
* koordinat satu ke yang lain
*
* @param x1
* @param y1
* Koordinat tempat titik pertama
* @param x2
* @param y2
* Koordinat tempat titik berikutnya
*/
void kuas(float x1, float y1, float x2, float y2) {
// Menambahkan sesuatu di sini
stroke((t/2) % TWO_PI, 0.6, 1.0, 0.6);
strokeWeight(1);
line(
x2 + 35 * cos(3 * t),
y2 + 35 * sin(3 * t),
x2 - 35 * cos(3 * t),
y2 - 35 * sin(3 * t)
);
// Garis utama
stroke(1.4, 0.9, 0.7, 1.0);
strokeWeight(15);
line(
x1, y1,
x2, y2
);
// Menjalankan t
t += 0.1;
}
/**
* Untuk menghapus seluruh kanvas
*/
void hapus() {
fill(0, 0, 1.0);
noStroke();
rect(0, 0, width, height);
}
/**
* MouseDragged akan dijalankan setiap kali
* mouse di-drag.
*/
void mouseDragged() {
// Ini akan menggambar kuas dari posisi
// pointer sebelumnya ke posisi pointer
// sekarang
kuas(
pmouseX, pmouseY,
mouseX, mouseY
);
}
/**
* Mengatur penekanan tombol keyboard
*/
void keyPressed() {
// Tombol h berarti menghapus kanvas
if (key == 'h') {
hapus();
}
// Tombol s berarti save
else if (key == 's') {
save("gambar.png");
}
// Tombol b berarti blur
else if (key == 'b') {
filter(BLUR, 3);
}
}