forked from lenaMK/art-algorithmique
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
79 lines (52 loc) · 1.69 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
/*
title: Where is art?
author: LenaMK
date: 2023-01-13
description: rechercher le texte "Art is here". La souris est un cercle blanc qui révèle le texte en noir sur fond noir. L'emplacement du texte est différent (random) à chaque fois qu'on charge la page ou quand on clique sur le texte
inpiration: effet lampe de poche; tel un spéléologue dans une grotte. Discussions dans le cours sur qu'est-ce que c'est l'art, et "où" il se trouve
initial code inspired by:
- https://www.geeksforgeeks.org/p5-js-displaywidth-variable/
*/
// Art position
var x, y
var art = "Art is here."
var fontsize = 35
var font = 'BagnardRegular'
var artWidth, artHeight, artAscent, artDescent
// Circle
var circleRadius //somehow isn't the radius but the diameter...
var overflow = 50
function setup() {
createCanvas(windowWidth, windowHeight);
textSize(fontsize);
textFont(font)
artWidth = textWidth(art)
artAscent = textAscent()
artDescent = textDescent()
artHeight = artAscent+artDescent
circleRadius = (artWidth+overflow)
setArt();
noCursor();
}
function setArt(){
//clear previous setArt
clear()
x = random(5, windowWidth-artWidth)
y = random(artAscent, windowHeight-artDescent)
}
function mousePressed() {
var artCenterX = x + artWidth/2
var artCenterY = y + artHeight/2
var distance = dist(mouseX, mouseY, artCenterX, artCenterY)
if (distance < overflow)
setArt();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
setArt()
}
function draw() {
background(0o0);
circle(mouseX, mouseY, circleRadius);
text(art, x, y);
}