Javascript'teki temel bilgilerim en güçlüsü değil ve diğerlerinin kendim için oluşturduğum mevcut sorun hakkında nasıl düşündüklerini merak ediyorum. www -Benzersiz değişkenler oluşturma
Ben paper.js
Aşağıdaki kod ile etrafında oynuyorum göz (bu kodu öğrenilen) burada gözlerde aynı şekilde fare olaylarına tepki bu
yaratır. Ben gözlerle tüm sayfayı doldurmak için arıyorum
// 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
İşte ben budur. Benim nihai amacı böyle bir şey oluşturmaktır:
Sorum şu, etkileşimli çoklu gözler oluşturma hakkında gitmek için en iyi yolu nedir.
'for' ile oynamaktayım, ancak onMouseMove işlevi yalnızca oluşturulan son Eye için geçerlidir.
da paperjs item.clone bakarak mı - paperjs.org/reference/item#clone
Ya da her bir göz için benzersiz değişkenler yaratarak benden bir konudur?
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)
}
en önemli kısım eksiktir .. 'for' loop ve göz yaratımınızı gönderin. –
Muhtemelen gözlerin oluşturulması için bir 'while' döngüsüne ve tüm gözleri güncellemek için bir' for' loop 'MouseMove' öğesine ihtiyacınız olacaktır. – MiniGod
@KarolyHorvath - Denediğim 'for' döngüsünü ekledim. Sadece birkaç tane üzerinde test ediyordum. Sorun sadece oluşturulan son Gözün interaktif olmasıdır. – cupcakekid