Last active
November 22, 2021 16:29
-
-
Save igor-kamil/dd72bfb0bd76abe5dbd95577ce3108f2 to your computer and use it in GitHub Desktop.
KP3 vectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArrayList<Castica> castice = new ArrayList<Castica>(); | |
PVector gravitacia = new PVector(0, 0.03); | |
class Castica { | |
PVector pozicia; | |
PVector smer; | |
Castica(float kamX, float kamY) { | |
pozicia = new PVector(kamX, kamY); | |
PVector mys = new PVector(mouseX, mouseY); | |
smer = PVector.sub(pozicia, mys); | |
smer.div(60); | |
} | |
void kresli() { | |
noStroke(); | |
fill(255); | |
circle(pozicia.x, pozicia.y, 10); | |
} | |
void pohni() { | |
smer = PVector.add(smer, gravitacia); | |
pozicia = PVector.add( pozicia, smer ); | |
} | |
boolean jeVonku() { | |
return (pozicia.y > (height*0.9)); | |
} | |
} | |
void setup() | |
{ | |
background(0); | |
size(800, 800); | |
noFill(); | |
stroke(255); | |
} | |
void draw() | |
{ | |
background(0); | |
for (int i = 0; i< castice.size(); i++) { | |
castice.get(i).kresli(); | |
castice.get(i).pohni(); | |
if (castice.get(i).jeVonku()) { | |
castice.remove(i); | |
} | |
} | |
} | |
void mousePressed() { | |
castice.add(new Castica(width / 2, height / 2)); | |
} | |
void mouseMoved() { | |
// tetiva | |
stroke(70); | |
line(width/2, 0, mouseX, mouseY); | |
line(width/2, height, mouseX, mouseY); | |
// sip | |
stroke(255, 0, 0); | |
line(mouseX, mouseY, width/2, height/2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment