oliver-wang-generative

This is an old revision of the document!


Oliver's code of crazy dog

I think my dog code is very different with other, cause I want to have a good score of program dog, so I think a lot and type a lot of code. My dog is different with other is because they just use triangle, square, circle, and I use a code name is “noStroke” it can make the shape be no line around it.

function setup() {
  createCanvas(790, 400);
noLoop()
}

class DogBackground{
constructor(y, numberOfDog){
this.positionY = y;
this.numberDog = numberOfDog
}draw(){
let x = 0;
let X = x;
let positionX = x;
let movingX = width/2
let movingY = height
//sun
fill('yellow')
noStroke(0)
circle(movingX, movingY, 100)
movingX = movingX + 1
movingY = movingY - 1
//sky
for(let i = 0; i < this.numberDog+10 ; i++){
//grass
noStroke()
fill(103, 222, 103)
rect(positionX, this.positionY+200, 400, 100)
positionX += 200 
}
//tree
for(let i = 0; i <this.numberDog+1; i++){
x += 200
fill(120, 74, 0)
rect(x-77, this.positionY+100, 30, 100)
triangle(x-75, this.positionY+200, x-30, this.positionY+200, x-50, this.positionY+175)
triangle(x-70, this.positionY+200, x-96, this.positionY+200, x-76, this.positionY+176)
fill('pink')
ellipse(x-62, this.positionY+35, 100, 200)
x += 60
}

for(let i = 0 ; i < this.numberDog+1; i++){

fill(246, 98, 135)
circle(x-118, this.positionY-7, 20)
circle(x-121, this.positionY+3, 20)
circle(x-104, this.positionY-7, 20)
circle(x-112, this.positionY+9, 20)
circle(x-102, this.positionY+3, 20)
fill('yellow')
circle(x-111, this.positionY-1, 10)
x -= 290
}}}

class Dog {
constructor(x, y, colorOfDog1, colorOfDog2, colorOfDog3, numberOfDog, space){
this.DogColor1 = colorOfDog1;
this.DogColor2 = colorOfDog2;
this.DogColor3 = colorOfDog3;
this.positionX = x;
this.positionY = y;
this.numberDog = numberOfDog;
this.dogSpace = space;
}draw (){
for(let i = 0; i < this.numberDog; i++){
noStroke()
//body
fill(Math.random()*255, Math.random()*255, Math.random()*255)
rect(this.positionX-3, this.positionY+163, 150, 40, 50)
//feet
rect(this.positionX+30, this.positionY-425, 50,  20, 50);
rect(this.positionX+82, this.positionY+189, 70, 20, 50);
rect(this.positionX+19, this.positionY+191, 40, 20, 50)

//head
rect(this.positionX+116, this.positionY+146, 40, 35, 15)
//mouth
rect(this.positionX+138, this.positionY+160, 30, 20, 10)

stroke(1)
noFill()
curve(this.positionX+23, this.positionY+202, this.positionX+142, this.positionY+208, this.positionX+96, this.positionY+208, this.positionX+43, this.positionY+208)
curve(this.positionX+207, this.positionY+183, this.positionX+96, this.positionY+208, this.positionX+92, this.positionY+191, this.positionX+126, this.positionY+209)
curve(this.positionX+73, this.positionY+208, this.positionX+145, this.positionY+208, this.positionX+125, this.positionY+190, this.positionX-60, this.positionY+244)
curve(this.positionX+44, this.positionY+217, this.positionX+53, this.positionY+196, this.positionX+49, this.positionY+211,  this.positionX-51, this.positionY+227)
curve(this.positionX+48, this.positionY+201, this.positionX+49, this.positionY+211, this.positionX+19, this.positionY+203, this.positionX+38, this.positionY+135)
curve(this.positionX+202, this.positionY+144, this.positionX+23, this.positionY+203, this.positionX+28, this.positionY+163, this.positionX+299, this.positionY+223)
curve(this.positionX+138, this.positionY+227, this.positionX+116, this.positionY+163, this.positionX+144, this.positionY+146, this.positionX+221, this.positionY+183)
curve(this.positionX+79, this.positionY+138, this.positionX+144, this.positionY+146, this.positionX+156, this.positionY+160, this.positionX+144, this.positionY+154)
curve(this.positionX+92, this.positionY+152, this.positionX+158, this.positionY+180, this.positionX+156, this.positionY+160, this.positionX+31, this.positionY+187)
curve(this.positionX+142  , this.positionY+170, this.positionX+146, this.positionY+191, this.positionX+145, this.positionY+180, this.positionX+123, this.positionY+197)
line(this.positionX+158, this.positionY+180, this.positionX+141, this.positionY+180)
line(this.positionX+28, this.positionY+163,this.positionX+116, this.positionY+163)
line(this.positionX+85, this.positionY+202, this.positionX+59, this.positionY+202)
//eye
fill('black')
circle(this.positionX+142, this.positionY+157, 5)
//ear
ellipse(this.positionX+127, this.positionY+157, 15, 20)
//nose
square(this.positionX+158, this.positionY+162, 11, 20)
fill(Math.random()*255, Math.random()*255, Math.random()*255)
noStroke()
stroke(1)
curve(this.positionX+24, this.positionY+202, this.positionX+6, this.positionY+167, this.positionX+16, this.positionY+164, this.positionX+155, this.positionY+482)
this.positionX = this.positionX + this.dogSpace
}}}
class Cloud{
constructor(x, y){
this.positionX = x;
this.positionY = y;
}draw(){
let positionX = this.positionX
for(let i = 0; i < 10; i++){
noStroke()
fill('white')
//cloud
ellipse(this.positionX, this.positionY-76, 50, 30)
rect(this.positionX-10, this.positionY-81, 50,  30, 20)
rect(this.positionX-30, this.positionY-81, 50,  30, 20)
ellipse(this.positionX*i, this.positionY-51, 50, 30)
this.positionX = this.positionX + 200
}
}
}

function backgroundArray (numberOfBackground){
var dogBackgroundArray = [];
for(let i = 0; i < numberOfBackground; i++){
dogBackgroundArray.push(new DogBackground(100, 10))
}
return dogBackgroundArray
}
function randomArray (numberOfHi){
var myColorArray = []
for(let i = 0; i < numberOfHi; i++){
myColorArray.push (Math.random()*255)
}
}
function pinkDogArray(numberOfDog){
var DogsArray = []
for(let i = 0; i < numberOfDog; i++){
DogsArray.push(new Dog(0, 100, Math.random()*255, Math.random()*255, Math.random()*255,100, 200))
}
return DogsArray
}

function cloudArray (n){
var myCloudArray = []
for(let i = 0; i < n; i++){
myCloudArray.push(new Cloud(100, 100))
}
return myCloudArray
}
let myCloudsArray = cloudArray(5)
console.log(myCloudsArray)
let myBackgroundArray = backgroundArray(5)
console.log(myBackgroundArray)
let myPinkDogArray = pinkDogArray(5)
console.log(myPinkDogArray)

function draw() {
background(163, 227, 255)

for(let i = 0; i < myCloudsArray.length; i++){
myCloudsArray[i].draw()
}

for(let i = 0; i < myBackgroundArray.length; i++){
myBackgroundArray[i].draw()
}

for(let i = 0; i < myPinkDogArray.length; i++){
myPinkDogArray[i].draw()
}
}
  • oliver-wang-generative.1624239345.txt.gz
  • Last modified: 2021/06/20 18:35
  • by oliver.wang