Javascript의 기초가 가장 강력하지 않으며 다른 사람들이 내가 직접 만든 현재의 도전에 대해 어떻게 생각하는지 궁금합니다. WWW -고유 한 변수 만들기
내가 paper.js
다음 코드로 장난있어 눈 (즉 코드에서 배운) 여기에 눈과 같은 방식으로 마우스 이벤트에 반응이
을 만듭니다. 내가 눈으로 전체 페이지를 채우기 위해 찾고 있어요
// Eye position center
eCntrX = 100
eCntrY = 100
var topLid = new Path()
topLid.add(new Point(eCntrX - 60, eCntrY))
topLid.add(new Point(eCntrX, eCntrY - 28))
topLid.add(new Point(eCntrX + 60, eCntrY))
topLid.add(new Point(eCntrX, eCntrY + 28))
topLid.strokeWidth = '6'
topLid.strokeColor = '#000'
topLid.closed = true
topLid.smooth()
var iris = new Path.Circle(eCntrX, eCntrY, 24)
iris.fillColor = '#6CE0FF'
iris.strokeWidth = '6'
iris.strokeColor = '#000'
var pupil = new Path.Circle(eCntrX, eCntrY, 15)
pupil.fillColor = '#000'
var glint = new Path.Circle(eCntrX, eCntrY, 5)
glint.fillColor = '#fff'
glint.position = new Point(eCntrX + 6, eCntrY - 6)
var ball = new Group([iris, pupil, glint])
function onMouseMove(event) {
// Cursor position
var csrX = event.point.x
var csrY = event.point.y
// Ball position
var ballX = ball.position.x
var ballY = ball.position.y
// Displacement
var dx = csrX - ballX
var dy = csrY - ballY
//Radius
var r = 5
//Pythagerous thereom calcs. R
var R = Math.sqrt(dx*dx+dy*dy)
x = dx*r/R
y = dy*r/R
ball.position = new Point(eCntrX + x, eCntrY + y)
// console.log('x:' + x + 'y:' + y)
}
: arc.id.au/XEyes.html
는여기에 내가 가진거야. 내 최종 목표는 다음과 같이 뭔가를 만드는 것입니다 :
내 질문은, 대화 형 복수의 눈을 만드는 방법에 대해 갈 수있는 가장 좋은 방법은 무엇인지.
저는 'for'로 놀아 왔지만 onMouseMove 함수는 마지막으로 만든 Eye에만 적용됩니다.
도 paperjs item.clone에서 찾고있다 - paperjs.org/reference/item#clone
아니면 각각의 눈에 대해 고유 한 변수를 만들어 내 문제인가?
for(var i = 0; i < 10; i++){
// Eye position center
// 100, 300, 500, 600
eCntrX = 100 * i + 100
eCntrY = 100
var topLid = new Path()
topLid.add(new Point(eCntrX - 60, eCntrY))
topLid.add(new Point(eCntrX, eCntrY - 28))
topLid.add(new Point(eCntrX + 60, eCntrY))
topLid.add(new Point(eCntrX, eCntrY + 28))
topLid.strokeWidth = '6'
topLid.strokeColor = '#000'
topLid.closed = true
topLid.smooth()
var iris = new Path.Circle(eCntrX, eCntrY, 24)
iris.fillColor = '#6CE0FF'
iris.strokeWidth = '6'
iris.strokeColor = '#000'
var pupil = new Path.Circle(eCntrX, eCntrY, 15)
pupil.fillColor = '#000'
var glint = new Path.Circle(eCntrX, eCntrY, 5)
glint.fillColor = '#fff'
glint.position = new Point(eCntrX + 6, eCntrY - 6)
var ball = new Group([iris, pupil, glint])
}
function onMouseMove(event) {
// Cursor position
var csrX = event.point.x
var csrY = event.point.y
// Ball position
var ballX = ball.position.x
var ballY = ball.position.y
// Displacement
var dx = csrX - ballX
var dy = csrY - ballY
//Radius
var r = 5
//Pythagerous thereom calcs. R
var R = Math.sqrt(dx*dx+dy*dy)
x = dx*r/R
y = dy*r/R
ball.position = new Point(eCntrX + x, eCntrY + y)
console.log('x:' + x + 'y:' + y)
}
가장 중요한 부분이 없습니다 ..'for' 루프와 눈 만들기를 게시하십시오. –
눈을 만들기 위해서는'while' 루프가 필요하고, 모든 눈을 업데이트하려면'for' 루프'onMouseMove'가 필요할 것입니다. – MiniGod
@KarolyHorvath - 나는 'for'루프를 추가했습니다. 몇 가지를 만들 때 테스트 해 보았습니다. 문제는 마지막으로 만든 Eye 만 상호 작용한다는 것입니다. – cupcakekid