【发布时间】:2020-04-20 14:38:40
【问题描述】:
我正在尝试找到一种方法,让我的程序在鼠标滚动到某个框中时确认它是什么文本。我不知道该怎么做,因为文本不是对象或任何东西,文本是根据框的位置写入框的。我认为如果盒子是单独的元素,这会更容易,但我不知道如何设置它。这是我到目前为止所得到的。
var curMonthName;
var daysInMonth;
var firstDayCal;
var currentWeek;
var calX;
var calY;
function setup() {
createCanvas(650, 500);
}
function draw() {
background(220, 15, 15);
drawCalendar();
}
function drawCalendar()
{
let monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
let monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
let weekDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var currentMonth = month() - 1;
var currentYear = year();
curMonthName = monthNames[currentMonth];
daysInMonth = monthDays[currentMonth];
firstDayCal = 1;
cDate = new Date(currentYear, currentMonth, firstDayCal);
calDate = cDate.getDate();
actualDate = cDate.getDate();
currentDay = cDate.getDay();
currentWeek = 1;
fill(255);
textAlign(LEFT);
textSize(40);
noStroke();
textSize(45);
textAlign(CENTER);
text(curMonthName, width/2, 45);
textSize(20);
text('Sun', 89.25, 75);
text('Mon', 167.75, 75);
text('Tue', 246.25, 75);
text('Wed', 324.75, 75);
text('Thur', 403.25, 75);
text('Fri', 481.75, 75);
text('Sat', 560.25, 75);
while (firstDayCal <= daysInMonth)
{
drawBoxes(calX, calY);
cDate.setDate(firstDayCal);
}
}
function drawBoxes(calX, calY)
{
numbOfRows = ceil((1 + daysInMonth) / 7);
textAlign(CENTER);
if(cDate.getDay() == 0)
{
calX = 50;
}
else if(cDate.getDay() == 1)
{
calX = 128.5;
}
else if(cDate.getDay() == 2)
{
calX = 207;
}
else if(cDate.getDay() == 3)
{
calX = 285.5;
}
else if(cDate.getDay() == 4)
{
calX = 364;
}
else if(cDate.getDay() == 5)
{
calX = 442.5;
}
else if(cDate.getDay() == 6)
{
calX = 521;
}
if (cDate.getDay() == 0 && calDate != 1)
{
currentWeek = currentWeek + 1;
}
calY = 70 * currentWeek + 18;
fill(255);
stroke(0);
strokeWeight(1.5);
rect(calX, calY, 78.5, 70);
fill(0);
textSize(30);
if (currentWeek == 1)
{
text(calDate, calX + 39.25, 135);
}
else if (currentWeek == 2)
{
text(calDate, calX + 39.25, 205);
}
else if (currentWeek == 3)
{
text(calDate, calX + 39.25, 275);
}
else if (currentWeek == 4)
{
text(calDate, calX + 39.25, 345);
}
else if (currentWeek == 5)
{
text(calDate, calX + 39.25, 415);
}
else if (currentWeek == 6)
{
text(calDate, calX + 39.25, 485);
}
firstDayCal = firstDayCal + 1;
calDate = calDate + 1;
if (currentDay != 6)
{
currentDay = currentDay + 1;
}
else if (currentDay >= 7)
{
currentDay = 0;
}
calReadableDate = calDate + month() + year();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"></script>
【问题讨论】:
-
那么,如果鼠标移到画布上显示的一段文字上,你想做什么?
-
@Schred 是的,基本上就是这样
标签: javascript object text processing p5.js