How to mirror / replicate

I want to mirror on the bottom halve of the screen to the top halve is there a quicker way of doing this then copying everything again and flipping it upside down

@majied I’m not sure what you’re going to draw, but here’s a solution. Everything you want mirrored would go into function draw1, so you only have 1 version of code.

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
end

function draw()
    background(40, 40, 50)
    
    translate(0,0)
    rotate(0)
    draw1()  -- draw normal
    
    translate(WIDTH,HEIGHT)
    rotate(180)
    draw1()  -- draw mirror image rotated
end

function draw1()  -- put your drawing stuff here
    fill(223, 198, 138, 255)
    rect(0,0,WIDTH,HEIGHT/2)
    fill(255)
    text("qwerty",300,300)
    text("abcdefghijklmnop",800,200)
    sprite("Planet Cute:Character Horn Girl",200,100)
    sprite("Small World:Court",100,300)
    sprite("SpaceCute:Beetle Ship",500,200)
end

I do this for the split-screen effect in Banjax.

First of all, put all of your drawing into a function, call it drawing or something. Just drawing, not updating, checking for collisions, or any of the other things you might do in the draw loop. Separating drawing from other logic is good practice anyway.

I recommend creating a viewport class to handle each area of the screen you want to draw to. It is easiest I think if you make the centre of each viewport the origin of your drawing (rather than the bottom-left corner).

Then, you just translate to each viewport’s centre, rotate to it’s orientation, and clip as necessay

A quick example


function setup()
  fontSize(100)
  views = {
    --bottom half of screen, right way up:
    viewport(WIDTH * 0.5, HEIGHT * 0.25, WIDTH, HEIGHT * 0.5, 0),
    
    --top half of screen, upside down 
    viewport(WIDTH * 0.5, HEIGHT * 0.75, WIDTH, HEIGHT * 0.5, 180),
  }

end

function drawing()
   text("Hi there\
if clipping\\is working\
okay the\
viewports shouldn't\
overlap")
end

function draw()
  background(0)
  views[1]:draw()
  views[2]:draw()
end

viewport = class()

function viewport:init(x,y,w,h,a) --x and y of centre of viewport
  self.originX, self.originY, self.width, self.height, self.angle = x,y,w,h,a
  self.ax = x - w * 0.5 --calculate lower-left corner for clipping
  self.ay = y - h * 0.5
end

function viewport:draw()
  clip(self.ax, self.ay, self.width, self.height)
  pushMatrix()
  translate(self.originX, self.originY)
  rotate(self.angle)
  drawing() --do your drawing
  popMatrix()
  clip() --cancel the clip
end

Thanks guys I will try this