-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
124 lines (109 loc) · 3.6 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var starsLocationsX=[];
var starsLocationsY=[];
var randomStarsX=[];
var randomStarsY=[];
var first=true;
var shootingXstart=[];
var shootingYstart=[];
function setup(){
//create canvas
createCanvas(900, 600);
// change the frame rate to make slower
frameRate(60);
//set the background
background(0);
//load images
img = loadImage("assets/lakeEveningSmall.jpg"); // Load an image into the program
hw=loadImage('assets/hwLake.jpg');
//initialize the shooting star location
shootingXstart.push(800);
shootingYstart.push(200);
}
function draw(){
//place the background image
image(img,0,0);
noFill(); //no fill in shapes
//////////// Hello Word Stars
//get the number of stars we already have
lengthStars=randomStarsX.length;
//define variables
var xS=0;
var yS=0;
var added=0; //counter for the number of stars added this iteration
// check if there are enough stars
if (lengthStars<900){
// we want to add 5 every iteration
while (added<5){
xS=round(Math.random()*(width)); //find random x
yS=round(Math.random()*(height-250)); //random y in range
if (red(hw.get(xS,yS))==0){ //if it is in the text field
starsLocationsX.push(xS); //add elements
starsLocationsY.push(yS);
added+=1; //update counter
}
}
}
strokeWeight(2); //set the stroke for the point
stroke(255);
//get number stars available
var lengthStars=starsLocationsX.length;
//keep the points inside letters to a limited number
if (lengthStars>900){
// remove the first 5 locations
starsLocationsX=starsLocationsX.slice(5, lengthStars);
starsLocationsY=starsLocationsY.slice(5, lengthStars);
}
//draw all stars inside letters
for (var k=1; k<lengthStars; k++){
// select the random brightness
stroke(255, 128+round(Math.random()*128));
//draw the point
point(starsLocationsX[k], starsLocationsY[k]);
}
//////////// Shooting star
///
// get the length of the tail
var lenSh=shootingXstart.length;
strokeWeight(4);
//draw the point
point(shootingXstart[lenSh-1], shootingYstart[lenSh-1]);
//update position
shootingXstart.push(shootingXstart[lenSh-1]-2);
shootingYstart.push(shootingYstart[lenSh-1]+1);
// draw the star+tail
for (f=0;f<lenSh; f++){
stroke(255, f); // alpha dependent on the iteration count
point(shootingXstart[f], shootingYstart[f]);
}
//if the tail longer than 50 point - restart
if (lenSh>50){
shootingXstart=[];
shootingYstart=[];
shootingXstart.push(800-round(Math.random()*600));
shootingYstart.push(round(200*Math.random()));
}
//////////// Background stars
///
/// add usual stars as some behind screen
strokeWeight(3); //set the stroke for the point
stroke(255,28);
xS=0; //define variables
yS=0;
added=0; //counter for the number of stars added this iteration
while (added<4){
xS=round(Math.random()*(width)); //find random x
yS=round(Math.random()*(height-250)); //random y in range
randomStarsX.push(xS); //add elements
randomStarsY.push(yS);
added+=1; //update counter
}
// check that there are less than X stars
if (lengthStars>20){
randomStarsX=randomStarsX.slice(4, lengthStars);
randomStarsY=randomStarsY.slice(4, lengthStars);
}
//draw them
for (var k=1; k<lengthStars; k++){
point(randomStarsX[k], randomStarsY[k]);
}
}